Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript improvements #91

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ All the implementations are based on JIS X 0510:1999.

The word "QR Code" is registered trademark of DENSO WAVE INCORPORATED
<br/>http://www.denso-wave.com/qrcode/faqpatent-e.html

----

This repository is a fork of the original with all programming languages.
It contains **only improvements for the JavaScript implementation**.
Please select the "improvements" branch to see the changes.
Other files have not been altered or regarded in any way.
39 changes: 34 additions & 5 deletions js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ Make a QR Code.
The number of modules(cells) for each orientation.
_[Note] call make() before this function._

#### getDarkCount() => <code>number</code>
The total number of modules(cells) that are dark in the final QR code.
_[Note] call make() before this function._

#### isDark(row, col) => <code>boolean</code>
The module at row and col is dark or not.
_[Note] call make() before this function._
Expand All @@ -68,11 +72,35 @@ _[Note] call make() before this function._
| row | <code>number</code> | 0 ~ moduleCount - 1 |
| col | <code>number</code> | 0 ~ moduleCount - 1 |

#### getTypeNumber() => <code>number</code>
Gets the code size type of the final QR code.
_[Note] call make() before this function._

#### getMaskPattern() => <code>number</code>
Gets the index of the mask pattern (0 to 7) that was used in the final QR code.
_[Note] call make() before this function._

#### getBestMaskPattern() => <code>number</code>
Gets the index of the mask pattern (0 to 7) that would be chosen for the QR code, based on its minimal penalty score.
_[Note] call make() before this function._

#### getMaskPatternPenaltyScores() => <code>number[]</code>
Gets the calculated penalty score for each mask pattern. Lower values make better QR codes.
_[Note] call make() before this function._

#### setMaskPattern(index) => <code>void</code>
Sets the index of the mask pattern (0 to 7) to use in the final QR code, regardless of which the best pattern would be.
Default to null, which selects the best pattern automatically.

#### setColors(foreground, background) => <code>void</code>
Sets the foreground and background colors for the output formats. Default to black and white, respectively.
_[Note] This has no effect on the ASCII output._

#### createDataURL(cellSize, margin) => <code>string</code>
#### createImgTag(cellSize, margin, alt) => <code>string</code>
#### createSvgTag(cellSize, margin) => <code>string</code>
#### createTableTag(cellSize, margin) => <code>string</code>
#### createASCII(cellSize, margin) => <code>string</code>
#### createASCII(cellSize, margin, inverted) => <code>string</code>
Helper functions for HTML.
_[Note] call make() before these functions._

Expand All @@ -81,6 +109,7 @@ Helper functions for HTML.
| cellSize | <code>number</code> | default: 2 |
| margin | <code>number</code> | default: cellSize * 4 |
| alt | <code>string</code> | (optional) |
| inverted | <code>bool</code> | (optional) |

#### createSvgTag(opts) => <code>string</code>

Expand All @@ -91,11 +120,11 @@ Helper functions for HTML.
| opts.margin | <code>number</code> | default: cellSize * 4 |
| opts.scalable | <code>boolean</code> | default: false |

#### renderTo2dContext(context, cellSize) => <code>void</code>
#### renderTo2dContext(context, cellSize, margin) => <code>void</code>

--
----

This implementation is based on JIS X 0510:1999.

The word 'QR Code' is registered trademark of DENSO WAVE INCORPORATED
<br/>http://www.denso-wave.com/qrcode/faqpatent-e.html
The word 'QR Code' is registered trademark of DENSO WAVE INCORPORATED.<br>
https://www.qrcode.com/en/faq.html
8 changes: 8 additions & 0 deletions js/miniwebcompiler.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"projectName": "qrcode-generator",
"files": [
{
"name": "qrcode.js"
}
]
}
17 changes: 8 additions & 9 deletions js/qrcode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//
// The word 'QR Code' is registered trademark of
// DENSO WAVE INCORPORATED
// http://www.denso-wave.com/qrcode/faqpatent-e.html
// https://www.qrcode.com/en/faq.html
//
//---------------------------------------------------------------------

Expand All @@ -31,23 +31,22 @@ interface QRCodeFactory {
(typeNumber: TypeNumber, errorCorrectionLevel: ErrorCorrectionLevel) : QRCode;
stringToBytes(s: string) : number[];
stringToBytesFuncs : { [encoding : string] : (s: string) => number[] };
createStringToBytes(unicodeData: string, numChars: number) :
(s : string) => number[];
createStringToBytes(unicodeData: string, numChars: number) : (s : string) => number[];
}

interface QRCode {
addData(data: string, mode?: Mode) : void;
make() : void;
getModuleCount() : number;
isDark(row: number, col: number) : boolean;
createImgTag(cellSize?: number, margin?: number) : string;
createSvgTag(cellSize?: number, margin?: number) : string;
createSvgTag(opts? : { cellSize?: number, margin?: number,
scalable?: boolean }) : string;
setColors(foreground: string, background: string) : void;
createImgTag(cellSize?: number, margin?: number, alt?: string) : string;
createSvgTag(cellSize?: number, margin?: number, alt?: string, title?: string) : string;
createSvgTag(opts? : { cellSize?: number, margin?: number, scalable?: boolean }) : string;
createDataURL(cellSize?: number, margin?: number) : string;
createTableTag(cellSize?: number, margin?: number) : string;
createASCII(cellSize?: number, margin?: number) : string;
renderTo2dContext(context: CanvasRenderingContext2D, cellSize?: number): void;
createASCII(cellSize?: number, margin?: number, inverted?: boolean) : string;
renderTo2dContext(context: CanvasRenderingContext2D, cellSize?: number, margin?: number): void;
}

declare var qrcode : QRCodeFactory;
Expand Down
Loading