Skip to content

Commit

Permalink
Alternative to #7357 for setting glyph page index. (#7388)
Browse files Browse the repository at this point in the history
* Alternative to #7357 for setting glyph page index.

* Spotless didn't seem to run initially.

The only "issue" is an unused import, which I guess is technically a code style violation of the most minor variety.

---------

Co-authored-by: Tommy Ettinger <tommy.ettinger@gmail.com>
  • Loading branch information
NathanSweet and tommyettinger committed Apr 27, 2024
1 parent 406f7d8 commit f2f176f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.badlogic.gdx.graphics.g2d.PixmapPacker;
import com.badlogic.gdx.graphics.g2d.PixmapPacker.GuillotineStrategy;
import com.badlogic.gdx.graphics.g2d.PixmapPacker.PackStrategy;
import com.badlogic.gdx.graphics.g2d.PixmapPacker.PixmapPackerRectangle;
import com.badlogic.gdx.graphics.g2d.PixmapPacker.SkylineStrategy;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g2d.freetype.FreeType.Bitmap;
Expand All @@ -42,7 +43,6 @@
import com.badlogic.gdx.graphics.g2d.freetype.FreeType.SizeMetrics;
import com.badlogic.gdx.graphics.g2d.freetype.FreeType.Stroker;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.GdxRuntimeException;
Expand Down Expand Up @@ -598,9 +598,8 @@ public FreeTypeBitmapFontData generateData (FreeTypeFontParameter parameter, Fre
}
}

String pixmapName = glyph.hashCode() + "_" + glyph.id;
Rectangle rect = packer.pack(pixmapName, mainPixmap);
glyph.page = packer.getPageIndex(pixmapName);
PixmapPackerRectangle rect = packer.pack(mainPixmap);
glyph.page = packer.getPages().indexOf(rect.page, true);
glyph.srcX = (int)rect.x;
glyph.srcY = (int)rect.y;

Expand Down
14 changes: 8 additions & 6 deletions gdx/src/com/badlogic/gdx/graphics/g2d/PixmapPacker.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void sort (Array<Pixmap> images) {

/** Inserts the pixmap without a name. It cannot be looked up by name.
* @see #pack(String, Pixmap) */
public synchronized Rectangle pack (Pixmap image) {
public synchronized PixmapPackerRectangle pack (Pixmap image) {
return pack(null, image);
}

Expand All @@ -162,7 +162,7 @@ public synchronized Rectangle pack (Pixmap image) {
* @return Rectangle describing the area the pixmap was rendered to.
* @throws GdxRuntimeException in case the image did not fit due to the page size being too small or providing a duplicate
* name. */
public synchronized Rectangle pack (String name, Pixmap image) {
public synchronized PixmapPackerRectangle pack (String name, Pixmap image) {
if (disposed) return null;
if (name != null && getRect(name) != null)
throw new GdxRuntimeException("Pixmap has already been packed with name: " + name);
Expand Down Expand Up @@ -282,6 +282,7 @@ public synchronized Rectangle pack (String name, Pixmap image) {
pixmapToDispose.dispose();
}

rect.page = page;
return rect;
}

Expand Down Expand Up @@ -849,10 +850,11 @@ private int getSplitPoint (Pixmap raster, int startX, int startY, boolean startP
}

public static class PixmapPackerRectangle extends Rectangle {
int[] splits;
int[] pads;
int offsetX, offsetY;
int originalWidth, originalHeight;
public Page page;
public int[] splits;
public int[] pads;
public int offsetX, offsetY;
public int originalWidth, originalHeight;

PixmapPackerRectangle (int x, int y, int width, int height) {
super(x, y, width, height);
Expand Down

0 comments on commit f2f176f

Please sign in to comment.