Skip to content

Commit

Permalink
added font line-height
Browse files Browse the repository at this point in the history
  • Loading branch information
ncannasse committed Dec 16, 2024
1 parent a77a282 commit 5405d59
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions h2d/domkit/BaseComponents.hx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class CustomParser extends domkit.CssValue.ValueParser {
public function parseFont( value : CssValue ) {
var path = null;
var sdf = null;
var offset = 0, offsetChar = 0;
var offset = 0, offsetChar = 0, lineHeight : Null<Float> = null;
switch(value) {
case VGroup(args):
var args = args.copy();
Expand All @@ -192,6 +192,14 @@ class CustomParser extends domkit.CssValue.ValueParser {
case VCall("offset", [v]):
offset = parseInt(v);
args.splice(1,1);
case null:
default:
}
switch( args[1] ) {
case VCall("line-height", [v]):
lineHeight = parseFloat(v);
args.splice(1,1);
case null:
default:
}
if( args[1] != null ) {
Expand Down Expand Up @@ -221,15 +229,17 @@ class CustomParser extends domkit.CssValue.ValueParser {
fnt = res.to(hxd.res.BitmapFont).toSdfFont(sdf.size, sdf.channel, sdf.cutoff, sdf.smooth);
else
fnt = res.to(hxd.res.BitmapFont).toFont();
if( offsetChar != 0 ) {
var c = offsetChar < 0 ? fnt.getChar("A".code) ?? fnt.getChar("0".code) ?? fnt.getChar("a".code) : fnt.getChar(offsetChar);
if( c != null ) offset = -Math.ceil(c.t.dy);
}
var defChar = offsetChar <= 0 ? fnt.getChar("A".code) ?? fnt.getChar("0".code) ?? fnt.getChar("a".code) : fnt.getChar(offsetChar);
if( offsetChar != 0 && defChar != null )
offset = -Math.ceil(defChar.t.dy);
if( offset != 0 ) {
fnt.setOffset(0,offset);
@:privateAccess fnt.lineHeight += offset;
@:privateAccess fnt.baseLine = fnt.calcBaseLine();
}
if( lineHeight != null && defChar != null ) {
@:privateAccess fnt.lineHeight = Math.ceil(defChar.t.height * lineHeight);
}
return fnt;
#end
}
Expand Down

0 comments on commit 5405d59

Please sign in to comment.