Repository navigation
Support variations of fonts in WOFF and WOFF2 containers #389
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
Open
sidorares
wants to merge
1
commit into
foliojs:master
Choose a base branch
from
windowkit:woff-variations
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+254
−31
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,8 +72,10 @@ export default class GlyphVariationProcessor { | |
| let offset = gvar.offsets[gid]; | ||
| if (offset === gvar.offsets[gid + 1]) { return; } | ||
|
|
||
| // Read the gvar data for this glyph | ||
| let { stream } = this.font; | ||
| // Read the gvar data for this glyph, from the stream its table was | ||
| // decoded from, which the offsets are positions in. That is the font's | ||
| // own, unless the table is compressed by itself (WOFF). | ||
| let stream = this.font._getTableStream('gvar'); | ||
| stream.pos = offset; | ||
| if (stream.pos >= stream.length) { | ||
| return; | ||
|
|
@@ -85,7 +87,7 @@ export default class GlyphVariationProcessor { | |
| if (tupleCount & TUPLES_SHARE_POINT_NUMBERS) { | ||
| var here = stream.pos; | ||
| stream.pos = offsetToData; | ||
| var sharedPoints = this.decodePoints(); | ||
| var sharedPoints = this.decodePoints(stream); | ||
| offsetToData = stream.pos; | ||
| stream.pos = here; | ||
| } | ||
|
|
@@ -134,15 +136,15 @@ export default class GlyphVariationProcessor { | |
| stream.pos = offsetToData; | ||
|
|
||
| if (tupleIndex & PRIVATE_POINT_NUMBERS) { | ||
| var points = this.decodePoints(); | ||
| var points = this.decodePoints(stream); | ||
| } else { | ||
| var points = sharedPoints; | ||
| } | ||
|
|
||
| // points.length = 0 means there are deltas for all points | ||
| let nPoints = points.length === 0 ? glyphPoints.length : points.length; | ||
| let xDeltas = this.decodeDeltas(nPoints); | ||
| let yDeltas = this.decodeDeltas(nPoints); | ||
| let xDeltas = this.decodeDeltas(stream, nPoints); | ||
| let yDeltas = this.decodeDeltas(stream, nPoints); | ||
|
|
||
| if (points.length === 0) { // all points | ||
| for (let i = 0; i < glyphPoints.length; i++) { | ||
|
|
@@ -181,8 +183,7 @@ export default class GlyphVariationProcessor { | |
| } | ||
| } | ||
|
|
||
| decodePoints() { | ||
| let stream = this.font.stream; | ||
| decodePoints(stream) { | ||
| let count = stream.readUInt8(); | ||
|
|
||
| if (count & POINTS_ARE_WORDS) { | ||
|
|
@@ -206,8 +207,7 @@ export default class GlyphVariationProcessor { | |
| return points; | ||
| } | ||
|
|
||
| decodeDeltas(count) { | ||
| let stream = this.font.stream; | ||
| decodeDeltas(stream, count) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. decodeDeltas can be declared as a function in module scope |
||
| let i = 0; | ||
| let deltas = new Int16Array(count); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import TTFGlyph from './TTFGlyph'; | ||
| import BBox from './BBox'; | ||
|
|
||
| /** | ||
| * Represents a TrueType glyph in the WOFF2 format, which compresses glyphs differently. | ||
|
|
@@ -8,10 +9,33 @@ export default class WOFF2Glyph extends TTFGlyph { | |
|
|
||
| _decode() { | ||
| // We have to decode in advance (in WOFF2Font), so just return the pre-decoded data. | ||
| return this._font._transformedGlyphs[this.id]; | ||
| let glyph = this._font._transformedGlyphs[this.id]; | ||
| if (!glyph || !this._font._variationProcessor || glyph.numberOfContours === 0) { | ||
| return glyph; | ||
| } | ||
|
|
||
| // A variation moves a copy of it: the decoded data is the font's, and | ||
| // that of every other variation of it. | ||
| let varied = Object.assign({}, glyph); | ||
| if (glyph.numberOfContours > 0) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. glyph.numberOfContours > 0 is always true? |
||
| varied.points = glyph.points.map(point => point.copy()); | ||
| } else { | ||
| varied.components = glyph.components.map(component => Object.assign({}, component)); | ||
| } | ||
|
|
||
| this._applyVariation(varied); | ||
| return varied; | ||
| } | ||
|
|
||
| _getCBox() { | ||
| _getCBox(internal) { | ||
| // What a variation starts from is the box in the glyph's header, as it | ||
| // is for a TTFGlyph. The path's own would be the varied glyph's, and | ||
| // decoding that is what is asking. | ||
| if (internal && this._font._variationProcessor) { | ||
| let glyph = this._font._transformedGlyphs[this.id]; | ||
| return Object.freeze(new BBox(glyph.xMin, glyph.yMin, glyph.xMax, glyph.yMax)); | ||
| } | ||
|
|
||
| return this.path.bbox; | ||
| } | ||
| } | ||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decodePoints can be declared as a function in module scope