Class STBTruetype
- java.lang.Object
-
- org.lwjgl.stb.STBTruetype
-
public class STBTruetype extends java.lang.Object
Native bindings to stb_truetype.h from the stb library.This library processes TrueType files:
- parse files
- extract glyph metrics
- extract glyph shapes
- render glyphs to one-channel bitmaps with antialiasing (box filter)
ADDITIONAL DOCUMENTATION
Some important concepts to understand to use this library:
Codepoint
Characters are defined by unicode codepoints, e.g. 65 is uppercase A, 231 is lowercase c with a cedilla, 0x7e30 is the hiragana for "ma".
Glyph
A visual character shape (every codepoint is rendered as some glyph)
Glyph index
A font-specific integer ID representing a glyph
Baseline
Glyph shapes are defined relative to a baseline, which is the bottom of uppercase characters. Characters extend both above and below the baseline.
Current Point
As you draw text to the screen, you keep track of a "current point" which is the origin of each character. The current point's vertical position is the baseline. Even "baked fonts" use this model.
Vertical Font Metrics
The vertical qualities of the font, used to vertically position and space the characters. See docs for
GetFontVMetrics
.Font Size in Pixels or Points
The preferred interface for specifying font sizes in stb_truetype is to specify how tall the font's vertical extent should be in pixels. If that sounds good enough, skip the next paragraph.
Most font APIs instead use "points", which are a common typographic measurement for describing font size, defined as 72 points per inch. stb_truetype provides a point API for compatibility. However, true "per inch" conventions don't make much sense on computer displays since different monitors have different number of pixels per inch. For example, Windows traditionally uses a convention that there are 96 pixels per inch, thus making 'inch' measurements have nothing to do with inches, and thus effectively defining a point to be 1.333 pixels. Additionally, the TrueType font data provides an explicit scale factor to scale a given font's glyphs to points, but the author has observed that this scale factor is often wrong for non-commercial fonts, thus making fonts scaled in points according to the TrueType spec incoherently sized in practice.
ADVANCED USAGE
Quality:
- Use the functions with Subpixel at the end to allow your characters to have subpixel positioning. Since the font is anti-aliased, not hinted, this is very important for quality. (This is not possible with baked fonts.)
- Kerning is now supported, and if you're supporting subpixel rendering then kerning is worth using to give your text a polished look.
Performance:
- Convert Unicode codepoints to glyph indexes and operate on the glyphs; if you don't do this, stb_truetype is forced to do the conversion on every call.
- There are a lot of memory allocations. We should modify it to take a temp buffer and allocate from the temp buffer (without freeing), should help performance a lot.
NOTES
The system uses the raw data found in the .ttf file without changing it and without building auxiliary data structures. This is a bit inefficient on little-endian systems (the data is big-endian), but assuming you're caching the bitmaps or glyph shapes this shouldn't be a big deal.
It appears to be very hard to programmatically determine what font a given file is in a general way. I provide an API for this, but I don't recommend it.
SAMPLE PROGRAMS
Incomplete text-in-3d-api example, which draws quads properly aligned to be lossless:
unsigned char ttf_buffer[1<<20]; unsigned char temp_bitmap[512*512]; stbtt_bakedchar cdata[96]; // ASCII 32..126 is 95 glyphs GLuint ftex; void my_stbtt_initfont(void) { fread(ttf_buffer, 1, 1<<20, fopen("c:/windows/fonts/times.ttf", "rb")); stbtt_BakeFontBitmap(ttf_buffer,0, 32.0, temp_bitmap,512,512, 32,96, cdata); // no guarantee this fits! // can free ttf_buffer at this point glGenTextures(1, &ftex); glBindTexture(GL_TEXTURE_2D, ftex); glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 512,512, 0, GL_ALPHA, GL_UNSIGNED_BYTE, temp_bitmap); // can free temp_bitmap at this point glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } void my_stbtt_print(float x, float y, char *text) { // assume orthographic projection with units = screen pixels, origin at top left glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, ftex); glBegin(GL_QUADS); while (*text) { if (*text >= 32 && *text < 128) { stbtt_aligned_quad q; stbtt_GetBakedQuad(cdata, 512,512, *text-32, &x,&y,&q,1);//1=opengl & d3d10+,0=d3d9 glTexCoord2f(q.s0,q.t1); glVertex2f(q.x0,q.y0); glTexCoord2f(q.s1,q.t1); glVertex2f(q.x1,q.y0); glTexCoord2f(q.s1,q.t0); glVertex2f(q.x1,q.y1); glTexCoord2f(q.s0,q.t0); glVertex2f(q.x0,q.y1); } ++text; } glEnd(); }
Complete program (this compiles): get a single bitmap, print as ASCII art:
char ttf_buffer[1<<25]; int main(int argc, char **argv) { stbtt_fontinfo font; unsigned char *bitmap; int w,h,i,j,c = (argc > 1 ? atoi(argv[1]) : 'a'), s = (argc > 2 ? atoi(argv[2]) : 20); fread(ttf_buffer, 1, 1<<25, fopen(argc > 3 ? argv[3] : "c:/windows/fonts/arialbd.ttf", "rb")); stbtt_InitFont(&font, ttf_buffer, stbtt_GetFontOffsetForIndex(ttf_buffer,0)); bitmap = stbtt_GetCodepointBitmap(&font, 0,stbtt_ScaleForPixelHeight(&font, s), c, &w, &h, 0,0); for (j=0; j < h; ++j) { for (i=0; i < w; ++i) putchar(" .:ioVM@"[bitmap[j*w+i]>>5]); putchar('\n'); } return 0; }
Complete program: print "Hello World!" banner, with bugs:
char buffer[24<<20]; unsigned char screen[20][79]; int main(int arg, char **argv) { stbtt_fontinfo font; int i,j,ascent,baseline,ch=0; float scale, xpos=2; // leave a little padding in case the character extends left char *text = "Heljo World!"; fread(buffer, 1, 1000000, fopen("c:/windows/fonts/arialbd.ttf", "rb")); stbtt_InitFont(&font, buffer, 0); scale = stbtt_ScaleForPixelHeight(&font, 15); stbtt_GetFontVMetrics(&font, &ascent,0,0); baseline = (int) (ascent*scale); while (text[ch]) { int advance,lsb,x0,y0,x1,y1; float x_shift = xpos - (float) floor(xpos); stbtt_GetCodepointHMetrics(&font, text[ch], &advance, &lsb); stbtt_GetCodepointBitmapBoxSubpixel(&font, text[ch], scale,scale,x_shift,0, &x0,&y0,&x1,&y1); stbtt_MakeCodepointBitmapSubpixel(&font, &screen[baseline + y0][(int) xpos + x0], x1-x0,y1-y0, 79, scale,scale,x_shift,0, text[ch]); // note that this stomps the old data, so where character boxes overlap (e.g. 'lj') it's wrong // because this API is really for baking character bitmaps into textures. if you want to render // a sequence of characters, you really need to render each bitmap to a temp buffer, then // "alpha blend" that into the working buffer xpos += (advance * scale); if (text[ch+1]) xpos += scale*stbtt_GetCodepointKernAdvance(&font, text[ch],text[ch+1]); ++ch; } for (j=0; j < 20; ++j) { for (i=0; i < 78; ++i) putchar(" .:ioVM@"[screen[j][i]>>5]); putchar('\n'); } return 0; }
Finding the right font...
You should really just solve this offline, keep your own tables of what font is what, and don't try to get it out of the .ttf file. That's because getting it out of the .ttf file is really hard, because the names in the file can appear in many possible encodings, in many possible languages, and e.g. if you need a case-insensitive comparison, the details of that depend on the encoding & language in a complex way (actually underspecified in truetype, but also gigantic).
But you can use the provided functions in two possible ways:
FindMatchingFont
will use *case-sensitive* comparisons on unicode-encoded names to try to find the font you want; you can run this before callingInitFont
GetFontNameString
lets you get any of the various strings from the file yourself and do your own comparisons on them. You have to have calledInitFont
first.
-
-
Field Summary
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static int
stbtt_BakeFontBitmap(java.nio.ByteBuffer data, float pixel_height, java.nio.ByteBuffer pixels, int pw, int ph, int first_char, STBTTBakedChar.Buffer chardata)
Bakes a font to a bitmap for use as texture.static boolean
stbtt_CompareUTF8toUTF16_bigendian(java.nio.ByteBuffer s1, java.nio.ByteBuffer s2)
Returns 1/0 whether the first string interpreted as utf8 is identical to the second string interpreted as big-endian utf16...static int
stbtt_FindGlyphIndex(STBTTFontinfo info, int unicode_codepoint)
If you're going to perform multiple operations on the same character and you want a speed-up, call this function with the character you're going to process, then use glyph-based functions instead of the codepoint-based functions.static int
stbtt_FindMatchingFont(java.nio.ByteBuffer fontdata, java.nio.ByteBuffer name, int flags)
Returns the offset (not index) of the font that matches, or -1 if none.static int
stbtt_FindMatchingFont(java.nio.ByteBuffer fontdata, java.lang.CharSequence name, int flags)
Returns the offset (not index) of the font that matches, or -1 if none.static void
stbtt_FreeBitmap(java.nio.ByteBuffer bitmap, long userdata)
Frees a bitmap allocated byGetCodepointBitmap
,GetCodepointBitmapSubpixel
,GetGlyphBitmap
orGetGlyphBitmapSubpixel
.static void
stbtt_FreeShape(STBTTFontinfo info, STBTTVertex.Buffer vertices)
Frees the data allocated byGetCodepointShape
andGetGlyphShape
.static void
stbtt_GetBakedQuad(STBTTBakedChar.Buffer chardata, int pw, int ph, int char_index, float[] xpos, float[] ypos, STBTTAlignedQuad q, boolean opengl_fillrule)
Array version of:GetBakedQuad
static void
stbtt_GetBakedQuad(STBTTBakedChar.Buffer chardata, int pw, int ph, int char_index, java.nio.FloatBuffer xpos, java.nio.FloatBuffer ypos, STBTTAlignedQuad q, boolean opengl_fillrule)
Computes quad to draw for a given char and advances the current position.static java.nio.ByteBuffer
stbtt_GetCodepointBitmap(STBTTFontinfo info, float scale_x, float scale_y, int codepoint, int[] width, int[] height, int[] xoff, int[] yoff)
Array version of:GetCodepointBitmap
static java.nio.ByteBuffer
stbtt_GetCodepointBitmap(STBTTFontinfo info, float scale_x, float scale_y, int codepoint, java.nio.IntBuffer width, java.nio.IntBuffer height, java.nio.IntBuffer xoff, java.nio.IntBuffer yoff)
Allocates a large-enough single-channel 8bpp bitmap and renders the specified character/glyph at the specified scale into it, with antialiasing.static void
stbtt_GetCodepointBitmapBox(STBTTFontinfo font, int codepoint, float scale_x, float scale_y, int[] ix0, int[] iy0, int[] ix1, int[] iy1)
Array version of:GetCodepointBitmapBox
static void
stbtt_GetCodepointBitmapBox(STBTTFontinfo font, int codepoint, float scale_x, float scale_y, java.nio.IntBuffer ix0, java.nio.IntBuffer iy0, java.nio.IntBuffer ix1, java.nio.IntBuffer iy1)
Get the bbox of the bitmap centered around the glyph origin; so the bitmap width isix1-ix0
, height isiy1-iy0
, and location to place the bitmap top left is(leftSideBearing*scale,iy0)
.static void
stbtt_GetCodepointBitmapBoxSubpixel(STBTTFontinfo font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int[] ix0, int[] iy0, int[] ix1, int[] iy1)
Array version of:GetCodepointBitmapBoxSubpixel
static void
stbtt_GetCodepointBitmapBoxSubpixel(STBTTFontinfo font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, java.nio.IntBuffer ix0, java.nio.IntBuffer iy0, java.nio.IntBuffer ix1, java.nio.IntBuffer iy1)
Same asGetCodepointBitmapBox
, but you can specify a subpixel shift for the character.static java.nio.ByteBuffer
stbtt_GetCodepointBitmapSubpixel(STBTTFontinfo info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int[] width, int[] height, int[] xoff, int[] yoff)
Array version of:GetCodepointBitmapSubpixel
static java.nio.ByteBuffer
stbtt_GetCodepointBitmapSubpixel(STBTTFontinfo info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, java.nio.IntBuffer width, java.nio.IntBuffer height, java.nio.IntBuffer xoff, java.nio.IntBuffer yoff)
Same asGetCodepointBitmap
, but you can specify a subpixel shift for the character.static boolean
stbtt_GetCodepointBox(STBTTFontinfo info, int codepoint, int[] x0, int[] y0, int[] x1, int[] y1)
Array version of:GetCodepointBox
static boolean
stbtt_GetCodepointBox(STBTTFontinfo info, int codepoint, java.nio.IntBuffer x0, java.nio.IntBuffer y0, java.nio.IntBuffer x1, java.nio.IntBuffer y1)
Gets the bounding box of the visible part of the glyph, in unscaled coordinates.static void
stbtt_GetCodepointHMetrics(STBTTFontinfo info, int codepoint, int[] advanceWidth, int[] leftSideBearing)
Array version of:GetCodepointHMetrics
static void
stbtt_GetCodepointHMetrics(STBTTFontinfo info, int codepoint, java.nio.IntBuffer advanceWidth, java.nio.IntBuffer leftSideBearing)
Returns horizontal metrics for the specified codepoint.static int
stbtt_GetCodepointKernAdvance(STBTTFontinfo info, int ch1, int ch2)
Returns the additional amount to add to theadvance
value betweench1
andch2
.static STBTTVertex.Buffer
stbtt_GetCodepointShape(STBTTFontinfo info, int unicode_codepoint)
Returns number of vertices and fills*vertices
with the pointer to themstatic int
stbtt_GetCodepointShape(STBTTFontinfo info, int unicode_codepoint, org.lwjgl.PointerBuffer vertices)
Returns number of vertices and fills*vertices
with the pointer to themstatic void
stbtt_GetFontBoundingBox(STBTTFontinfo info, int[] x0, int[] y0, int[] x1, int[] y1)
Array version of:GetFontBoundingBox
static void
stbtt_GetFontBoundingBox(STBTTFontinfo info, java.nio.IntBuffer x0, java.nio.IntBuffer y0, java.nio.IntBuffer x1, java.nio.IntBuffer y1)
Returns the bounding box around all possible characters.static java.nio.ByteBuffer
stbtt_GetFontNameString(STBTTFontinfo font, int platformID, int encodingID, int languageID, int nameID)
Returns the string (which may be big-endian double byte, e.g.static int
stbtt_GetFontOffsetForIndex(java.nio.ByteBuffer data, int index)
Each .ttf/.ttc file may have more than one font.static void
stbtt_GetFontVMetrics(STBTTFontinfo info, int[] ascent, int[] descent, int[] lineGap)
Array version of:GetFontVMetrics
static void
stbtt_GetFontVMetrics(STBTTFontinfo info, java.nio.IntBuffer ascent, java.nio.IntBuffer descent, java.nio.IntBuffer lineGap)
Returns vertical metrics for the specified font.static java.nio.ByteBuffer
stbtt_GetGlyphBitmap(STBTTFontinfo info, float scale_x, float scale_y, int glyph, int[] width, int[] height, int[] xoff, int[] yoff)
Array version of:GetGlyphBitmap
static java.nio.ByteBuffer
stbtt_GetGlyphBitmap(STBTTFontinfo info, float scale_x, float scale_y, int glyph, java.nio.IntBuffer width, java.nio.IntBuffer height, java.nio.IntBuffer xoff, java.nio.IntBuffer yoff)
Allocates a large-enough single-channel 8bpp bitmap and renders the specified character/glyph at the specified scale into it, with antialiasing.static void
stbtt_GetGlyphBitmapBox(STBTTFontinfo font, int glyph, float scale_x, float scale_y, int[] ix0, int[] iy0, int[] ix1, int[] iy1)
Array version of:GetGlyphBitmapBox
static void
stbtt_GetGlyphBitmapBox(STBTTFontinfo font, int glyph, float scale_x, float scale_y, java.nio.IntBuffer ix0, java.nio.IntBuffer iy0, java.nio.IntBuffer ix1, java.nio.IntBuffer iy1)
Get the bbox of the bitmap centered around the glyph origin; so the bitmap width isix1-ix0
, height isiy1-iy0
, and location to place the bitmap top left is(leftSideBearing*scale,iy0)
.static void
stbtt_GetGlyphBitmapBoxSubpixel(STBTTFontinfo font, int glyph, float scale_x, float scale_y, float shift_x, float shift_y, int[] ix0, int[] iy0, int[] ix1, int[] iy1)
Array version of:GetGlyphBitmapBoxSubpixel
static void
stbtt_GetGlyphBitmapBoxSubpixel(STBTTFontinfo font, int glyph, float scale_x, float scale_y, float shift_x, float shift_y, java.nio.IntBuffer ix0, java.nio.IntBuffer iy0, java.nio.IntBuffer ix1, java.nio.IntBuffer iy1)
Same asGetGlyphBitmapBox
, but you can specify a subpixel shift for the character.static java.nio.ByteBuffer
stbtt_GetGlyphBitmapSubpixel(STBTTFontinfo info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int[] width, int[] height, int[] xoff, int[] yoff)
Array version of:GetGlyphBitmapSubpixel
static java.nio.ByteBuffer
stbtt_GetGlyphBitmapSubpixel(STBTTFontinfo info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, java.nio.IntBuffer width, java.nio.IntBuffer height, java.nio.IntBuffer xoff, java.nio.IntBuffer yoff)
Same asGetGlyphBitmap
, but you can specify a subpixel shift for the character.static boolean
stbtt_GetGlyphBox(STBTTFontinfo info, int glyph_index, int[] x0, int[] y0, int[] x1, int[] y1)
Array version of:GetGlyphBox
static boolean
stbtt_GetGlyphBox(STBTTFontinfo info, int glyph_index, java.nio.IntBuffer x0, java.nio.IntBuffer y0, java.nio.IntBuffer x1, java.nio.IntBuffer y1)
Glyph version ofGetCodepointBox
, for greater efficiency.static void
stbtt_GetGlyphHMetrics(STBTTFontinfo info, int glyph_index, int[] advanceWidth, int[] leftSideBearing)
Array version of:GetGlyphHMetrics
static void
stbtt_GetGlyphHMetrics(STBTTFontinfo info, int glyph_index, java.nio.IntBuffer advanceWidth, java.nio.IntBuffer leftSideBearing)
Glyph version ofGetCodepointHMetrics
, for greater efficiency.static int
stbtt_GetGlyphKernAdvance(STBTTFontinfo info, int glyph1, int glyph2)
Glyph version ofGetCodepointKernAdvance
, for greater efficiency.static STBTTVertex.Buffer
stbtt_GetGlyphShape(STBTTFontinfo info, int glyph_index)
Glyph version ofGetCodepointShape
, for greater efficiency.static int
stbtt_GetGlyphShape(STBTTFontinfo info, int glyph_index, org.lwjgl.PointerBuffer vertices)
Glyph version ofGetCodepointShape
, for greater efficiency.static void
stbtt_GetPackedQuad(STBTTPackedchar.Buffer chardata, int pw, int ph, int char_index, float[] xpos, float[] ypos, STBTTAlignedQuad q, boolean align_to_integer)
Array version of:GetPackedQuad
static void
stbtt_GetPackedQuad(STBTTPackedchar.Buffer chardata, int pw, int ph, int char_index, java.nio.FloatBuffer xpos, java.nio.FloatBuffer ypos, STBTTAlignedQuad q, boolean align_to_integer)
Computes quad to draw for a given char and advances the current position.static boolean
stbtt_InitFont(STBTTFontinfo info, java.nio.ByteBuffer data)
Given an offset into the file that defines a font, this function builds the necessary cached info for the rest of the system.static boolean
stbtt_InitFont(STBTTFontinfo info, java.nio.ByteBuffer data, int offset)
Given an offset into the file that defines a font, this function builds the necessary cached info for the rest of the system.static boolean
stbtt_IsGlyphEmpty(STBTTFontinfo info, int glyph_index)
Returns non-zero if nothing is drawn for this glyph.static void
stbtt_MakeCodepointBitmap(STBTTFontinfo info, java.nio.ByteBuffer output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint)
Same asGetCodepointBitmap
, but you pass in storage for the bitmap in the form ofoutput
, with row spacing ofout_stride
bytes.static void
stbtt_MakeCodepointBitmapSubpixel(STBTTFontinfo info, java.nio.ByteBuffer output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint)
Same asMakeCodepointBitmap
, but you can specify a subpixel shift for the character.static void
stbtt_MakeGlyphBitmap(STBTTFontinfo info, java.nio.ByteBuffer output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph)
Same asGetGlyphBitmap
, but you pass in storage for the bitmap in the form ofoutput
, with row spacing ofout_stride
bytes.static void
stbtt_MakeGlyphBitmapSubpixel(STBTTFontinfo info, java.nio.ByteBuffer output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph)
Same asMakeGlyphBitmap
, but you can specify a subpixel shift for the character.static boolean
stbtt_PackBegin(STBTTPackContext spc, java.nio.ByteBuffer pixels, int width, int height, int stride_in_bytes, int padding)
Initializes a packing context stored in the passed-instbtt_pack_context
.static boolean
stbtt_PackBegin(STBTTPackContext spc, java.nio.ByteBuffer pixels, int width, int height, int stride_in_bytes, int padding, long alloc_context)
Initializes a packing context stored in the passed-instbtt_pack_context
.static void
stbtt_PackEnd(STBTTPackContext spc)
Cleans up the packing context and frees all memory.static boolean
stbtt_PackFontRange(STBTTPackContext spc, java.nio.ByteBuffer fontdata, int font_index, float font_size, int first_unicode_char_in_range, STBTTPackedchar.Buffer chardata_for_range)
Creates character bitmaps from thefont_index
'th font found in fontdata (usefont_index=0
if you don't know what that is).static boolean
stbtt_PackFontRanges(STBTTPackContext spc, java.nio.ByteBuffer fontdata, int font_index, STBTTPackRange.Buffer ranges)
Creates character bitmaps from multiple ranges of characters stored in ranges.static int
stbtt_PackFontRangesGatherRects(STBTTPackContext spc, STBTTFontinfo info, STBTTPackRange.Buffer ranges, STBRPRect rects)
Calling these functions in sequence is roughly equivalent to callingPackFontRanges
.static void
stbtt_PackFontRangesPackRects(STBTTPackContext spc, STBRPRect.Buffer rects)
static boolean
stbtt_PackFontRangesRenderIntoRects(STBTTPackContext spc, STBTTFontinfo info, STBTTPackRange.Buffer ranges, STBRPRect rects)
static void
stbtt_PackSetOversampling(STBTTPackContext spc, int h_oversample, int v_oversample)
Oversampling a font increases the quality by allowing higher-quality subpixel positioning, and is especially valuable at smaller text sizes.static int
STBTT_POINT_SIZE(int font_size)
Converts the full height of a character from ascender to descender, as computed byScaleForPixelHeight
, to a point size as computed byScaleForMappingEmToPixels
.static float
stbtt_ScaleForMappingEmToPixels(STBTTFontinfo info, float pixels)
Computes a scale factor to produce a font whose EM size is mapped topixels
tall.static float
stbtt_ScaleForPixelHeight(STBTTFontinfo info, float pixels)
Computes a scale factor to produce a font whose "height" ispixels
tall.
-
-
-
Field Detail
-
STBTT_vmove, STBTT_vline, STBTT_vcurve
Vertex type.
-
STBTT_MACSTYLE_DONTCARE, STBTT_MACSTYLE_BOLD, STBTT_MACSTYLE_ITALIC, STBTT_MACSTYLE_UNDERSCORE, STBTT_MACSTYLE_NONE
Style flags, use inFindMatchingFont
.
-
STBTT_PLATFORM_ID_UNICODE, STBTT_PLATFORM_ID_MAC, STBTT_PLATFORM_ID_ISO, STBTT_PLATFORM_ID_MICROSOFT
Platform IDs.
-
STBTT_UNICODE_EID_UNICODE_1_0, STBTT_UNICODE_EID_UNICODE_1_1, STBTT_UNICODE_EID_ISO_10646, STBTT_UNICODE_EID_UNICODE_2_0_BMP, STBTT_UNICODE_EID_UNICODE_2_0_FULL
Encoding IDs forPLATFORM_ID_UNICODE
.
-
STBTT_MS_EID_SYMBOL, STBTT_MS_EID_UNICODE_BMP, STBTT_MS_EID_SHIFTJIS, STBTT_MS_EID_UNICODE_FULL
Encoding IDs forPLATFORM_ID_MICROSOFT
.
-
STBTT_MAC_EID_ROMAN, STBTT_MAC_EID_JAPANESE, STBTT_MAC_EID_CHINESE_TRAD, STBTT_MAC_EID_KOREAN, STBTT_MAC_EID_ARABIC, STBTT_MAC_EID_HEBREW, STBTT_MAC_EID_GREEK, STBTT_MAC_EID_RUSSIAN
Encoding IDs forPLATFORM_ID_MAC
.
-
STBTT_MS_LANG_ENGLISH, STBTT_MS_LANG_CHINESE, STBTT_MS_LANG_DUTCH, STBTT_MS_LANG_FRENCH, STBTT_MS_LANG_GERMAN, STBTT_MS_LANG_HEBREW, STBTT_MS_LANG_ITALIAN, STBTT_MS_LANG_JAPANESE, STBTT_MS_LANG_KOREAN, STBTT_MS_LANG_RUSSIAN, STBTT_MS_LANG_SPANISH, STBTT_MS_LANG_SWEDISH
Language ID forPLATFORM_ID_MICROSOFT
.
-
STBTT_MAC_LANG_ENGLISH, STBTT_MAC_LANG_ARABIC, STBTT_MAC_LANG_DUTCH, STBTT_MAC_LANG_FRENCH, STBTT_MAC_LANG_GERMAN, STBTT_MAC_LANG_HEBREW, STBTT_MAC_LANG_ITALIAN, STBTT_MAC_LANG_JAPANESE, STBTT_MAC_LANG_KOREAN, STBTT_MAC_LANG_RUSSIAN, STBTT_MAC_LANG_SPANISH, STBTT_MAC_LANG_SWEDISH, STBTT_MAC_LANG_CHINESE_SIMPLIFIED, STBTT_MAC_LANG_CHINESE_TRAD
Language ID forPLATFORM_ID_MAC
.
-
-
Method Detail
-
stbtt_BakeFontBitmap
public static int stbtt_BakeFontBitmap(java.nio.ByteBuffer data, float pixel_height, java.nio.ByteBuffer pixels, int pw, int ph, int first_char, STBTTBakedChar.Buffer chardata)
Bakes a font to a bitmap for use as texture.This uses a very simply packing, use with
GetBakedQuad
.- Parameters:
data
- the font datapixel_height
- the font height, in pixelspixels
- a buffer in which to write the font bitmappw
- the bitmap width, in pixelsph
- the bitmap height, in pixelsfirst_char
- the first character to bakechardata
- an array ofSTBTTBakedChar
structs, it'snum_chars
long- Returns:
- if positive, the first unused row of the bitmap. If negative, returns the negative of the number of characters that fit. If 0, no characters fit and no rows were used.
-
stbtt_GetBakedQuad
public static void stbtt_GetBakedQuad(STBTTBakedChar.Buffer chardata, int pw, int ph, int char_index, java.nio.FloatBuffer xpos, java.nio.FloatBuffer ypos, STBTTAlignedQuad q, boolean opengl_fillrule)
Computes quad to draw for a given char and advances the current position.The coordinate system used assumes y increases downwards. Characters will extend both above and below the current position; see discussion of "BASELINE" above.
- Parameters:
chardata
- an array ofSTBTTBakedChar
structspw
- the bitmap width, in pixelsph
- the bitmap height, in pixelschar_index
- the character index in thechardata
arrayxpos
- the current x position, in screen pixel spaceypos
- the current y position, in screen pixel spaceq
- anSTBTTAlignedQuad
struct in which to return the quad to drawopengl_fillrule
- 1 if opengl fill rule; 0 if DX9 or earlier
-
stbtt_PackBegin
public static boolean stbtt_PackBegin(STBTTPackContext spc, java.nio.ByteBuffer pixels, int width, int height, int stride_in_bytes, int padding, long alloc_context)
Initializes a packing context stored in the passed-instbtt_pack_context
. Future calls using this context will pack characters into the bitmap passed in here: a 1-channel bitmap that is width x height.- Parameters:
spc
- anSTBTTPackContext
structpixels
- a buffer in which to store the bitmap datawidth
- the bitmap width, in pixelsheight
- the bitmap height, in pixelsstride_in_bytes
- the distance from one row to the next (or 0 to mean they are packed tightly together)padding
- the amount of padding to leave between each character (normally you want '1' for bitmaps you'll use as textures with bilinear filtering)alloc_context
- a pointer to an allocation context- Returns:
- 1 on success, 0 on failure
-
stbtt_PackBegin
public static boolean stbtt_PackBegin(STBTTPackContext spc, java.nio.ByteBuffer pixels, int width, int height, int stride_in_bytes, int padding)
Initializes a packing context stored in the passed-instbtt_pack_context
. Future calls using this context will pack characters into the bitmap passed in here: a 1-channel bitmap that is width x height.- Parameters:
spc
- anSTBTTPackContext
structpixels
- a buffer in which to store the bitmap datawidth
- the bitmap width, in pixelsheight
- the bitmap height, in pixelsstride_in_bytes
- the distance from one row to the next (or 0 to mean they are packed tightly together)padding
- the amount of padding to leave between each character (normally you want '1' for bitmaps you'll use as textures with bilinear filtering)- Returns:
- 1 on success, 0 on failure
-
stbtt_PackEnd
public static void stbtt_PackEnd(STBTTPackContext spc)
Cleans up the packing context and frees all memory.- Parameters:
spc
- anSTBTTPackContext
struct
-
STBTT_POINT_SIZE
public static int STBTT_POINT_SIZE(int font_size)
Converts the full height of a character from ascender to descender, as computed byScaleForPixelHeight
, to a point size as computed byScaleForMappingEmToPixels
.- Parameters:
font_size
- the full height of a character- Returns:
- the point size of the character
-
stbtt_PackFontRange
public static boolean stbtt_PackFontRange(STBTTPackContext spc, java.nio.ByteBuffer fontdata, int font_index, float font_size, int first_unicode_char_in_range, STBTTPackedchar.Buffer chardata_for_range)
Creates character bitmaps from thefont_index
'th font found in fontdata (usefont_index=0
if you don't know what that is). It createsnum_chars_in_range
bitmaps for characters with unicode values starting atfirst_unicode_char_in_range
and increasing. Data for how to render them is stored inchardata_for_range
; pass these toGetPackedQuad
to get back renderable quads.- Parameters:
spc
- anSTBTTPackContext
structfontdata
- the font datafont_index
- the font index (use 0 if you don't know what that isfont_size
- the full height of the character from ascender to descender, as computed byScaleForPixelHeight
. To use a point size as computed byScaleForMappingEmToPixels
, wrap the font size inSTBTruetype.STBTT_POINT_SIZE(int)
and pass the result, i.e.:..., 20 , ... // font max minus min y is 20 pixels tall ..., STBTT_POINT_SIZE(20), ... // 'M' is 20 pixels tall
first_unicode_char_in_range
- the first unicode code point in the rangechardata_for_range
- an array ofSTBTTPackedchar
structs- Returns:
- 1 on success, 0 on failure
-
stbtt_PackFontRanges
public static boolean stbtt_PackFontRanges(STBTTPackContext spc, java.nio.ByteBuffer fontdata, int font_index, STBTTPackRange.Buffer ranges)
Creates character bitmaps from multiple ranges of characters stored in ranges. This will usually create a better-packed bitmap than multiple calls toPackFontRange
. Note that you can call this multiple times within a singlePackBegin
/PackEnd
.- Parameters:
spc
- anSTBTTPackContext
structfontdata
- the font datafont_index
- the font index (use 0 if you don't know what that isranges
- an array ofSTBTTPackRange
structs- Returns:
- 1 on success, 0 on failure
-
stbtt_PackSetOversampling
public static void stbtt_PackSetOversampling(STBTTPackContext spc, int h_oversample, int v_oversample)
Oversampling a font increases the quality by allowing higher-quality subpixel positioning, and is especially valuable at smaller text sizes.This function sets the amount of oversampling for all following calls to
PackFontRange
orPackFontRangesGatherRects
for a given pack context. The default (no oversampling) is achieved byh_oversample=1, v_oversample=1
. The total number of pixels required ish_oversample*v_oversample
larger than the default; for example, 2x2 oversampling requires 4x the storage of 1x1. For best results, render oversampled textures with bilinear filtering. Look at the readme in stb/tests/oversample for information about oversampled fonts.To use with PackFontRangesGather etc., you must set it before calls to
PackFontRangesGatherRects
.- Parameters:
spc
- anSTBTTPackContext
structh_oversample
- the horizontal oversampling amountv_oversample
- the vertical oversampling amount
-
stbtt_GetPackedQuad
public static void stbtt_GetPackedQuad(STBTTPackedchar.Buffer chardata, int pw, int ph, int char_index, java.nio.FloatBuffer xpos, java.nio.FloatBuffer ypos, STBTTAlignedQuad q, boolean align_to_integer)
Computes quad to draw for a given char and advances the current position.The coordinate system used assumes y increases downwards. Characters will extend both above and below the current position; see discussion of "BASELINE" above.
- Parameters:
chardata
- an array ofSTBTTPackedchar
structspw
- the bitmap width, in pixelsph
- the bitmap height, in pixelschar_index
- the character index in thechardata
arrayxpos
- the current x position, in screen pixel spaceypos
- the current y position, in screen pixel spaceq
- anSTBTTAlignedQuad
struct in which to return the quad to drawalign_to_integer
- 1 to align the quad to integer coordinates
-
stbtt_PackFontRangesGatherRects
public static int stbtt_PackFontRangesGatherRects(STBTTPackContext spc, STBTTFontinfo info, STBTTPackRange.Buffer ranges, STBRPRect rects)
Calling these functions in sequence is roughly equivalent to callingPackFontRanges
. If you want more control over the packing of multiple fonts, or if you want to pack custom data into a font texture, take a look at the source ofPackFontRanges
and create a custom version using these functions, e.g. callPackFontRangesGatherRects
multiple times, building up a single array of rects, then callPackFontRangesPackRects
once, then callPackFontRangesRenderIntoRects
repeatedly. This may result in a better packing than callingPackFontRanges
multiple times (or it may not).- Parameters:
spc
- anSTBTTPackContext
structinfo
- anSTBTTFontinfo
structranges
- an array ofSTBTTPackRange
structsrects
- an array ofSTBRPRect
structs. It must be big enough to accommodate all characters in the given ranges.- Returns:
- the number of structs written in
rects
-
stbtt_PackFontRangesPackRects
public static void stbtt_PackFontRangesPackRects(STBTTPackContext spc, STBRPRect.Buffer rects)
- Parameters:
spc
- anSTBTTPackContext
structrects
- an array ofSTBRPRect
structs
-
stbtt_PackFontRangesRenderIntoRects
public static boolean stbtt_PackFontRangesRenderIntoRects(STBTTPackContext spc, STBTTFontinfo info, STBTTPackRange.Buffer ranges, STBRPRect rects)
- Parameters:
spc
- anSTBTTPackContext
structinfo
- anSTBTTFontinfo
structranges
- an array ofSTBTTPackRange
structsrects
- an array ofSTBRPRect
structs. It must be big enough to accommodate all characters in the given ranges.- Returns:
- 1 on success, 0 on failure
-
stbtt_GetFontOffsetForIndex
public static int stbtt_GetFontOffsetForIndex(java.nio.ByteBuffer data, int index)
Each .ttf/.ttc file may have more than one font. Each font has a sequential index number starting from 0. Call this function to get the font offset for a given index; it returns -1 if the index is out of range. A regular .ttf file will only define one font and it always be at offset 0, so it will return '0' for index 0, and -1 for all other indices. You can just skip this step if you know it's that kind of font.- Parameters:
data
- the font dataindex
- the font index
-
stbtt_InitFont
public static boolean stbtt_InitFont(STBTTFontinfo info, java.nio.ByteBuffer data, int offset)
Given an offset into the file that defines a font, this function builds the necessary cached info for the rest of the system. You must allocate theSTBTTFontinfo
yourself, and stbtt_InitFont will fill it out. You don't need to do anything special to free it, because the contents are pure value data with no additional data structures.- Parameters:
info
- anSTBTTFontinfo
structdata
- the font dataoffset
- the font data offset- Returns:
- 1 on success, 0 on failure
-
stbtt_InitFont
public static boolean stbtt_InitFont(STBTTFontinfo info, java.nio.ByteBuffer data)
Given an offset into the file that defines a font, this function builds the necessary cached info for the rest of the system. You must allocate theSTBTTFontinfo
yourself, and stbtt_InitFont will fill it out. You don't need to do anything special to free it, because the contents are pure value data with no additional data structures.- Parameters:
info
- anSTBTTFontinfo
structdata
- the font data- Returns:
- 1 on success, 0 on failure
-
stbtt_FindGlyphIndex
public static int stbtt_FindGlyphIndex(STBTTFontinfo info, int unicode_codepoint)
If you're going to perform multiple operations on the same character and you want a speed-up, call this function with the character you're going to process, then use glyph-based functions instead of the codepoint-based functions.- Parameters:
info
- anSTBTTFontinfo
structunicode_codepoint
- the unicode code point- Returns:
- the glyph index
-
stbtt_ScaleForPixelHeight
public static float stbtt_ScaleForPixelHeight(STBTTFontinfo info, float pixels)
Computes a scale factor to produce a font whose "height" ispixels
tall. Height is measured as the distance from the highest ascender to the lowest descender; in other words, it's equivalent to callingGetFontVMetrics
and computing:scale = pixels / (ascent - descent)
so if you prefer to measure height by the ascent only, use a similar calculation.
- Parameters:
info
- anSTBTTFontinfo
structpixels
- the font height, in pixels- Returns:
- the scale factor
-
stbtt_ScaleForMappingEmToPixels
public static float stbtt_ScaleForMappingEmToPixels(STBTTFontinfo info, float pixels)
Computes a scale factor to produce a font whose EM size is mapped topixels
tall. This is probably what traditional APIs compute, but I'm not positive.- Parameters:
info
- anSTBTTFontinfo
structpixels
- the font height, in pixels- Returns:
- the scale factor
-
stbtt_GetFontVMetrics
public static void stbtt_GetFontVMetrics(STBTTFontinfo info, java.nio.IntBuffer ascent, java.nio.IntBuffer descent, java.nio.IntBuffer lineGap)
Returns vertical metrics for the specified font. You should advance the vertical position by*ascent - *descent + *lineGap
The returned values are expressed in unscaled coordinates, so you must multiply by the scale factor for a given size.
- Parameters:
info
- anSTBTTFontinfo
structascent
- returns the coordinate above the baseline the font extendsdescent
- returns the coordinate below the baseline the font extends (i.e. it is typically negative)lineGap
- returns the spacing between one row's descent and the next row's ascent
-
stbtt_GetFontBoundingBox
public static void stbtt_GetFontBoundingBox(STBTTFontinfo info, java.nio.IntBuffer x0, java.nio.IntBuffer y0, java.nio.IntBuffer x1, java.nio.IntBuffer y1)
Returns the bounding box around all possible characters.- Parameters:
info
- anSTBTTFontinfo
structx0
- the left coordinatey0
- the bottom coordinatex1
- the right coordinatey1
- the top coordinate
-
stbtt_GetCodepointHMetrics
public static void stbtt_GetCodepointHMetrics(STBTTFontinfo info, int codepoint, java.nio.IntBuffer advanceWidth, java.nio.IntBuffer leftSideBearing)
Returns horizontal metrics for the specified codepoint.The returned values are expressed in unscaled coordinates.
- Parameters:
info
- anSTBTTFontinfo
structcodepoint
- the unicode codepointadvanceWidth
- the offset from the current horizontal position to the next horizontal positionleftSideBearing
- the offset from the current horizontal position to the left edge of the character
-
stbtt_GetCodepointKernAdvance
public static int stbtt_GetCodepointKernAdvance(STBTTFontinfo info, int ch1, int ch2)
Returns the additional amount to add to theadvance
value betweench1
andch2
.- Parameters:
info
- anSTBTTFontinfo
structch1
- the first unicode codepointch2
- the second unicode codepoint
-
stbtt_GetCodepointBox
public static boolean stbtt_GetCodepointBox(STBTTFontinfo info, int codepoint, java.nio.IntBuffer x0, java.nio.IntBuffer y0, java.nio.IntBuffer x1, java.nio.IntBuffer y1)
Gets the bounding box of the visible part of the glyph, in unscaled coordinates.- Parameters:
info
- anSTBTTFontinfo
structcodepoint
- the unicode codepointx0
- returns the left coordinatey0
- returns the bottom coordinatex1
- returns the right coordinatey1
- returns the top coordinate
-
stbtt_GetGlyphHMetrics
public static void stbtt_GetGlyphHMetrics(STBTTFontinfo info, int glyph_index, java.nio.IntBuffer advanceWidth, java.nio.IntBuffer leftSideBearing)
Glyph version ofGetCodepointHMetrics
, for greater efficiency.- Parameters:
info
- anSTBTTFontinfo
structglyph_index
- the glyph indexadvanceWidth
- the offset from the current horizontal position to the next horizontal positionleftSideBearing
- the offset from the current horizontal position to the left edge of the character
-
stbtt_GetGlyphKernAdvance
public static int stbtt_GetGlyphKernAdvance(STBTTFontinfo info, int glyph1, int glyph2)
Glyph version ofGetCodepointKernAdvance
, for greater efficiency.- Parameters:
info
- anSTBTTFontinfo
structglyph1
- the first glyph indexglyph2
- the second glyph index
-
stbtt_GetGlyphBox
public static boolean stbtt_GetGlyphBox(STBTTFontinfo info, int glyph_index, java.nio.IntBuffer x0, java.nio.IntBuffer y0, java.nio.IntBuffer x1, java.nio.IntBuffer y1)
Glyph version ofGetCodepointBox
, for greater efficiency.- Parameters:
info
- anSTBTTFontinfo
structglyph_index
- the glyph indexx0
- returns the left coordinatey0
- returns the bottom coordinatex1
- returns the right coordinatey1
- returns the top coordinate
-
stbtt_IsGlyphEmpty
public static boolean stbtt_IsGlyphEmpty(STBTTFontinfo info, int glyph_index)
Returns non-zero if nothing is drawn for this glyph.- Parameters:
info
- anSTBTTFontinfo
structglyph_index
- the glyph index
-
stbtt_GetCodepointShape
public static int stbtt_GetCodepointShape(STBTTFontinfo info, int unicode_codepoint, org.lwjgl.PointerBuffer vertices)
Returns number of vertices and fills*vertices
with the pointer to themThe shape is a series of countours. Each one starts with a
vmove
, then consists of a series of mixedvline
andvcurve
segments. Avline
draws a line from previous endpoint to itsx,y
; avcurve
draws a quadratic bezier from previous endpoint to itsx,y
, usingcx,cy
as the bezier control point.The
STBTTVertex
values are expressed in "unscaled" coordinates.- Parameters:
info
- anSTBTTFontinfo
structunicode_codepoint
- the unicode codepointvertices
- returns a pointer to an array ofSTBTTVertex
structs
-
stbtt_GetCodepointShape
public static STBTTVertex.Buffer stbtt_GetCodepointShape(STBTTFontinfo info, int unicode_codepoint)
Returns number of vertices and fills*vertices
with the pointer to themThe shape is a series of countours. Each one starts with a
vmove
, then consists of a series of mixedvline
andvcurve
segments. Avline
draws a line from previous endpoint to itsx,y
; avcurve
draws a quadratic bezier from previous endpoint to itsx,y
, usingcx,cy
as the bezier control point.The
STBTTVertex
values are expressed in "unscaled" coordinates.- Parameters:
info
- anSTBTTFontinfo
structunicode_codepoint
- the unicode codepoint
-
stbtt_GetGlyphShape
public static int stbtt_GetGlyphShape(STBTTFontinfo info, int glyph_index, org.lwjgl.PointerBuffer vertices)
Glyph version ofGetCodepointShape
, for greater efficiency.- Parameters:
info
- anSTBTTFontinfo
structglyph_index
- the unicode codepointvertices
- returns a pointer to an array ofSTBTTVertex
structs
-
stbtt_GetGlyphShape
public static STBTTVertex.Buffer stbtt_GetGlyphShape(STBTTFontinfo info, int glyph_index)
Glyph version ofGetCodepointShape
, for greater efficiency.- Parameters:
info
- anSTBTTFontinfo
structglyph_index
- the unicode codepoint
-
stbtt_FreeShape
public static void stbtt_FreeShape(STBTTFontinfo info, STBTTVertex.Buffer vertices)
Frees the data allocated byGetCodepointShape
andGetGlyphShape
.- Parameters:
info
- anSTBTTFontinfo
structvertices
- the array ofSTBTTVertex
structs to free
-
stbtt_FreeBitmap
public static void stbtt_FreeBitmap(java.nio.ByteBuffer bitmap, long userdata)
Frees a bitmap allocated byGetCodepointBitmap
,GetCodepointBitmapSubpixel
,GetGlyphBitmap
orGetGlyphBitmapSubpixel
.- Parameters:
bitmap
- the bitmap to freeuserdata
- a pointer to user data
-
stbtt_GetCodepointBitmap
public static java.nio.ByteBuffer stbtt_GetCodepointBitmap(STBTTFontinfo info, float scale_x, float scale_y, int codepoint, java.nio.IntBuffer width, java.nio.IntBuffer height, java.nio.IntBuffer xoff, java.nio.IntBuffer yoff)
Allocates a large-enough single-channel 8bpp bitmap and renders the specified character/glyph at the specified scale into it, with antialiasing.- Parameters:
info
- anSTBTTFontinfo
structscale_x
- the horizontal scalescale_y
- the vertical scalecodepoint
- the unicode codepoint to renderwidth
- returns the bitmap widthheight
- returns the bitmap heightxoff
- returns the horizontal offset in pixel space from the glyph origin to the left of the bitmapyoff
- returns the vertical offset in pixel space from the glyph origin to the top of the bitmap
-
stbtt_GetCodepointBitmapSubpixel
public static java.nio.ByteBuffer stbtt_GetCodepointBitmapSubpixel(STBTTFontinfo info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, java.nio.IntBuffer width, java.nio.IntBuffer height, java.nio.IntBuffer xoff, java.nio.IntBuffer yoff)
Same asGetCodepointBitmap
, but you can specify a subpixel shift for the character.- Parameters:
info
- anSTBTTFontinfo
structscale_x
- the horizontal scalescale_y
- the vertical scaleshift_x
- the horizontal subpixel shiftshift_y
- the vertical subpixel shiftcodepoint
- the unicode codepoint to renderwidth
- returns the bitmap widthheight
- returns the bitmap heightxoff
- returns the horizontal offset in pixel space from the glyph origin to the left of the bitmapyoff
- returns the vertical offset in pixel space from the glyph origin to the top of the bitmap
-
stbtt_MakeCodepointBitmap
public static void stbtt_MakeCodepointBitmap(STBTTFontinfo info, java.nio.ByteBuffer output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint)
Same asGetCodepointBitmap
, but you pass in storage for the bitmap in the form ofoutput
, with row spacing ofout_stride
bytes. The bitmap is clipped toout_w/out_h
bytes. CallGetCodepointBitmapBox
to get the width and height and positioning info for it first.- Parameters:
info
- anSTBTTFontinfo
structoutput
- the bitmap storageout_w
- the bitmap widthout_h
- the bitmap heightout_stride
- the row stride, in bytesscale_x
- the horizontal scalescale_y
- the vertical scalecodepoint
- the unicode codepoint to render
-
stbtt_MakeCodepointBitmapSubpixel
public static void stbtt_MakeCodepointBitmapSubpixel(STBTTFontinfo info, java.nio.ByteBuffer output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint)
Same asMakeCodepointBitmap
, but you can specify a subpixel shift for the character.- Parameters:
info
- anSTBTTFontinfo
structoutput
- the bitmap storageout_w
- the bitmap widthout_h
- the bitmap heightout_stride
- the row stride, in bytesscale_x
- the horizontal scalescale_y
- the vertical scaleshift_x
- the horizontal subpixel shiftshift_y
- the vertical subpixel shiftcodepoint
- the unicode codepoint to render
-
stbtt_GetCodepointBitmapBox
public static void stbtt_GetCodepointBitmapBox(STBTTFontinfo font, int codepoint, float scale_x, float scale_y, java.nio.IntBuffer ix0, java.nio.IntBuffer iy0, java.nio.IntBuffer ix1, java.nio.IntBuffer iy1)
Get the bbox of the bitmap centered around the glyph origin; so the bitmap width isix1-ix0
, height isiy1-iy0
, and location to place the bitmap top left is(leftSideBearing*scale,iy0)
.Note that the bitmap uses y-increases-down, but the shape uses y-increases-up, so
CodepointBitmapBox
andCodepointBox
are inverted.- Parameters:
font
- anSTBTTFontinfo
structcodepoint
- the unicode codepointscale_x
- the horizontal scalescale_y
- the vertical scaleix0
- returns the left coordinateiy0
- returns the bottom coordinateix1
- returns the right coordinateiy1
- returns the top coordinate
-
stbtt_GetCodepointBitmapBoxSubpixel
public static void stbtt_GetCodepointBitmapBoxSubpixel(STBTTFontinfo font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, java.nio.IntBuffer ix0, java.nio.IntBuffer iy0, java.nio.IntBuffer ix1, java.nio.IntBuffer iy1)
Same asGetCodepointBitmapBox
, but you can specify a subpixel shift for the character.- Parameters:
font
- anSTBTTFontinfo
structcodepoint
- the unicode codepointscale_x
- the horizontal scalescale_y
- the vertical scaleshift_x
- the horizontal subpixel shiftshift_y
- the vertical subpixel shiftix0
- returns the left coordinateiy0
- returns the bottom coordinateix1
- returns the right coordinateiy1
- returns the top coordinate
-
stbtt_GetGlyphBitmap
public static java.nio.ByteBuffer stbtt_GetGlyphBitmap(STBTTFontinfo info, float scale_x, float scale_y, int glyph, java.nio.IntBuffer width, java.nio.IntBuffer height, java.nio.IntBuffer xoff, java.nio.IntBuffer yoff)
Allocates a large-enough single-channel 8bpp bitmap and renders the specified character/glyph at the specified scale into it, with antialiasing.- Parameters:
info
- anSTBTTFontinfo
structscale_x
- the horizontal scalescale_y
- the vertical scaleglyph
- the glyph index to renderwidth
- returns the bitmap widthheight
- returns the bitmap heightxoff
- returns the horizontal offset in pixel space from the glyph origin to the left of the bitmapyoff
- returns the vertical offset in pixel space from the glyph origin to the top of the bitmap
-
stbtt_GetGlyphBitmapSubpixel
public static java.nio.ByteBuffer stbtt_GetGlyphBitmapSubpixel(STBTTFontinfo info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, java.nio.IntBuffer width, java.nio.IntBuffer height, java.nio.IntBuffer xoff, java.nio.IntBuffer yoff)
Same asGetGlyphBitmap
, but you can specify a subpixel shift for the character.- Parameters:
info
- anSTBTTFontinfo
structscale_x
- the horizontal scalescale_y
- the vertical scaleshift_x
- the horizontal subpixel shiftshift_y
- the vertical subpixel shiftglyph
- the glyph index to renderwidth
- returns the bitmap widthheight
- returns the bitmap heightxoff
- returns the horizontal offset in pixel space from the glyph origin to the left of the bitmapyoff
- returns the vertical offset in pixel space from the glyph origin to the top of the bitmap
-
stbtt_MakeGlyphBitmap
public static void stbtt_MakeGlyphBitmap(STBTTFontinfo info, java.nio.ByteBuffer output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph)
Same asGetGlyphBitmap
, but you pass in storage for the bitmap in the form ofoutput
, with row spacing ofout_stride
bytes. The bitmap is clipped toout_w/out_h
bytes. CallGetGlyphBitmapBox
to get the width and height and positioning info for it first.- Parameters:
info
- anSTBTTFontinfo
structoutput
- the bitmap storageout_w
- the bitmap widthout_h
- the bitmap heightout_stride
- the row stride, in bytesscale_x
- the horizontal scalescale_y
- the vertical scaleglyph
- the glyph index to render
-
stbtt_MakeGlyphBitmapSubpixel
public static void stbtt_MakeGlyphBitmapSubpixel(STBTTFontinfo info, java.nio.ByteBuffer output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph)
Same asMakeGlyphBitmap
, but you can specify a subpixel shift for the character.- Parameters:
info
- anSTBTTFontinfo
structoutput
- the bitmap storageout_w
- the bitmap widthout_h
- the bitmap heightout_stride
- the row stride, in bytesscale_x
- the horizontal scalescale_y
- the vertical scaleshift_x
- the horizontal subpixel shiftshift_y
- the vertical subpixel shiftglyph
- the glyph index to render
-
stbtt_GetGlyphBitmapBox
public static void stbtt_GetGlyphBitmapBox(STBTTFontinfo font, int glyph, float scale_x, float scale_y, java.nio.IntBuffer ix0, java.nio.IntBuffer iy0, java.nio.IntBuffer ix1, java.nio.IntBuffer iy1)
Get the bbox of the bitmap centered around the glyph origin; so the bitmap width isix1-ix0
, height isiy1-iy0
, and location to place the bitmap top left is(leftSideBearing*scale,iy0)
.Note that the bitmap uses y-increases-down, but the shape uses y-increases-up, so
GlyphBitmapBox
andGlyphBox
are inverted.- Parameters:
font
- anSTBTTFontinfo
structglyph
- the glyph indexscale_x
- the horizontal scalescale_y
- the vertical scaleix0
- returns the left coordinateiy0
- returns the bottom coordinateix1
- returns the right coordinateiy1
- returns the top coordinate
-
stbtt_GetGlyphBitmapBoxSubpixel
public static void stbtt_GetGlyphBitmapBoxSubpixel(STBTTFontinfo font, int glyph, float scale_x, float scale_y, float shift_x, float shift_y, java.nio.IntBuffer ix0, java.nio.IntBuffer iy0, java.nio.IntBuffer ix1, java.nio.IntBuffer iy1)
Same asGetGlyphBitmapBox
, but you can specify a subpixel shift for the character.- Parameters:
font
- anSTBTTFontinfo
structglyph
- the glyph indexscale_x
- the horizontal scalescale_y
- the vertical scaleshift_x
- the horizontal subpixel shiftshift_y
- the vertical subpixel shiftix0
- returns the left coordinateiy0
- returns the bottom coordinateix1
- returns the right coordinateiy1
- returns the top coordinate
-
stbtt_FindMatchingFont
public static int stbtt_FindMatchingFont(java.nio.ByteBuffer fontdata, java.nio.ByteBuffer name, int flags) public static int stbtt_FindMatchingFont(java.nio.ByteBuffer fontdata, java.lang.CharSequence name, int flags)
Returns the offset (not index) of the font that matches, or -1 if none.If you use STBTT_MACSTYLE_DONTCARE, use a font name like "Arial Bold". If you use any other flag, use a font name like "Arial"; this checks the
macStyle
header field; I don't know if fonts set this consistently.- Parameters:
fontdata
- the font dataname
- the font nameflags
- the style flags. One of:MACSTYLE_DONTCARE
MACSTYLE_BOLD
MACSTYLE_ITALIC
MACSTYLE_UNDERSCORE
MACSTYLE_NONE
-
stbtt_CompareUTF8toUTF16_bigendian
public static boolean stbtt_CompareUTF8toUTF16_bigendian(java.nio.ByteBuffer s1, java.nio.ByteBuffer s2)
Returns 1/0 whether the first string interpreted as utf8 is identical to the second string interpreted as big-endian utf16... useful for strings returned fromGetFontNameString
.- Parameters:
s1
- the first strings2
- the second string
-
stbtt_GetFontNameString
public static java.nio.ByteBuffer stbtt_GetFontNameString(STBTTFontinfo font, int platformID, int encodingID, int languageID, int nameID)
Returns the string (which may be big-endian double byte, e.g. for unicode) and puts the length in bytes in*length
.See the truetype spec:
- Parameters:
font
- anSTBTTFontinfo
structplatformID
- the platform ID. One of:PLATFORM_ID_UNICODE
PLATFORM_ID_MAC
PLATFORM_ID_ISO
PLATFORM_ID_MICROSOFT
encodingID
- the encoding ID. One of:languageID
- the language ID. One of:nameID
- the name ID
-
stbtt_GetBakedQuad
public static void stbtt_GetBakedQuad(STBTTBakedChar.Buffer chardata, int pw, int ph, int char_index, float[] xpos, float[] ypos, STBTTAlignedQuad q, boolean opengl_fillrule)
Array version of:GetBakedQuad
-
stbtt_GetPackedQuad
public static void stbtt_GetPackedQuad(STBTTPackedchar.Buffer chardata, int pw, int ph, int char_index, float[] xpos, float[] ypos, STBTTAlignedQuad q, boolean align_to_integer)
Array version of:GetPackedQuad
-
stbtt_GetFontVMetrics
public static void stbtt_GetFontVMetrics(STBTTFontinfo info, int[] ascent, int[] descent, int[] lineGap)
Array version of:GetFontVMetrics
-
stbtt_GetFontBoundingBox
public static void stbtt_GetFontBoundingBox(STBTTFontinfo info, int[] x0, int[] y0, int[] x1, int[] y1)
Array version of:GetFontBoundingBox
-
stbtt_GetCodepointHMetrics
public static void stbtt_GetCodepointHMetrics(STBTTFontinfo info, int codepoint, int[] advanceWidth, int[] leftSideBearing)
Array version of:GetCodepointHMetrics
-
stbtt_GetCodepointBox
public static boolean stbtt_GetCodepointBox(STBTTFontinfo info, int codepoint, int[] x0, int[] y0, int[] x1, int[] y1)
Array version of:GetCodepointBox
-
stbtt_GetGlyphHMetrics
public static void stbtt_GetGlyphHMetrics(STBTTFontinfo info, int glyph_index, int[] advanceWidth, int[] leftSideBearing)
Array version of:GetGlyphHMetrics
-
stbtt_GetGlyphBox
public static boolean stbtt_GetGlyphBox(STBTTFontinfo info, int glyph_index, int[] x0, int[] y0, int[] x1, int[] y1)
Array version of:GetGlyphBox
-
stbtt_GetCodepointBitmap
public static java.nio.ByteBuffer stbtt_GetCodepointBitmap(STBTTFontinfo info, float scale_x, float scale_y, int codepoint, int[] width, int[] height, int[] xoff, int[] yoff)
Array version of:GetCodepointBitmap
-
stbtt_GetCodepointBitmapSubpixel
public static java.nio.ByteBuffer stbtt_GetCodepointBitmapSubpixel(STBTTFontinfo info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int[] width, int[] height, int[] xoff, int[] yoff)
Array version of:GetCodepointBitmapSubpixel
-
stbtt_GetCodepointBitmapBox
public static void stbtt_GetCodepointBitmapBox(STBTTFontinfo font, int codepoint, float scale_x, float scale_y, int[] ix0, int[] iy0, int[] ix1, int[] iy1)
Array version of:GetCodepointBitmapBox
-
stbtt_GetCodepointBitmapBoxSubpixel
public static void stbtt_GetCodepointBitmapBoxSubpixel(STBTTFontinfo font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int[] ix0, int[] iy0, int[] ix1, int[] iy1)
Array version of:GetCodepointBitmapBoxSubpixel
-
stbtt_GetGlyphBitmap
public static java.nio.ByteBuffer stbtt_GetGlyphBitmap(STBTTFontinfo info, float scale_x, float scale_y, int glyph, int[] width, int[] height, int[] xoff, int[] yoff)
Array version of:GetGlyphBitmap
-
stbtt_GetGlyphBitmapSubpixel
public static java.nio.ByteBuffer stbtt_GetGlyphBitmapSubpixel(STBTTFontinfo info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int[] width, int[] height, int[] xoff, int[] yoff)
Array version of:GetGlyphBitmapSubpixel
-
stbtt_GetGlyphBitmapBox
public static void stbtt_GetGlyphBitmapBox(STBTTFontinfo font, int glyph, float scale_x, float scale_y, int[] ix0, int[] iy0, int[] ix1, int[] iy1)
Array version of:GetGlyphBitmapBox
-
stbtt_GetGlyphBitmapBoxSubpixel
public static void stbtt_GetGlyphBitmapBoxSubpixel(STBTTFontinfo font, int glyph, float scale_x, float scale_y, float shift_x, float shift_y, int[] ix0, int[] iy0, int[] ix1, int[] iy1)
Array version of:GetGlyphBitmapBoxSubpixel
-
-