|
3 | 3 | /* |
4 | 4 | Part of the Processing project - http://processing.org |
5 | 5 |
|
6 | | - Copyright (c) 2004-10 Ben Fry & Casey Reas |
| 6 | + Copyright (c) 2012-15 The Processing Foundation |
| 7 | + Copyright (c) 2004-12 Ben Fry & Casey Reas |
7 | 8 | Copyright (c) 2001-04 Massachusetts Institute of Technology |
8 | 9 |
|
9 | 10 | This library is free software; you can redistribute it and/or |
@@ -84,7 +85,15 @@ public class PFont implements PConstants { |
84 | 85 | /** |
85 | 86 | * The original size of the font when it was first created |
86 | 87 | */ |
87 | | - protected int size; |
| 88 | + //protected int size; |
| 89 | + private int size; |
| 90 | + |
| 91 | + protected int density; |
| 92 | +// /** |
| 93 | +// * The size that this font will default to when drawn. Used to create fonts |
| 94 | +// * at 2x the size for high-res displays in OpenGL. |
| 95 | +// */ |
| 96 | +// protected int defaultSize; |
88 | 97 |
|
89 | 98 | /** true if smoothing was enabled for this font, used for native impl */ |
90 | 99 | protected boolean smooth; |
@@ -124,11 +133,10 @@ public class PFont implements PConstants { |
124 | 133 | protected Font font; |
125 | 134 |
|
126 | 135 | /** |
127 | | - * True if this font was loaded from a stream, rather than from the OS. |
128 | | - * It's always safe to use the native version of a font loaded from a TTF |
129 | | - * file, since that's how it'll look when exported. Otherwise, you'll have |
130 | | - * to use hint(ENABLE_NATIVE_FONTS) to get the native version working with |
131 | | - * renderers that support it. |
| 136 | + * True if this font was loaded from an InputStream, rather than by name |
| 137 | + * from the OS. It's best to use the native version of a font loaded from |
| 138 | + * a TTF file, since that will ensure that the font is available when the |
| 139 | + * sketch is exported. |
132 | 140 | */ |
133 | 141 | protected boolean stream; |
134 | 142 |
|
@@ -329,9 +337,11 @@ public PFont(Font font, boolean smooth, char charset[]) { |
329 | 337 | * |
330 | 338 | * @nowebref |
331 | 339 | */ |
332 | | - public PFont(Font font, boolean smooth, char charset[], boolean stream) { |
| 340 | + public PFont(Font font, boolean smooth, char charset[], |
| 341 | + boolean stream, int density) { |
333 | 342 | this(font, smooth, charset); |
334 | 343 | this.stream = stream; |
| 344 | + this.density = density; |
335 | 345 | } |
336 | 346 |
|
337 | 347 | /** |
@@ -536,6 +546,24 @@ public int getSize() { |
536 | 546 | } |
537 | 547 |
|
538 | 548 |
|
| 549 | +// public void setDefaultSize(int size) { |
| 550 | +// defaultSize = size; |
| 551 | +// } |
| 552 | + |
| 553 | + |
| 554 | + /** |
| 555 | + * Returns the size that will be used when textFont(font) is called. |
| 556 | + * When drawing with 2x pixel density, bitmap fonts in OpenGL need to be |
| 557 | + * created (behind the scenes) at double the requested size. This ensures |
| 558 | + * that they're shown at half on displays (so folks don't have to change |
| 559 | + * their sketch code). |
| 560 | + */ |
| 561 | + public int getDefaultSize() { |
| 562 | + //return defaultSize; |
| 563 | + return size / density; |
| 564 | + } |
| 565 | + |
| 566 | + |
539 | 567 | public boolean isStream() { |
540 | 568 | return stream; |
541 | 569 | } |
|
0 commit comments