html: handle text theme text properties

This commit is contained in:
Hannes Janetzek 2013-08-10 15:05:40 +02:00
parent 422e70b4a3
commit 9f5a89b610

View File

@ -11,9 +11,13 @@ public class GwtPaint implements Paint {
boolean stroke; boolean stroke;
float strokeWidth; float strokeWidth;
float fontSize;
Align mAlign; Align mAlign;
float fontSize = 12;
private FontStyle fontStyle = FontStyle.NORMAL;
private FontFamily fontFamily = FontFamily.DEFAULT;
//String font = "12px sans-serif"; //String font = "12px sans-serif";
String font = "13px Helvetica"; String font = "13px Helvetica";
@ -55,7 +59,6 @@ public class GwtPaint implements Paint {
@Override @Override
public void setStrokeCap(Cap cap) { public void setStrokeCap(Cap cap) {
stroke = true; stroke = true;
// TODO
} }
@Override @Override
@ -76,11 +79,14 @@ public class GwtPaint implements Paint {
@Override @Override
public void setTextSize(float size) { public void setTextSize(float size) {
fontSize = size; fontSize = size;
buildFont();
} }
@Override @Override
public void setTypeface(FontFamily fontFamily, FontStyle fontStyle) { public void setTypeface(FontFamily fontFamily, FontStyle fontStyle) {
this.fontStyle = fontStyle;
this.fontFamily = fontFamily;
buildFont();
} }
@Override @Override
@ -88,9 +94,10 @@ public class GwtPaint implements Paint {
return GwtCanvasAdapter.getTextWidth(text, font); return GwtCanvasAdapter.getTextWidth(text, font);
} }
// FIXME all estimates. no idea how to properly measure canvas text..
@Override @Override
public float getFontHeight() { public float getFontHeight() {
return 14 + strokeWidth * 2; return 2 + fontSize + strokeWidth * 2;
} }
@Override @Override
@ -98,4 +105,20 @@ public class GwtPaint implements Paint {
return 4 + strokeWidth; return 4 + strokeWidth;
} }
void buildFont(){
StringBuilder sb = new StringBuilder();
if (this.fontStyle == FontStyle.BOLD)
sb.append("bold ");
else if (this.fontStyle == FontStyle.ITALIC)
sb.append("italic ");
sb.append(Math.round(this.fontSize));
sb.append("px ");
sb.append("Helvetica");
this.font = sb.toString();
}
} }