Skip to content

Commit

Permalink
improve hotfix documentation and mention px_scaling hotfix in jsPDF d…
Browse files Browse the repository at this point in the history
…ocumentation
  • Loading branch information
HackbrettXXX committed Sep 24, 2020
1 parent 77ce3d3 commit 511b0a3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
41 changes: 27 additions & 14 deletions HOTFIX_README.md
Expand Up @@ -3,51 +3,64 @@
We sometimes bake-in solutions (A.K.A. hotfixes) to solve issues for specific use cases.

When we deem a hotfix will not break existing code,
will make it default behaviour and mark the hotfix as _accepted_,
At that point the define can be removed.

To enable a hotfix, define the following member of your created PDF,
where the pdf.hotfix field is the name of the hotfix.

var pdf new jsPDF(...);
pdf.hotfix.fill_close = true;

will make it default behaviour and mark the hotfix as _accepted_,
At that point the define can be removed.

To enable a hotfix, pass the `hotfixes` option to the jsPDF constructor:

```js
new jsPDF({
hotfixes: ["px_scaling"]
});
```

# Active Hotfixes

## px_scaling

### Applies To

jsPDF Core

### Description

When supplying 'px' as the unit for the PDF, the internal scaling factor was being miscalculated making drawn components
larger than they should be. Enabling this hotfix will correct this scaling calculation and items will be drawn to the
larger than they should be. Enabling this hotfix will correct this scaling calculation and items will be drawn to the
correct scale.

### To Enable

To enable this hotfix, supply a 'hotfixes' array to the options object in the jsPDF constructor function, and add the
string 'px_scaling' to this array.

#Accepted Hotfixes

## scale_text

### Applies To

context2d plugin

### Affects

Drawing and Filling Text when a scale transformation is active.

### Description

jsPDF currently has no way to draw scaled text.
This hotfix scales the current font size by the x-axis scale factor.

## fill_close

### Applies To

context2d plugin

### Affects
Filling paths

Filling paths

### Description

In certain cases, closing a fill would result in a path resolving to an incorrect point.
The was most likely fixed when we refactored matrix logic. Enabling this hotfix will ignore a most-likely unneeded workaround.

The was most likely fixed when we refactored matrix logic. Enabling this hotfix will ignore a most-likely unneeded workaround.
4 changes: 3 additions & 1 deletion src/jspdf.js
Expand Up @@ -177,13 +177,15 @@ function TilingPattern(boundingBox, xStep, yStep, gState, matrix) {
* @param {Object} [options] - Collection of settings initializing the jsPDF-instance
* @param {string} [options.orientation=portrait] - Orientation of the first page. Possible values are "portrait" or "landscape" (or shortcuts "p" or "l").<br />
* @param {string} [options.unit=mm] Measurement unit (base unit) to be used when coordinates are specified.<br />
* Possible values are "pt" (points), "mm", "cm", "m", "in" or "px".
* Possible values are "pt" (points), "mm", "cm", "m", "in" or "px". Note that in order to get the correct scaling for "px"
* units, you need to enable the hotfix "px_scaling" by setting options.hotfixes = ["px_scaling"].
* @param {string/Array} [options.format=a4] The format of the first page. Can be:<ul><li>a0 - a10</li><li>b0 - b10</li><li>c0 - c10</li><li>dl</li><li>letter</li><li>government-letter</li><li>legal</li><li>junior-legal</li><li>ledger</li><li>tabloid</li><li>credit-card</li></ul><br />
* Default is "a4". If you want to use your own format just pass instead of one of the above predefined formats the size as an number-array, e.g. [595.28, 841.89]
* @param {boolean} [options.putOnlyUsedFonts=false] Only put fonts into the PDF, which were used.
* @param {boolean} [options.compress=false] Compress the generated PDF.
* @param {number} [options.precision=16] Precision of the element-positions.
* @param {number} [options.userUnit=1.0] Not to be confused with the base unit. Please inform yourself before you use it.
* @param {string[]} [options.hotfixes] An array of strings to enable hotfixes such as correct pixel scaling.
* @param {number|"smart"} [options.floatPrecision=16]
* @returns {jsPDF} jsPDF-instance
* @description
Expand Down

0 comments on commit 511b0a3

Please sign in to comment.