Skip to content

Commit cd9b89e

Browse files
committed
Added font override mechanism
1 parent 962a97d commit cd9b89e

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

arc-core/src/arc/graphics/g2d/Font.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,10 @@ public FontData(Fi fontFile, boolean flip){
555555
load(fontFile, flip);
556556
}
557557

558+
public void setOverride(FontData override){
559+
//not implemented for non-freetype fonts
560+
}
561+
558562
public void addFallback(FontData data){
559563
//not implemented for non-freetype fonts
560564
}

extensions/freetype/src/arc/freetype/FreeTypeFontGenerator.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,14 @@ public static class FreeTypeFontData extends FontData implements Disposable{
691691
Seq<Glyph> glyphs;
692692
private boolean dirty;
693693
Seq<FontData> fallback = new Seq<>();
694+
@Nullable FontData override;
695+
696+
/** Sets a font to override the glyphs of this one, if they are available. This is the opposite of a fallback. */
697+
@Override
698+
public void setOverride(FontData override){
699+
this.override = override;
700+
override.capHeight = capHeight;
701+
}
694702

695703
@Override
696704
public void addFallback(FontData data){
@@ -701,6 +709,15 @@ public void addFallback(FontData data){
701709

702710
@Override
703711
public Glyph getGlyph(char ch){
712+
if(override != null){
713+
Glyph result = override.getGlyph(ch);
714+
if(result != override.missingGlyph){
715+
setGlyph(ch, result);
716+
dirty = true;
717+
return result;
718+
}
719+
}
720+
704721
Glyph glyph = super.getGlyph(ch);
705722
if(glyph == null && generator != null){
706723
generator.setPixelSizes(0, parameter.size);

0 commit comments

Comments
 (0)