Skip to content

Commit

Permalink
Merge pull request #15665 from Snuffleupagus/Glyph-category
Browse files Browse the repository at this point in the history
[api-minor] Initialize the unicode-category *lazily* on the `Glyph`-instance
  • Loading branch information
Snuffleupagus authored Nov 5, 2022
2 parents 26f6f77 + c8868a1 commit 7e5008f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2775,7 +2775,9 @@ class PartialEvaluator {

for (let i = 0, ii = glyphs.length; i < ii; i++) {
const glyph = glyphs[i];
if (glyph.isInvisibleFormatMark) {
const { category } = glyph;

if (category.isInvisibleFormatMark) {
continue;
}
let charSpacing =
Expand All @@ -2787,7 +2789,7 @@ class PartialEvaluator {
}
let scaledDim = glyphWidth * scale;

if (glyph.isWhitespace) {
if (category.isWhitespace) {
// Don't push a " " in the textContentItem
// (except when it's between two non-spaces chars),
// it will be done (if required) in next call to
Expand Down Expand Up @@ -2815,7 +2817,7 @@ class PartialEvaluator {
// Must be called after compareWithLastPosition because
// the textContentItem could have been flushed.
const textChunk = ensureTextContentItem();
if (glyph.isZeroWidthDiacritic) {
if (category.isZeroWidthDiacritic) {
scaledDim = 0;
}

Expand Down
17 changes: 13 additions & 4 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,20 @@ class Glyph {
this.operatorListId = operatorListId;
this.isSpace = isSpace;
this.isInFont = isInFont;
}

const category = getCharUnicodeCategory(unicode);
this.isWhitespace = category.isWhitespace;
this.isZeroWidthDiacritic = category.isZeroWidthDiacritic;
this.isInvisibleFormatMark = category.isInvisibleFormatMark;
/**
* This property, which is only used by `PartialEvaluator.getTextContent`,
* is purposely made non-serializable.
* @type {Object}
*/
get category() {
return shadow(
this,
"category",
getCharUnicodeCategory(this.unicode),
/* nonSerializable = */ true
);
}

/**
Expand Down

0 comments on commit 7e5008f

Please sign in to comment.