Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 4b5525b

Browse files
committed
Bug 1362167 - Use strongly-typed enum classes instead of generic uint16_t fields for the gfxShapedText and gfxTextRun flags. r=jrmuizel
1 parent 6fc5313 commit 4b5525b

23 files changed

Lines changed: 489 additions & 416 deletions

dom/canvas/CanvasRenderingContext2D.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4266,17 +4266,18 @@ struct MOZ_STACK_CLASS CanvasBidiProcessor : public nsBidiPresUtils::BidiProcess
42664266
{
42674267
mFontgrp->UpdateUserFonts(); // ensure user font generation is current
42684268
// adjust flags for current direction run
4269-
uint16_t flags = mTextRunFlags;
4269+
gfx::ShapedTextFlags flags = mTextRunFlags;
42704270
if (aDirection == NSBIDI_RTL) {
4271-
flags |= gfxTextRunFactory::TEXT_IS_RTL;
4271+
flags |= gfx::ShapedTextFlags::TEXT_IS_RTL;
42724272
} else {
4273-
flags &= ~gfxTextRunFactory::TEXT_IS_RTL;
4273+
flags &= ~gfx::ShapedTextFlags::TEXT_IS_RTL;
42744274
}
42754275
mTextRun = mFontgrp->MakeTextRun(aText,
42764276
aLength,
42774277
mDrawTarget,
42784278
mAppUnitsPerDevPixel,
4279-
flags, 0,
4279+
flags,
4280+
nsTextFrameUtils::Flags(),
42804281
mMissingFonts);
42814282
}
42824283

@@ -4489,7 +4490,7 @@ struct MOZ_STACK_CLASS CanvasBidiProcessor : public nsBidiPresUtils::BidiProcess
44894490
gfxRect mBoundingBox;
44904491

44914492
// flags to use when creating textrun, based on CSS style
4492-
uint16_t mTextRunFlags;
4493+
gfx::ShapedTextFlags mTextRunFlags;
44934494

44944495
// true iff the bounding box should be measured
44954496
bool mDoMeasureBoundingBox;
@@ -4577,11 +4578,12 @@ CanvasRenderingContext2D::DrawOrMeasureText(const nsAString& aRawText,
45774578

45784579
// If we don't have a style context, we can't set up vertical-text flags
45794580
// (for now, at least; perhaps we need new Canvas API to control this).
4580-
processor.mTextRunFlags = canvasStyle ?
4581-
nsLayoutUtils::GetTextRunFlagsForStyle(canvasStyle,
4582-
canvasStyle->StyleFont(),
4583-
canvasStyle->StyleText(),
4584-
0) : 0;
4581+
processor.mTextRunFlags = canvasStyle
4582+
? nsLayoutUtils::GetTextRunFlagsForStyle(canvasStyle,
4583+
canvasStyle->StyleFont(),
4584+
canvasStyle->StyleText(),
4585+
0)
4586+
: gfx::ShapedTextFlags();
45854587

45864588
GetAppUnitsValues(&processor.mAppUnitsPerDevPixel, nullptr);
45874589
processor.mPt = gfxPoint(aX, aY);
@@ -4675,11 +4677,11 @@ CanvasRenderingContext2D::DrawOrMeasureText(const nsAString& aRawText,
46754677

46764678
// We can't query the textRun directly, as it may not have been created yet;
46774679
// so instead we check the flags that will be used to initialize it.
4678-
uint16_t runOrientation =
4679-
(processor.mTextRunFlags & gfxTextRunFactory::TEXT_ORIENT_MASK);
4680-
if (runOrientation != gfxTextRunFactory::TEXT_ORIENT_HORIZONTAL) {
4681-
if (runOrientation == gfxTextRunFactory::TEXT_ORIENT_VERTICAL_MIXED ||
4682-
runOrientation == gfxTextRunFactory::TEXT_ORIENT_VERTICAL_UPRIGHT) {
4680+
gfx::ShapedTextFlags runOrientation =
4681+
(processor.mTextRunFlags & gfx::ShapedTextFlags::TEXT_ORIENT_MASK);
4682+
if (runOrientation != gfx::ShapedTextFlags::TEXT_ORIENT_HORIZONTAL) {
4683+
if (runOrientation == gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_MIXED ||
4684+
runOrientation == gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT) {
46834685
// Adjust to account for mTextRun being shaped using center baseline
46844686
// rather than alphabetic.
46854687
baselineAnchor -= (fontMetrics.emAscent - fontMetrics.emDescent) * .5f;

gfx/src/nsFontMetrics.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class AutoTextRun {
3838
reinterpret_cast<const uint8_t*>(aString), aLength,
3939
aDrawTarget,
4040
aMetrics->AppUnitsPerDevPixel(),
41-
ComputeFlags(aMetrics), 0,
41+
ComputeFlags(aMetrics), nsTextFrameUtils::Flags(),
4242
nullptr);
4343
}
4444

@@ -49,29 +49,29 @@ class AutoTextRun {
4949
aString, aLength,
5050
aDrawTarget,
5151
aMetrics->AppUnitsPerDevPixel(),
52-
ComputeFlags(aMetrics), 0,
52+
ComputeFlags(aMetrics), nsTextFrameUtils::Flags(),
5353
nullptr);
5454
}
5555

5656
gfxTextRun *get() { return mTextRun.get(); }
5757
gfxTextRun *operator->() { return mTextRun.get(); }
5858

5959
private:
60-
static uint16_t ComputeFlags(nsFontMetrics* aMetrics) {
61-
uint16_t flags = 0;
60+
static gfx::ShapedTextFlags ComputeFlags(nsFontMetrics* aMetrics) {
61+
gfx::ShapedTextFlags flags = gfx::ShapedTextFlags();
6262
if (aMetrics->GetTextRunRTL()) {
63-
flags |= gfxTextRunFactory::TEXT_IS_RTL;
63+
flags |= gfx::ShapedTextFlags::TEXT_IS_RTL;
6464
}
6565
if (aMetrics->GetVertical()) {
6666
switch (aMetrics->GetTextOrientation()) {
6767
case NS_STYLE_TEXT_ORIENTATION_MIXED:
68-
flags |= gfxTextRunFactory::TEXT_ORIENT_VERTICAL_MIXED;
68+
flags |= gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_MIXED;
6969
break;
7070
case NS_STYLE_TEXT_ORIENTATION_UPRIGHT:
71-
flags |= gfxTextRunFactory::TEXT_ORIENT_VERTICAL_UPRIGHT;
71+
flags |= gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT;
7272
break;
7373
case NS_STYLE_TEXT_ORIENTATION_SIDEWAYS:
74-
flags |= gfxTextRunFactory::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT;
74+
flags |= gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT;
7575
break;
7676
}
7777
}

gfx/thebes/gfxDWriteFonts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ gfxDWriteFont::Measure(const gfxTextRun* aTextRun,
551551
BoundingBoxType aBoundingBoxType,
552552
DrawTarget* aRefDrawTarget,
553553
Spacing* aSpacing,
554-
uint16_t aOrientation)
554+
gfx::ShapedTextFlags aOrientation)
555555
{
556556
gfxFont::RunMetrics metrics =
557557
gfxFont::Measure(aTextRun, aStart, aEnd, aBoundingBoxType,

gfx/thebes/gfxDWriteFonts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class gfxDWriteFont : public gfxFont
5454
BoundingBoxType aBoundingBoxType,
5555
DrawTarget *aDrawTargetForTightBoundingBox,
5656
Spacing *aSpacing,
57-
uint16_t aOrientation) override;
57+
mozilla::gfx::ShapedTextFlags aOrientation) override;
5858

5959
virtual bool ProvidesGlyphWidths() const override;
6060

gfx/thebes/gfxFont.cpp

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,7 +2032,7 @@ gfxFont::DrawEmphasisMarks(const gfxTextRun* aShapedText, gfxPoint* aPt,
20322032
void
20332033
gfxFont::Draw(const gfxTextRun *aTextRun, uint32_t aStart, uint32_t aEnd,
20342034
gfxPoint *aPt, const TextRunDrawParams& aRunParams,
2035-
uint16_t aOrientation)
2035+
gfx::ShapedTextFlags aOrientation)
20362036
{
20372037
NS_ASSERTION(aRunParams.drawMode == DrawMode::GLYPH_PATH ||
20382038
!(int(aRunParams.drawMode) & int(DrawMode::GLYPH_PATH)),
@@ -2057,7 +2057,7 @@ gfxFont::Draw(const gfxTextRun *aTextRun, uint32_t aStart, uint32_t aEnd,
20572057
fontParams.haveColorGlyphs = GetFontEntry()->TryGetColorGlyphs();
20582058
fontParams.contextPaint = aRunParams.runContextPaint;
20592059
fontParams.isVerticalFont =
2060-
aOrientation == gfxTextRunFactory::TEXT_ORIENT_VERTICAL_UPRIGHT;
2060+
aOrientation == gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT;
20612061

20622062
bool sideways = false;
20632063
gfxPoint origPt = *aPt;
@@ -2071,7 +2071,7 @@ gfxFont::Draw(const gfxTextRun *aTextRun, uint32_t aStart, uint32_t aEnd,
20712071
// with 90-degree CW rotation.
20722072
const gfxFloat
20732073
rotation = (aOrientation ==
2074-
gfxTextRunFactory::TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT)
2074+
gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT)
20752075
? -M_PI / 2.0 : M_PI / 2.0;
20762076
gfxMatrix mat =
20772077
aRunParams.context->CurrentMatrix().
@@ -2192,7 +2192,7 @@ gfxFont::Draw(const gfxTextRun *aTextRun, uint32_t aStart, uint32_t aEnd,
21922192
// adjust updated aPt to account for the transform we were using
21932193
gfxFloat advance = aPt->x - origPt.x;
21942194
if (aOrientation ==
2195-
gfxTextRunFactory::TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT) {
2195+
gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT) {
21962196
*aPt = gfxPoint(origPt.x, origPt.y - advance);
21972197
} else {
21982198
*aPt = gfxPoint(origPt.x, origPt.y + advance);
@@ -2290,7 +2290,7 @@ UnionRange(gfxFloat aX, gfxFloat* aDestMin, gfxFloat* aDestMax)
22902290
static bool
22912291
NeedsGlyphExtents(gfxFont *aFont, const gfxTextRun *aTextRun)
22922292
{
2293-
return (aTextRun->GetFlags() & gfxTextRunFactory::TEXT_NEED_BOUNDING_BOX) ||
2293+
return (aTextRun->GetFlags() & gfx::ShapedTextFlags::TEXT_NEED_BOUNDING_BOX) ||
22942294
aFont->GetFontEntry()->IsUserFont();
22952295
}
22962296

@@ -2318,7 +2318,7 @@ gfxFont::Measure(const gfxTextRun *aTextRun,
23182318
BoundingBoxType aBoundingBoxType,
23192319
DrawTarget* aRefDrawTarget,
23202320
Spacing *aSpacing,
2321-
uint16_t aOrientation)
2321+
gfx::ShapedTextFlags aOrientation)
23222322
{
23232323
// If aBoundingBoxType is TIGHT_HINTED_OUTLINE_EXTENTS
23242324
// and the underlying cairo font may be antialiased,
@@ -2341,7 +2341,7 @@ gfxFont::Measure(const gfxTextRun *aTextRun,
23412341
const int32_t appUnitsPerDevUnit = aTextRun->GetAppUnitsPerDevUnit();
23422342
// Current position in appunits
23432343
gfxFont::Orientation orientation =
2344-
aOrientation == gfxTextRunFactory::TEXT_ORIENT_VERTICAL_UPRIGHT
2344+
aOrientation == gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT
23452345
? eVertical : eHorizontal;
23462346
const gfxFont::Metrics& fontMetrics = GetMetrics(orientation);
23472347

@@ -2571,7 +2571,7 @@ gfxFont::GetShapedWord(DrawTarget *aDrawTarget,
25712571
Script aRunScript,
25722572
bool aVertical,
25732573
int32_t aAppUnitsPerDevUnit,
2574-
uint16_t aFlags,
2574+
gfx::ShapedTextFlags aFlags,
25752575
RoundingFlags aRounding,
25762576
gfxTextPerfMetrics *aTextPerf GFX_MAYBE_UNUSED)
25772577
{
@@ -2669,7 +2669,7 @@ gfxFont::CacheHashEntry::KeyEquals(const KeyTypePointer aKey) const
26692669
}
26702670
return true;
26712671
}
2672-
NS_ASSERTION((aKey->mFlags & gfxTextRunFactory::TEXT_IS_8BIT) == 0 &&
2672+
NS_ASSERTION(!(aKey->mFlags & gfx::ShapedTextFlags::TEXT_IS_8BIT) &&
26732673
!aKey->mTextIs8Bit, "didn't expect 8-bit text here");
26742674
return (0 == memcmp(sw->TextUnicode(), aKey->mText.mDouble,
26752675
aKey->mLength * sizeof(char16_t)));
@@ -2872,7 +2872,7 @@ gfxFont::ShapeTextWithoutWordCache(DrawTarget *aDrawTarget,
28722872
} else if (ch == '\n') {
28732873
aTextRun->SetIsNewline(aOffset + i);
28742874
} else if (IsInvalidControlChar(ch) &&
2875-
!(aTextRun->GetFlags() & gfxTextRunFactory::TEXT_HIDE_CONTROL_CHARACTERS)) {
2875+
!(aTextRun->GetFlags() & gfx::ShapedTextFlags::TEXT_HIDE_CONTROL_CHARACTERS)) {
28762876
if (GetFontEntry()->IsUserFont() && HasCharacter(ch)) {
28772877
ShapeFragmentWithoutWordCache(aDrawTarget, aText + i,
28782878
aOffset + i, 1,
@@ -2966,13 +2966,13 @@ gfxFont::SplitAndInitTextRun(DrawTarget *aDrawTarget,
29662966
InitWordCache();
29672967

29682968
// the only flags we care about for ShapedWord construction/caching
2969-
uint16_t flags = aTextRun->GetFlags();
2970-
flags &= (gfxTextRunFactory::TEXT_IS_RTL |
2971-
gfxTextRunFactory::TEXT_DISABLE_OPTIONAL_LIGATURES |
2972-
gfxTextRunFactory::TEXT_USE_MATH_SCRIPT |
2973-
gfxTextRunFactory::TEXT_ORIENT_MASK);
2969+
gfx::ShapedTextFlags flags = aTextRun->GetFlags();
2970+
flags &= (gfx::ShapedTextFlags::TEXT_IS_RTL |
2971+
gfx::ShapedTextFlags::TEXT_DISABLE_OPTIONAL_LIGATURES |
2972+
gfx::ShapedTextFlags::TEXT_USE_MATH_SCRIPT |
2973+
gfx::ShapedTextFlags::TEXT_ORIENT_MASK);
29742974
if (sizeof(T) == sizeof(uint8_t)) {
2975-
flags |= gfxTextRunFactory::TEXT_IS_8BIT;
2975+
flags |= gfx::ShapedTextFlags::TEXT_IS_8BIT;
29762976
}
29772977

29782978
uint32_t wordStart = 0;
@@ -3018,13 +3018,13 @@ gfxFont::SplitAndInitTextRun(DrawTarget *aDrawTarget,
30183018
return false;
30193019
}
30203020
} else if (length > 0) {
3021-
uint16_t wordFlags = flags;
3021+
gfx::ShapedTextFlags wordFlags = flags;
30223022
// in the 8-bit version of this method, TEXT_IS_8BIT was
30233023
// already set as part of |flags|, so no need for a per-word
30243024
// adjustment here
30253025
if (sizeof(T) == sizeof(char16_t)) {
30263026
if (wordIs8Bit) {
3027-
wordFlags |= gfxTextRunFactory::TEXT_IS_8BIT;
3027+
wordFlags |= gfx::ShapedTextFlags::TEXT_IS_8BIT;
30283028
}
30293029
}
30303030
gfxShapedWord* sw = GetShapedWord(aDrawTarget,
@@ -3041,11 +3041,12 @@ gfxFont::SplitAndInitTextRun(DrawTarget *aDrawTarget,
30413041

30423042
if (boundary) {
30433043
// word was terminated by a space: add that to the textrun
3044-
uint16_t orientation = flags & gfxTextRunFactory::TEXT_ORIENT_MASK;
3045-
if (orientation == gfxTextRunFactory::TEXT_ORIENT_VERTICAL_MIXED) {
3044+
gfx::ShapedTextFlags orientation =
3045+
flags & gfx::ShapedTextFlags::TEXT_ORIENT_MASK;
3046+
if (orientation == gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_MIXED) {
30463047
orientation = aVertical ?
3047-
gfxTextRunFactory::TEXT_ORIENT_VERTICAL_UPRIGHT :
3048-
gfxTextRunFactory::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT;
3048+
gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT :
3049+
gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT;
30493050
}
30503051
if (boundary != ' ' ||
30513052
!aTextRun->SetSpaceGlyphIfSimple(this, aRunStart + i, ch,
@@ -3061,7 +3062,7 @@ gfxFont::SplitAndInitTextRun(DrawTarget *aDrawTarget,
30613062
GetShapedWord(aDrawTarget, &boundary, 1,
30623063
gfxShapedWord::HashMix(0, boundary),
30633064
aRunScript, aVertical, appUnitsPerDevUnit,
3064-
flags | gfxTextRunFactory::TEXT_IS_8BIT,
3065+
flags | gfx::ShapedTextFlags::TEXT_IS_8BIT,
30653066
rounding, tp);
30663067
if (sw) {
30673068
aTextRun->CopyGlyphDataFrom(sw, aRunStart + i);
@@ -3090,7 +3091,7 @@ gfxFont::SplitAndInitTextRun(DrawTarget *aDrawTarget,
30903091
} else if (ch == '\n') {
30913092
aTextRun->SetIsNewline(aRunStart + i);
30923093
} else if (IsInvalidControlChar(ch) &&
3093-
!(aTextRun->GetFlags() & gfxTextRunFactory::TEXT_HIDE_CONTROL_CHARACTERS)) {
3094+
!(aTextRun->GetFlags() & gfx::ShapedTextFlags::TEXT_HIDE_CONTROL_CHARACTERS)) {
30943095
if (GetFontEntry()->IsUserFont() && HasCharacter(ch)) {
30953096
ShapeFragmentWithoutWordCache(aDrawTarget, aString + i,
30963097
aRunStart + i, 1,
@@ -3135,7 +3136,7 @@ gfxFont::InitFakeSmallCapsRun(DrawTarget *aDrawTarget,
31353136
uint32_t aOffset,
31363137
uint32_t aLength,
31373138
uint8_t aMatchType,
3138-
uint16_t aOrientation,
3139+
gfx::ShapedTextFlags aOrientation,
31393140
Script aScript,
31403141
bool aSyntheticLower,
31413142
bool aSyntheticUpper)
@@ -3157,7 +3158,7 @@ gfxFont::InitFakeSmallCapsRun(DrawTarget *aDrawTarget,
31573158
RunCaseAction runAction = kNoChange;
31583159
uint32_t runStart = 0;
31593160
bool vertical =
3160-
aOrientation == gfxTextRunFactory::TEXT_ORIENT_VERTICAL_UPRIGHT;
3161+
aOrientation == gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT;
31613162

31623163
for (uint32_t i = 0; i <= aLength; ++i) {
31633164
uint32_t extraCodeUnits = 0; // Will be set to 1 if we need to consume
@@ -3257,7 +3258,9 @@ gfxFont::InitFakeSmallCapsRun(DrawTarget *aDrawTarget,
32573258
};
32583259
RefPtr<gfxTextRun> tempRun(
32593260
gfxTextRun::Create(&params, convertedString.Length(),
3260-
aTextRun->GetFontGroup(), 0, 0));
3261+
aTextRun->GetFontGroup(),
3262+
gfx::ShapedTextFlags(),
3263+
nsTextFrameUtils::Flags()));
32613264
tempRun->AddGlyphRun(f, aMatchType, 0, true, aOrientation);
32623265
if (!f->SplitAndInitTextRun(aDrawTarget, tempRun.get(),
32633266
convertedString.BeginReading(),
@@ -3267,7 +3270,9 @@ gfxFont::InitFakeSmallCapsRun(DrawTarget *aDrawTarget,
32673270
} else {
32683271
RefPtr<gfxTextRun> mergedRun(
32693272
gfxTextRun::Create(&params, runLength,
3270-
aTextRun->GetFontGroup(), 0, 0));
3273+
aTextRun->GetFontGroup(),
3274+
gfx::ShapedTextFlags(),
3275+
nsTextFrameUtils::Flags()));
32713276
MergeCharactersInTextRun(mergedRun.get(), tempRun.get(),
32723277
charsToMergeArray.Elements(),
32733278
deletedCharsArray.Elements());
@@ -3308,7 +3313,7 @@ gfxFont::InitFakeSmallCapsRun(DrawTarget *aDrawTarget,
33083313
uint32_t aOffset,
33093314
uint32_t aLength,
33103315
uint8_t aMatchType,
3311-
uint16_t aOrientation,
3316+
gfx::ShapedTextFlags aOrientation,
33123317
Script aScript,
33133318
bool aSyntheticLower,
33143319
bool aSyntheticUpper)

0 commit comments

Comments
 (0)