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

Remove all instances of HasFlag #426

Merged
merged 1 commit into from
Dec 16, 2024
Merged
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
4 changes: 2 additions & 2 deletions src/SixLabors.Fonts/Font.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private string LoadFontName()
return metrics;
}

if (this.RequestedStyle.HasFlag(FontStyle.Italic))
if ((this.RequestedStyle & FontStyle.Italic) == FontStyle.Italic)
{
// Can't find style requested and they want one that's at least partial italic.
// Try the regular italic.
Expand All @@ -300,7 +300,7 @@ private string LoadFontName()
}
}

if (this.RequestedStyle.HasFlag(FontStyle.Bold))
if ((this.RequestedStyle & FontStyle.Bold) == FontStyle.Bold)
{
// Can't find style requested and they want one that's at least partial bold.
// Try the regular bold.
Expand Down
8 changes: 4 additions & 4 deletions src/SixLabors.Fonts/FontDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,24 @@ private static FontStyle ConvertStyle(OS2Table? os2, HeadTable? head)

if (os2 != null)
{
if (os2.FontStyle.HasFlag(OS2Table.FontStyleSelection.BOLD))
if ((os2.FontStyle & OS2Table.FontStyleSelection.BOLD) == OS2Table.FontStyleSelection.BOLD)
{
style |= FontStyle.Bold;
}

if (os2.FontStyle.HasFlag(OS2Table.FontStyleSelection.ITALIC))
if ((os2.FontStyle & OS2Table.FontStyleSelection.ITALIC) == OS2Table.FontStyleSelection.ITALIC)
{
style |= FontStyle.Italic;
}
}
else if (head != null)
{
if (head.MacStyle.HasFlag(HeadTable.HeadMacStyle.Bold))
if ((head.MacStyle & HeadTable.HeadMacStyle.Bold) == HeadTable.HeadMacStyle.Bold)
{
style |= FontStyle.Bold;
}

if (head.MacStyle.HasFlag(HeadTable.HeadMacStyle.Italic))
if ((head.MacStyle & HeadTable.HeadMacStyle.Italic) == HeadTable.HeadMacStyle.Italic)
{
style |= FontStyle.Italic;
}
Expand Down
4 changes: 2 additions & 2 deletions src/SixLabors.Fonts/GlyphMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ internal GlyphMetrics(

Vector2 offset = Vector2.Zero;
Vector2 scaleFactor = new(unitsPerEM * 72F);
if (textAttributes.HasFlag(TextAttributes.Subscript))
if ((textAttributes & TextAttributes.Subscript) == TextAttributes.Subscript)
{
float units = this.UnitsPerEm;
scaleFactor /= new Vector2(font.SubscriptXSize / units, font.SubscriptYSize / units);
offset = new(font.SubscriptXOffset, font.SubscriptYOffset < 0 ? font.SubscriptYOffset : -font.SubscriptYOffset);
}
else if (textAttributes.HasFlag(TextAttributes.Superscript))
else if ((textAttributes & TextAttributes.Superscript) == TextAttributes.Superscript)
{
float units = this.UnitsPerEm;
scaleFactor /= new Vector2(font.SuperscriptXSize / units, font.SuperscriptYSize / units);
Expand Down
2 changes: 1 addition & 1 deletion src/SixLabors.Fonts/StreamFontMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ private static HorizontalMetrics InitializeHorizontalMetrics(HorizontalHeadTable
// 3.If they are zero and the OS/ 2 table exists,
// - Use the OS/ 2 table's sTypo* metrics if they are non-zero.
// - Otherwise, use the OS / 2 table's usWin* metrics.
bool useTypoMetrics = os2.FontStyle.HasFlag(OS2Table.FontStyleSelection.USE_TYPO_METRICS);
bool useTypoMetrics = (os2.FontStyle & OS2Table.FontStyleSelection.USE_TYPO_METRICS) == OS2Table.FontStyleSelection.USE_TYPO_METRICS;
if (useTypoMetrics)
{
ascender = os2.TypoAscender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public override bool TryUpdatePosition(
int parent = nextIndex;
int xOffset = entryXY.XCoordinate - exitXY.XCoordinate;
int yOffset = entryXY.YCoordinate - exitXY.YCoordinate;
if (this.LookupFlags.HasFlag(LookupFlags.RightToLeft))
if ((this.LookupFlags & LookupFlags.RightToLeft) == LookupFlags.RightToLeft)
{
(parent, child) = (child, parent);

Expand Down
3 changes: 3 additions & 0 deletions src/SixLabors.Fonts/Tables/General/OS2Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,11 @@ public OS2Table(OS2Table versionLessThan5Table, ushort lowerOpticalPointSize, us
this.upperOpticalPointSize = upperOpticalPointSize;
}

[Flags]
internal enum FontStyleSelection : ushort
{
NONE = 0,

// 0 bit 1 ITALIC Font contains italic or oblique characters, otherwise they are upright.
ITALIC = 1,

Expand Down
22 changes: 10 additions & 12 deletions src/SixLabors.Fonts/Tables/TrueType/Glyphs/SimpleGlyphLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static GlyphLoader LoadSimpleGlyph(BigEndianBinaryReader reader, short co
var controlPoints = new ControlPoint[xs.Length];
for (int i = 0; i < flags.Length; i++)
{
controlPoints[i] = new(new Vector2(xs[i], ys[i]), flags[i].HasFlag(Flags.OnCurve));
controlPoints[i] = new(new Vector2(xs[i], ys[i]), (flags[i] & Flags.OnCurve) == Flags.OnCurve);
}

return new SimpleGlyphLoader(controlPoints, endPoints, bounds, instructions);
Expand All @@ -96,7 +96,7 @@ private static Flags[] ReadFlags(BigEndianBinaryReader reader, int flagCount)
else
{
flag = (Flags)reader.ReadUInt8();
if (flag.HasFlag(Flags.Repeat))
if ((flag & Flags.Repeat) == Flags.Repeat)
{
repeatCount = reader.ReadByte();
}
Expand All @@ -115,21 +115,19 @@ private static short[] ReadCoordinates(BigEndianBinaryReader reader, int pointCo
for (int i = 0; i < pointCount; i++)
{
short dx;
if (flags[i].HasFlag(isByte))
Flags currentFlag = flags[i];
if ((currentFlag & isByte) == isByte)
{
byte b = reader.ReadByte();
dx = (short)(flags[i].HasFlag(signOrSame) ? b : -b);
dx = (short)((currentFlag & signOrSame) == signOrSame ? b : -b);
}
else if ((currentFlag & signOrSame) == signOrSame)
{
dx = 0;
}
else
{
if (flags[i].HasFlag(signOrSame))
{
dx = 0;
}
else
{
dx = reader.ReadInt16();
}
dx = reader.ReadInt16();
}

x += dx;
Expand Down
Loading