Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use a default font if one is not specified in the format.

  • Loading branch information...
commit 16b06edf3e0f9afd2f174d430675897504adfdee 1 parent 672a753
@samskivert samskivert authored
View
2  android/src/playn/android/AndroidFont.java
@@ -24,6 +24,8 @@
class AndroidFont extends AbstractFont {
+ public static AndroidFont DEFAULT = new AndroidFont("Default", Style.PLAIN, 14, Typeface.DEFAULT);
+
public final Typeface typeface;
public AndroidFont(String name, Style style, float size) {
View
25 android/src/playn/android/AndroidTextLayout.java
@@ -28,11 +28,12 @@
@SuppressWarnings("deprecation")
class AndroidTextLayout implements TextLayout {
- private float width, height;
- private TextFormat format;
- private Paint paint;
- private Paint.FontMetrics metrics;
- private List<Line> lines = new ArrayList<Line>();
+ private final TextFormat format;
+ private final AndroidFont font;
+ private final Paint paint;
+ private final float width, height;
+ private final Paint.FontMetrics metrics;
+ private final List<Line> lines = new ArrayList<Line>();
private static class Line {
public final String text;
@@ -65,15 +66,11 @@ public TextFormat format() {
AndroidTextLayout(String text, TextFormat format) {
this.format = format;
+ this.font = (format.font == null) ? AndroidFont.DEFAULT : (AndroidFont)format.font;
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
- if (format.font != null) {
- paint.setTypeface(((AndroidFont)format.font).typeface);
- // TODO
- // float density = getContext().getResources().getDisplayMetrics().density;
- // float scaledPx = format.font.size() * density;
- paint.setTextSize(format.font.size());
- }
+ paint.setTypeface(font.typeface);
+ paint.setTextSize(font.size());
metrics = paint.getFontMetrics();
// normalize newlines in the text (Windows: CRLF -> LF, Mac OS pre-X: CR -> LF)
@@ -147,8 +144,8 @@ void breakLine(String text) {
}
void draw(Canvas canvas, float x, float y, Paint paint) {
- paint.setTypeface(((AndroidFont)format.font).typeface);
- paint.setTextSize(format.font.size());
+ paint.setTypeface(font.typeface);
+ paint.setTextSize(font.size());
float yoff = 0;
for (Line line : lines) {
Please sign in to comment.
Something went wrong with that request. Please try again.