-
-
Notifications
You must be signed in to change notification settings - Fork 845
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
text: Allow specifying multiple device fonts for text fields #19274
Merged
+423
−42
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e815455
tests: Support device fonts with case-insensitive names
kjarosh 8fb4765
core: Add FontType.is_embedded() method
kjarosh 3b617de
text: Allow specifying multiple device fonts for text fields
kjarosh 2e77280
core: Add DefaultFont.from_name()
kjarosh 09f3548
tests: Add fonts/device_font_list test
kjarosh 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package { | ||
import flash.display.*; | ||
import flash.text.*; | ||
|
||
[SWF(width="100", height="200")] | ||
public class Test extends Sprite { | ||
[Embed(source="TestFontA.ttf", fontName="EmbeddedTestFontA", embedAsCFF="false", unicodeRange="U+0061-U+0064")] | ||
private var EmbeddedTestFontA:Class; | ||
|
||
[Embed(source="TestFontB.ttf", fontName="EmbeddedTestFontB", embedAsCFF="false", unicodeRange="U+0061-U+0064")] | ||
private var EmbeddedTestFontB:Class; | ||
|
||
private var nextY: Number = 0; | ||
|
||
private var fontListsDevice: Array = [ | ||
"Totally Unknown, TestFontA , TestFontB", | ||
" testFOntB , TestFontA , TestFontB", | ||
]; | ||
private var fontListsEmbedded: Array = [ | ||
"Totally Unknown, EmbeddedTestFontA, EmbeddedTestFontB", | ||
"EmbeddedTestFontA", | ||
" EmbeddedTestFontA", | ||
"EmbeddedTestFontA ", | ||
" EmbeddedTestFontA ", | ||
" embeddedTESTFonta", | ||
]; | ||
|
||
public function Test() { | ||
stage.scaleMode = "noScale"; | ||
|
||
for each (var embedded in [false, true]) { | ||
var fontLists = embedded ? fontListsEmbedded : fontListsDevice; | ||
for each (var fontList in fontLists) { | ||
testFontListCss(embedded, fontList); | ||
testFontListFormat(embedded, fontList); | ||
} | ||
} | ||
} | ||
|
||
function testFontListCss(embedded: Boolean, fontList: String) { | ||
trace("Testing CSS font list fallback:"); | ||
trace(" Embedded? = " + embedded); | ||
trace(" Font list? = " + fontList); | ||
|
||
var style: StyleSheet = new StyleSheet(); | ||
|
||
var classFontList:Object = new Object(); | ||
classFontList.fontFamily = fontList; | ||
classFontList.fontSize = 20; | ||
style.setStyle(".fontlist", classFontList); | ||
|
||
var text: TextField = new TextField(); | ||
text.embedFonts = embedded; | ||
text.styleSheet = style; | ||
|
||
text.width = 100; | ||
text.height = 50; | ||
text.y = nextY; | ||
nextY += text.height; | ||
text.text = "<span class='fontlist'>abc</span>"; | ||
|
||
addChild(text); | ||
|
||
traceChars(text); | ||
} | ||
|
||
function testFontListFormat(embedded: Boolean, fontList: String) { | ||
trace("Testing TextFormat font list fallback:"); | ||
trace(" Embedded? = " + embedded); | ||
trace(" Font list? = " + fontList); | ||
|
||
var tf: TextFormat = new TextFormat(fontList, 20); | ||
var text: TextField = new TextField(); | ||
text.embedFonts = embedded; | ||
text.defaultTextFormat = tf; | ||
|
||
text.width = 100; | ||
text.height = 50; | ||
text.y = nextY; | ||
nextY += text.height; | ||
text.text = "abc"; | ||
|
||
addChild(text); | ||
|
||
traceChars(text); | ||
} | ||
|
||
private function traceChars(text: TextField) { | ||
traceChar(text, 0); | ||
traceChar(text, 1); | ||
traceChar(text, 2); | ||
} | ||
|
||
private function traceChar(text: TextField, i: int) { | ||
try { | ||
var ch: Number = text.getCharBoundaries(i).width; | ||
if (ch == 32) { | ||
trace(" Char " + i + " is TestFontA"); | ||
} | ||
if (ch == 30) { | ||
trace(" Char " + i + " is TestFontB"); | ||
} | ||
} catch(e) {} | ||
} | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
SplineFontDB: 3.2 | ||
FontName: TestFontA | ||
FullName: TestFontA | ||
FamilyName: TestFontA | ||
Weight: Regular | ||
Copyright: Copyright (c) 2024, Kamil Jarosz | ||
UComments: "2024-7-24: Created with FontForge (http://fontforge.org)" | ||
Version: 001.000 | ||
ItalicAngle: 0 | ||
UnderlinePosition: -76 | ||
UnderlineWidth: 38 | ||
Ascent: 800 | ||
Descent: 200 | ||
InvalidEm: 0 | ||
LayerCount: 2 | ||
Layer: 0 0 "Back" 1 | ||
Layer: 1 0 "Fore" 0 | ||
XUID: [1021 253 198287149 6396829] | ||
StyleMap: 0x0000 | ||
FSType: 0 | ||
OS2Version: 0 | ||
OS2_WeightWidthSlopeOnly: 0 | ||
OS2_UseTypoMetrics: 1 | ||
CreationTime: 1721856925 | ||
ModificationTime: 1737156144 | ||
PfmFamily: 17 | ||
TTFWeight: 400 | ||
TTFWidth: 5 | ||
LineGap: 100 | ||
VLineGap: 0 | ||
OS2TypoAscent: 0 | ||
OS2TypoAOffset: 1 | ||
OS2TypoDescent: 0 | ||
OS2TypoDOffset: 1 | ||
OS2TypoLinegap: 100 | ||
OS2WinAscent: 0 | ||
OS2WinAOffset: 1 | ||
OS2WinDescent: 0 | ||
OS2WinDOffset: 1 | ||
HheadAscent: 0 | ||
HheadAOffset: 1 | ||
HheadDescent: 0 | ||
HheadDOffset: 1 | ||
OS2Vendor: 'PfEd' | ||
MarkAttachClasses: 1 | ||
DEI: 91125 | ||
Encoding: ISO8859-1 | ||
UnicodeInterp: none | ||
NameList: AGL For New Fonts | ||
DisplaySize: -48 | ||
AntiAlias: 1 | ||
FitToEm: 0 | ||
WinInfo: 0 30 10 | ||
BeginPrivate: 0 | ||
EndPrivate | ||
BeginChars: 256 2 | ||
|
||
StartChar: a | ||
Encoding: 97 97 0 | ||
Width: 1600 | ||
Flags: HW | ||
LayerCount: 2 | ||
Fore | ||
SplineSet | ||
0 800 m 1 | ||
1600 800 l 1 | ||
1600 0 l 1 | ||
0 0 l 1 | ||
0 800 l 1 | ||
EndSplineSet | ||
EndChar | ||
|
||
StartChar: c | ||
Encoding: 99 99 1 | ||
Width: 1600 | ||
Flags: HW | ||
LayerCount: 2 | ||
Fore | ||
SplineSet | ||
0 800 m 1 | ||
1600 800 l 1 | ||
1600 0 l 1 | ||
0 0 l 1 | ||
0 800 l 1 | ||
EndSplineSet | ||
EndChar | ||
EndChars | ||
EndSplineFont |
Binary file not shown.
Oops, something went wrong.
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.
Would this work if you iterated on the split without collecting into a Vec?
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.
I could do that, sure, but then I'm using the vec to get the fallback font name and IMO it's clearer when I do
font_names.first()
compared to not collecting into a vec and doing something else.