Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
JayDeeTay committed Jan 1, 2025
2 parents a920130 + a75f7b9 commit 76f4343
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public int[] getCrop() {
*/
public LabelMaker(boolean fullColor) {
mFullColor = fullColor;
mStrikeWidth = 512;
mStrikeWidth = -1;
mStrikeHeight = -1;
}

Expand All @@ -159,8 +159,17 @@ public TextureReference initialize(GL10 gl, Paint textPaint, LabelData[] labels,
GL10.GL_CLAMP_TO_EDGE);

gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE);

int minHeight = addLabelsInternal(gl, textPaint, false, labels);

// Maximum allowed text label width, set to window width
int maxLabelWidth = mRes.getDisplayMetrics().widthPixels;
// mStrikeWidth should be enough to hold maxTextWidth and
// rounded up to the nearest power of two, since textures have to be a power of two in size.
int roundedWidth = 512;
while (roundedWidth < maxLabelWidth)
roundedWidth <<= 1;
mStrikeWidth = roundedWidth;

int minHeight = addLabelsInternal(gl, textPaint, false, labels, maxLabelWidth);

// Round up to the nearest power of two, since textures have to be a power of two in size.
int roundedHeight = 1;
Expand All @@ -173,7 +182,7 @@ public TextureReference initialize(GL10 gl, Paint textPaint, LabelData[] labels,
mTexelHeight = (float) (1.0 / mStrikeHeight);

beginAdding(gl);
addLabelsInternal(gl, textPaint, true, labels);
addLabelsInternal(gl, textPaint, true, labels, maxLabelWidth);
endAdding(gl);

return mTexture;
Expand All @@ -194,10 +203,11 @@ public void shutdown(GL10 gl) {
* @param gl
* @param textPaint the paint of the label
* @param labels the array of labels being added
* @param maxLabelWidth maximum display width of a label
* @return the required height
*/
private int addLabelsInternal(GL10 gl, Paint textPaint, boolean drawToCanvas,
LabelData[] labels) {
LabelData[] labels, int maxLabelWidth) {
int u = 0;
int v = 0;
int lineHeight = 0;
Expand Down Expand Up @@ -229,7 +239,7 @@ private int addLabelsInternal(GL10 gl, Paint textPaint, boolean drawToCanvas,
// If it's wider than the screen, try it again with a font size of 1
// smaller.
fontSize--;
} while (fontSize > 0 && width > mRes.getDisplayMetrics().widthPixels);
} while (fontSize > 0 && width > maxLabelWidth);

int nextU;

Expand Down

0 comments on commit 76f4343

Please sign in to comment.