Top Description Fields Constructors Methods
org.lwjgl.stb

public Class STBTruetype

extends Object
Class Inheritance
Imports
javax.annotation.*, java.nio.*, org.lwjgl.*, org.lwjgl.system.*

Native bindings to stb_truetype.h from the stb library.

This library processes TrueType files:

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.

DETAILED USAGE

Scale:

Select how high you want the font to be, in points or pixels. Call #()ScaleForPixelHeight or ScaleForMappingEmToPixels to compute a scale factor SF that will be used by all other functions.

Baseline:

You need to select a y-coordinate that is the baseline of where your text will appear. Call GetFontBoundingBox to get the baseline-relative bounding box for all characters. SF*-y0 will be the distance in pixels that the worst-case character could extend above the baseline, so if you want the top edge of characters to appear at the top of the screen where y=0, then you would set the baseline to SF*-y0.

Current point:

Set the current point where the first character will appear. The first character could extend left of the current point; this is font dependent. You can either choose a current point that is the leftmost point and hope, or add some padding, or check the bounding box or left-side-bearing of the first character to be displayed and set the current point based on that.

Displaying a character:

Compute the bounding box of the character. It will contain signed values relative to <current_point, baseline>. I.e. if it returns x0,y0,x1,y1, then the character should be displayed in the rectangle from <current_point+SF*x0, baseline+SF*y0> to <current_point+SF*x1,baseline+SF*y1).

Advancing for the next character:

Call GetGlyphHMetrics, and compute current_point += SF * advance.

ADVANCED USAGE

Quality:

Performance:

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:

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
STBTT_PLATFORM_ID_ISO

Platform IDs.

public static final int
STBTT_PLATFORM_ID_MAC

Platform IDs.

public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final byte
STBTT_vcubic

Vertex type.

public static final byte
STBTT_vcurve

Vertex type.

public static final byte
STBTT_vline

Vertex type.

public static final byte
STBTT_vmove

Vertex type.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public static native int
nstbtt_BakeFontBitmap(long data, int offset, float pixel_height, long pixels, int pw, int ph, int first_char, int
the number of characters to bake, starting at first_char
num_chars
,
long chardata)

Unsafe version of: BakeFontBitmap

public static native int
nstbtt_CompareUTF8toUTF16_bigendian(long s1, int
the length of the first string, in bytes
len1
,
long s2, int
the length of the second string, in bytes
len2
)

Unsafe version of: CompareUTF8toUTF16_bigendian

public static native int
nstbtt_FindGlyphIndex(long info, int unicode_codepoint)

Unsafe version of: FindGlyphIndex

public static native int
nstbtt_FindMatchingFont(long fontdata, long name, int flags)

Unsafe version of: FindMatchingFont

public static native long
nstbtt_FindSVGDoc(long info, int gl)

public static native void
nstbtt_FreeBitmap(long bitmap, long userdata)

Unsafe version of: FreeBitmap

public static native void
nstbtt_FreeSDF(long bitmap, long userdata)

Unsafe version of: FreeSDF

public static native void
nstbtt_FreeShape(long info, long vertices)

Unsafe version of: FreeShape

public static native void
nstbtt_GetBakedQuad(long chardata, int pw, int ph, int char_index, long xpos, long ypos, long q, int opengl_fillrule)

Unsafe version of: GetBakedQuad

public static native void
nstbtt_GetBakedQuad(long chardata, int pw, int ph, int char_index, float[] xpos, float[] ypos, long q, int opengl_fillrule)

Array version of: nstbtt_GetBakedQuad

public static native long
nstbtt_GetCodepointBitmap(long info, float scale_x, float scale_y, int codepoint, long width, long height, long xoff, long yoff)

Unsafe version of: GetCodepointBitmap

public static native long
nstbtt_GetCodepointBitmap(long info, float scale_x, float scale_y, int codepoint, int[] width, int[] height, int[] xoff, int[] yoff)

Array version of: nstbtt_GetCodepointBitmap

public static native void
nstbtt_GetCodepointBitmapBox(long font, int codepoint, float scale_x, float scale_y, long ix0, long iy0, long ix1, long iy1)

Unsafe version of: GetCodepointBitmapBox

public static native void
nstbtt_GetCodepointBitmapBox(long font, int codepoint, float scale_x, float scale_y, int[] ix0, int[] iy0, int[] ix1, int[] iy1)

Array version of: nstbtt_GetCodepointBitmapBox

public static native void
nstbtt_GetCodepointBitmapBoxSubpixel(long font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, long ix0, long iy0, long ix1, long iy1)

Unsafe version of: GetCodepointBitmapBoxSubpixel

public static native void
nstbtt_GetCodepointBitmapBoxSubpixel(long 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: nstbtt_GetCodepointBitmapBoxSubpixel

public static native long
nstbtt_GetCodepointBitmapSubpixel(long info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, long width, long height, long xoff, long yoff)

Unsafe version of: GetCodepointBitmapSubpixel

public static native long
nstbtt_GetCodepointBitmapSubpixel(long 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: nstbtt_GetCodepointBitmapSubpixel

public static native int
nstbtt_GetCodepointBox(long info, int codepoint, long x0, long y0, long x1, long y1)

Unsafe version of: GetCodepointBox

public static native int
nstbtt_GetCodepointBox(long info, int codepoint, int[] x0, int[] y0, int[] x1, int[] y1)

Array version of: nstbtt_GetCodepointBox

public static native void
nstbtt_GetCodepointHMetrics(long info, int codepoint, long advanceWidth, long leftSideBearing)

Unsafe version of: GetCodepointHMetrics

public static native void
nstbtt_GetCodepointHMetrics(long info, int codepoint, int[] advanceWidth, int[] leftSideBearing)

Array version of: nstbtt_GetCodepointHMetrics

public static native int
nstbtt_GetCodepointKernAdvance(long info, int ch1, int ch2)

Unsafe version of: GetCodepointKernAdvance

public static native long
nstbtt_GetCodepointSDF(long font, float scale, int codepoint, int padding, byte onedge_value, float pixel_dist_scale, long width, long height, long xoff, long yoff)

Unsafe version of: GetCodepointSDF

public static native long
nstbtt_GetCodepointSDF(long font, float scale, int codepoint, int padding, byte onedge_value, float pixel_dist_scale, int[] width, int[] height, int[] xoff, int[] yoff)

Array version of: nstbtt_GetCodepointSDF

public static native int
nstbtt_GetCodepointShape(long info, int unicode_codepoint, long vertices)

Unsafe version of: GetCodepointShape

public static native int
nstbtt_GetCodepointSVG(long info, int unicode_codepoint, long svg)

Unsafe version of: GetCodepointSVG

public static native void
nstbtt_GetFontBoundingBox(long info, long x0, long y0, long x1, long y1)

Unsafe version of: GetFontBoundingBox

public static native void
nstbtt_GetFontBoundingBox(long info, int[] x0, int[] y0, int[] x1, int[] y1)

Array version of: nstbtt_GetFontBoundingBox

public static native long
nstbtt_GetFontNameString(long font, long
returns the string length, in bytes
length
,
int platformID, int encodingID, int languageID, int nameID)

Unsafe version of: GetFontNameString

public static native int
nstbtt_GetFontOffsetForIndex(long data, int index)

Unsafe version of: GetFontOffsetForIndex

public static native void
nstbtt_GetFontVMetrics(long info, long ascent, long descent, long lineGap)

Unsafe version of: GetFontVMetrics

public static native void
nstbtt_GetFontVMetrics(long info, int[] ascent, int[] descent, int[] lineGap)

Array version of: nstbtt_GetFontVMetrics

public static native int
nstbtt_GetFontVMetricsOS2(long info, long typoAscent, long typoDescent, long typoLineGap)

Unsafe version of: GetFontVMetricsOS2

public static native int
nstbtt_GetFontVMetricsOS2(long info, int[] typoAscent, int[] typoDescent, int[] typoLineGap)

Array version of: nstbtt_GetFontVMetricsOS2

public static native long
nstbtt_GetGlyphBitmap(long info, float scale_x, float scale_y, int glyph, long width, long height, long xoff, long yoff)

Unsafe version of: GetGlyphBitmap

public static native long
nstbtt_GetGlyphBitmap(long info, float scale_x, float scale_y, int glyph, int[] width, int[] height, int[] xoff, int[] yoff)

Array version of: nstbtt_GetGlyphBitmap

public static native void
nstbtt_GetGlyphBitmapBox(long font, int glyph, float scale_x, float scale_y, long ix0, long iy0, long ix1, long iy1)

Unsafe version of: GetGlyphBitmapBox

public static native void
nstbtt_GetGlyphBitmapBox(long font, int glyph, float scale_x, float scale_y, int[] ix0, int[] iy0, int[] ix1, int[] iy1)

Array version of: nstbtt_GetGlyphBitmapBox

public static native void
nstbtt_GetGlyphBitmapBoxSubpixel(long font, int glyph, float scale_x, float scale_y, float shift_x, float shift_y, long ix0, long iy0, long ix1, long iy1)

Unsafe version of: GetGlyphBitmapBoxSubpixel

public static native void
nstbtt_GetGlyphBitmapBoxSubpixel(long 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: nstbtt_GetGlyphBitmapBoxSubpixel

public static native long
nstbtt_GetGlyphBitmapSubpixel(long info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, long width, long height, long xoff, long yoff)

Unsafe version of: GetGlyphBitmapSubpixel

public static native long
nstbtt_GetGlyphBitmapSubpixel(long 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: nstbtt_GetGlyphBitmapSubpixel

public static native int
nstbtt_GetGlyphBox(long info, int glyph_index, long x0, long y0, long x1, long y1)

Unsafe version of: GetGlyphBox

public static native int
nstbtt_GetGlyphBox(long info, int glyph_index, int[] x0, int[] y0, int[] x1, int[] y1)

Array version of: nstbtt_GetGlyphBox

public static native void
nstbtt_GetGlyphHMetrics(long info, int glyph_index, long advanceWidth, long leftSideBearing)

Unsafe version of: GetGlyphHMetrics

public static native void
nstbtt_GetGlyphHMetrics(long info, int glyph_index, int[] advanceWidth, int[] leftSideBearing)

Array version of: nstbtt_GetGlyphHMetrics

public static native int
nstbtt_GetGlyphKernAdvance(long info, int glyph1, int glyph2)

Unsafe version of: GetGlyphKernAdvance

public static native long
nstbtt_GetGlyphSDF(long font, float scale, int glyph, int padding, byte onedge_value, float pixel_dist_scale, long width, long height, long xoff, long yoff)

Unsafe version of: GetGlyphSDF

public static native long
nstbtt_GetGlyphSDF(long font, float scale, int glyph, int padding, byte onedge_value, float pixel_dist_scale, int[] width, int[] height, int[] xoff, int[] yoff)

Array version of: nstbtt_GetGlyphSDF

public static native int
nstbtt_GetGlyphShape(long info, int glyph_index, long vertices)

Unsafe version of: GetGlyphShape

public static native int
nstbtt_GetGlyphSVG(long info, int gl, long svg)

Unsafe version of: GetGlyphSVG

public static native int
nstbtt_GetKerningTable(long info, long table, int table_length)

Unsafe version of: GetKerningTable

public static native int
public static native int
nstbtt_GetNumberOfFonts(long data)

Unsafe version of: GetNumberOfFonts

public static native void
nstbtt_GetPackedQuad(long chardata, int pw, int ph, int char_index, long xpos, long ypos, long q, int align_to_integer)

Unsafe version of: GetPackedQuad

public static native void
nstbtt_GetPackedQuad(long chardata, int pw, int ph, int char_index, float[] xpos, float[] ypos, long q, int align_to_integer)

Array version of: nstbtt_GetPackedQuad

public static native void
nstbtt_GetScaledFontVMetrics(long fontdata, int index, float size, long ascent, long descent, long lineGap)

Unsafe version of: GetScaledFontVMetrics

public static native void
nstbtt_GetScaledFontVMetrics(long fontdata, int index, float size, float[] ascent, float[] descent, float[] lineGap)

Array version of: nstbtt_GetScaledFontVMetrics

public static native int
nstbtt_InitFont(long info, long data, int offset)

Unsafe version of: InitFont

public static native int
nstbtt_IsGlyphEmpty(long info, int glyph_index)

Unsafe version of: IsGlyphEmpty

public static native void
nstbtt_MakeCodepointBitmap(long info, long output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint)

Unsafe version of: MakeCodepointBitmap

public static native void
nstbtt_MakeCodepointBitmapSubpixel(long info, long output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint)

Unsafe version of: MakeCodepointBitmapSubpixel

public static native void
nstbtt_MakeCodepointBitmapSubpixelPrefilter(long info, long output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int oversample_x, int oversample_y, long sub_x, long sub_y, int codepoint)

Unsafe version of: MakeCodepointBitmapSubpixelPrefilter

public static native void
nstbtt_MakeCodepointBitmapSubpixelPrefilter(long info, long output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int oversample_x, int oversample_y, float[] sub_x, float[] sub_y, int codepoint)

Array version of: nstbtt_MakeCodepointBitmapSubpixelPrefilter

public static native void
nstbtt_MakeGlyphBitmap(long info, long output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph)

Unsafe version of: MakeGlyphBitmap

public static native void
nstbtt_MakeGlyphBitmapSubpixel(long info, long output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph)

Unsafe version of: MakeGlyphBitmapSubpixel

public static native void
nstbtt_MakeGlyphBitmapSubpixelPrefilter(long info, long output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int oversample_x, int oversample_y, long sub_x, long sub_y, int glyph)

Unsafe version of: MakeGlyphBitmapSubpixelPrefilter

public static native void
nstbtt_MakeGlyphBitmapSubpixelPrefilter(long info, long output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int oversample_x, int oversample_y, float[] sub_x, float[] sub_y, int glyph)

Array version of: nstbtt_MakeGlyphBitmapSubpixelPrefilter

public static native int
nstbtt_PackBegin(long spc, long pixels, int width, int height, int stride_in_bytes, int padding, long alloc_context)

Unsafe version of: PackBegin

public static native void
nstbtt_PackEnd(long spc)

Unsafe version of: PackEnd

public static native int
nstbtt_PackFontRange(long spc, long fontdata, int font_index, float font_size, int first_unicode_char_in_range, int
the number of unicode code points in the range
num_chars_in_range
,
long chardata_for_range)

Unsafe version of: PackFontRange

public static native int
nstbtt_PackFontRanges(long spc, long fontdata, int font_index, long ranges, int
the number of STBTTPackRange structs in ranges
num_ranges
)

Unsafe version of: PackFontRanges

public static native int
nstbtt_PackFontRangesGatherRects(long spc, long info, long ranges, int
the number of STBTTPackRange structs in ranges
num_ranges
,
long rects)

Unsafe version of: PackFontRangesGatherRects

public static native void
nstbtt_PackFontRangesPackRects(long spc, long rects, int
the number of structs in rects
num_rects
)

Unsafe version of: PackFontRangesPackRects

public static native int
nstbtt_PackFontRangesRenderIntoRects(long spc, long info, long ranges, int
the number of STBTTPackRange structs in ranges
num_ranges
,
long rects)

Unsafe version of: PackFontRangesRenderIntoRects

public static native void
nstbtt_PackSetOversampling(long spc, int h_oversample, int v_oversample)

Unsafe version of: PackSetOversampling

public static native void
public static native void
nstbtt_Rasterize(long result, float flatness_in_pixels, long vertices, int
number of vertices in above array
num_verts
,
float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, long alloc_context)

Unsafe version of: Rasterize

public static native float
nstbtt_ScaleForMappingEmToPixels(long info, float pixels)

Unsafe version of: ScaleForMappingEmToPixels

public static native float
nstbtt_ScaleForPixelHeight(long info, float pixels)

Unsafe version of: ScaleForPixelHeight

public static int

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_BakeFontBitmap
(ByteBuffer
the font data
data
,
float
the font height, in pixels
pixel_height
,
ByteBuffer
a buffer in which to write the font bitmap
pixels
,
int
the bitmap width, in pixels
pw
,
int
the bitmap height, in pixels
ph
,
int
the first character to bake
first_char
,
STBTTBakedChar.Buffer
an array of STBTTBakedChar structs, it's num_chars long
chardata
)

Bakes a font to a bitmap for use as texture.

public static boolean
stbtt_CompareUTF8toUTF16_bigendian(ByteBuffer
the first string
s1
,
ByteBuffer
the second string
s2
)

Returns 1/0 whether the first string interpreted as utf8 is identical to the second string interpreted as big-endian utf16...

public static int

Returns:

the glyph index or 0 if the character codepoint is not defined in the font
stbtt_FindGlyphIndex
(STBTTFontinfo
an STBTTFontinfo struct
info
,
int
the unicode code point
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.

public static int
stbtt_FindMatchingFont(ByteBuffer
the font data
fontdata
,
ByteBuffer
the font name
name
,
int flags)

Returns the offset (not index) of the font that matches, or -1 if none.

public static int
stbtt_FindMatchingFont(ByteBuffer
the font data
fontdata
,
CharSequence
the font name
name
,
int flags)

Returns the offset (not index) of the font that matches, or -1 if none.

public static long
public static void
stbtt_FreeBitmap(ByteBuffer
the bitmap to free
bitmap
,
long
a pointer to an allocation context
userdata
)

Frees a bitmap allocated by GetCodepointBitmap, GetCodepointBitmapSubpixel, GetGlyphBitmap or GetGlyphBitmapSubpixel.

public static void
public static void
stbtt_FreeSDF(ByteBuffer
the SDF bitmap to free
bitmap
,
long
a pointer to an allocation context
userdata
)

Frees an SDF bitmap.

public static void
stbtt_FreeSDF(ByteBuffer
the SDF bitmap to free
bitmap
)

Frees an SDF bitmap.

public static void
stbtt_FreeShape(STBTTFontinfo
an STBTTFontinfo struct
info
,
STBTTVertex.Buffer
the array of STBTTVertex structs to free
vertices
)

Frees the data allocated by GetCodepointShape and GetGlyphShape.

public static void
stbtt_GetBakedQuad(STBTTBakedChar.Buffer
an array of STBTTBakedChar structs
chardata
,
int
the bitmap width, in pixels
pw
,
int
the bitmap height, in pixels
ph
,
int
the character index in the chardata array
char_index
,
FloatBuffer
the current x position, in screen pixel space
xpos
,
FloatBuffer
the current y position, in screen pixel space
ypos
,
STBTTAlignedQuad
an STBTTAlignedQuad struct in which to return the quad to draw
q
,
boolean
1 if opengl fill rule; 0 if DX9 or earlier
opengl_fillrule
)

Computes quad to draw for a given char and advances the current position.

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

public static ByteBuffer
stbtt_GetCodepointBitmap(STBTTFontinfo
an STBTTFontinfo struct
info
,
float
the horizontal scale
scale_x
,
float
the vertical scale
scale_y
,
int
the unicode codepoint to render
codepoint
,
IntBuffer
returns the bitmap width
width
,
IntBuffer
returns the bitmap height
height
,
IntBuffer
returns the horizontal offset in pixel space from the glyph origin to the left of the bitmap
xoff
,
IntBuffer
returns the vertical offset in pixel space from the glyph origin to the top of the bitmap
yoff
)

Allocates a large-enough single-channel 8bpp bitmap and renders the specified character/glyph at the specified scale into it, with antialiasing.

public static 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

public static void
stbtt_GetCodepointBitmapBox(STBTTFontinfo
an STBTTFontinfo struct
font
,
int
the unicode codepoint
codepoint
,
float
the horizontal scale
scale_x
,
float
the vertical scale
scale_y
,
IntBuffer
returns the left coordinate
ix0
,
IntBuffer
returns the bottom coordinate
iy0
,
IntBuffer
returns the right coordinate
ix1
,
IntBuffer
returns the top coordinate
iy1
)

Get the bbox of the bitmap centered around the glyph origin; so the bitmap width is ix1-ix0, height is iy1-iy0, and location to place the bitmap top left is (leftSideBearing*scale,iy0).

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

public static void
stbtt_GetCodepointBitmapBoxSubpixel(STBTTFontinfo
an STBTTFontinfo struct
font
,
int
the unicode codepoint
codepoint
,
float
the horizontal scale
scale_x
,
float
the vertical scale
scale_y
,
float
the horizontal subpixel shift
shift_x
,
float
the vertical subpixel shift
shift_y
,
IntBuffer
returns the left coordinate
ix0
,
IntBuffer
returns the bottom coordinate
iy0
,
IntBuffer
returns the right coordinate
ix1
,
IntBuffer
returns the top coordinate
iy1
)

Same as GetCodepointBitmapBox, but you can specify a subpixel shift for the character.

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

public static ByteBuffer
stbtt_GetCodepointBitmapSubpixel(STBTTFontinfo
an STBTTFontinfo struct
info
,
float
the horizontal scale
scale_x
,
float
the vertical scale
scale_y
,
float
the horizontal subpixel shift
shift_x
,
float
the vertical subpixel shift
shift_y
,
int
the unicode codepoint to render
codepoint
,
IntBuffer
returns the bitmap width
width
,
IntBuffer
returns the bitmap height
height
,
IntBuffer
returns the horizontal offset in pixel space from the glyph origin to the left of the bitmap
xoff
,
IntBuffer
returns the vertical offset in pixel space from the glyph origin to the top of the bitmap
yoff
)

Same as GetCodepointBitmap, but you can specify a subpixel shift for the character.

public static 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

public static boolean
stbtt_GetCodepointBox(STBTTFontinfo
an STBTTFontinfo struct
info
,
int
the unicode codepoint
codepoint
,
IntBuffer
returns the left coordinate
x0
,
IntBuffer
returns the bottom coordinate
y0
,
IntBuffer
returns the right coordinate
x1
,
IntBuffer
returns the top coordinate
y1
)

Gets the bounding box of the visible part of the glyph, in unscaled coordinates.

public static boolean
stbtt_GetCodepointBox(STBTTFontinfo info, int codepoint, int[] x0, int[] y0, int[] x1, int[] y1)

Array version of: GetCodepointBox

public static void
stbtt_GetCodepointHMetrics(STBTTFontinfo
an STBTTFontinfo struct
info
,
int
the unicode codepoint
codepoint
,
IntBuffer
the offset from the current horizontal position to the next horizontal position
advanceWidth
,
IntBuffer
the offset from the current horizontal position to the left edge of the character
leftSideBearing
)

Returns horizontal metrics for the specified codepoint.

public static void
stbtt_GetCodepointHMetrics(STBTTFontinfo info, int codepoint, int[] advanceWidth, int[] leftSideBearing)

Array version of: GetCodepointHMetrics

public static int
stbtt_GetCodepointKernAdvance(STBTTFontinfo
an STBTTFontinfo struct
info
,
int
the first unicode codepoint
ch1
,
int
the second unicode codepoint
ch2
)

Returns the additional amount to add to the advance value between ch1 and ch2.

public static ByteBuffer
stbtt_GetCodepointSDF(STBTTFontinfo
an STBTTFontinfo struct
font
,
float
controls the size of the resulting SDF bitmap, same as it would be creating a regular bitmap
scale
,
int
the codepoint to generate the SDF for
codepoint
,
int
extra "pixels" around the character which are filled with the distance to the character (not 0), which allows effects like bit outlines
padding
,
byte
value 0-255 to test the SDF against to reconstruct the character (i.e. the isocontour of the character)
onedge_value
,
float
what value the SDF should increase by when moving one SDF "pixel" away from the edge (on the 0..255 scale). If positive, > onedge_value is inside; if negative, < onedge_value is inside.
pixel_dist_scale
,
IntBuffer
output width of the SDF bitmap (including padding)
width
,
IntBuffer
output height of the SDF bitmap (including padding)
height
,
IntBuffer
output horizontal origin of the character
xoff
,
IntBuffer
output vertical origin of the character
yoff
)

Codepoint version of GetGlyphSDF.

public static ByteBuffer
stbtt_GetCodepointSDF(STBTTFontinfo font, float scale, int codepoint, int padding, byte onedge_value, float pixel_dist_scale, int[] width, int[] height, int[] xoff, int[] yoff)

Array version of: GetCodepointSDF

public static int
stbtt_GetCodepointShape(STBTTFontinfo
an STBTTFontinfo struct
info
,
int
the unicode codepoint
unicode_codepoint
,
PointerBuffer
returns a pointer to an array of STBTTVertex structs
vertices
)

Returns number of vertices and fills *vertices with the pointer to them

The shape is a series of contours.

public static STBTTVertex.Buffer
stbtt_GetCodepointShape(STBTTFontinfo
an STBTTFontinfo struct
info
,
int
the unicode codepoint
unicode_codepoint
)

Returns number of vertices and fills *vertices with the pointer to them

The shape is a series of contours.

public static int

Returns:

data size or 0 if SVG not found
stbtt_GetCodepointSVG
(STBTTFontinfo info, int unicode_codepoint, PointerBuffer svg)

Fills svg with the character's SVG data.

public static void
stbtt_GetFontBoundingBox(STBTTFontinfo
an STBTTFontinfo struct
info
,
IntBuffer
the left coordinate
x0
,
IntBuffer
the bottom coordinate
y0
,
IntBuffer
the right coordinate
x1
,
IntBuffer
the top coordinate
y1
)

Returns the bounding box around all possible characters.

public static void
stbtt_GetFontBoundingBox(STBTTFontinfo info, int[] x0, int[] y0, int[] x1, int[] y1)

Array version of: GetFontBoundingBox

public static ByteBuffer
public static int
stbtt_GetFontOffsetForIndex(ByteBuffer
the font data
data
,
int
the font index
index
)

Each .ttf/.ttc file may have more than one font.

public static void
stbtt_GetFontVMetrics(STBTTFontinfo
an STBTTFontinfo struct
info
,
IntBuffer
returns the coordinate above the baseline the font extends
ascent
,
IntBuffer
returns the coordinate below the baseline the font extends (i.e. it is typically negative)
descent
,
IntBuffer
returns the spacing between one row's descent and the next row's ascent
lineGap
)

Returns vertical metrics for the specified font.

public static void
stbtt_GetFontVMetrics(STBTTFontinfo info, int[] ascent, int[] descent, int[] lineGap)

Array version of: GetFontVMetrics

public static boolean

Returns:

1 on success (table present), 0 on failure
stbtt_GetFontVMetricsOS2
(STBTTFontinfo
an STBTTFontinfo struct
info
,
IntBuffer
returns the coordinate above the baseline the font extends
typoAscent
,
IntBuffer
returns the coordinate below the baseline the font extends (i.e. it is typically negative)
typoDescent
,
IntBuffer
returns the spacing between one row's descent and the next row's ascent
typoLineGap
)

Analogous to GetFontVMetrics, but returns the "typographic" values from the OS/2 table (specific to MS/Windows TTF files).

public static boolean
stbtt_GetFontVMetricsOS2(STBTTFontinfo info, int[] typoAscent, int[] typoDescent, int[] typoLineGap)

Array version of: GetFontVMetricsOS2

public static ByteBuffer
stbtt_GetGlyphBitmap(STBTTFontinfo
an STBTTFontinfo struct
info
,
float
the horizontal scale
scale_x
,
float
the vertical scale
scale_y
,
int
the glyph index to render
glyph
,
IntBuffer
returns the bitmap width
width
,
IntBuffer
returns the bitmap height
height
,
IntBuffer
returns the horizontal offset in pixel space from the glyph origin to the left of the bitmap
xoff
,
IntBuffer
returns the vertical offset in pixel space from the glyph origin to the top of the bitmap
yoff
)

Allocates a large-enough single-channel 8bpp bitmap and renders the specified character/glyph at the specified scale into it, with antialiasing.

public static 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

public static void
stbtt_GetGlyphBitmapBox(STBTTFontinfo
an STBTTFontinfo struct
font
,
int
the glyph index
glyph
,
float
the horizontal scale
scale_x
,
float
the vertical scale
scale_y
,
IntBuffer
returns the left coordinate
ix0
,
IntBuffer
returns the bottom coordinate
iy0
,
IntBuffer
returns the right coordinate
ix1
,
IntBuffer
returns the top coordinate
iy1
)

Get the bbox of the bitmap centered around the glyph origin; so the bitmap width is ix1-ix0, height is iy1-iy0, and location to place the bitmap top left is (leftSideBearing*scale,iy0).

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

public static void
stbtt_GetGlyphBitmapBoxSubpixel(STBTTFontinfo
an STBTTFontinfo struct
font
,
int
the glyph index
glyph
,
float
the horizontal scale
scale_x
,
float
the vertical scale
scale_y
,
float
the horizontal subpixel shift
shift_x
,
float
the vertical subpixel shift
shift_y
,
IntBuffer
returns the left coordinate
ix0
,
IntBuffer
returns the bottom coordinate
iy0
,
IntBuffer
returns the right coordinate
ix1
,
IntBuffer
returns the top coordinate
iy1
)

Same as GetGlyphBitmapBox, but you can specify a subpixel shift for the character.

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

public static ByteBuffer
stbtt_GetGlyphBitmapSubpixel(STBTTFontinfo
an STBTTFontinfo struct
info
,
float
the horizontal scale
scale_x
,
float
the vertical scale
scale_y
,
float
the horizontal subpixel shift
shift_x
,
float
the vertical subpixel shift
shift_y
,
int
the glyph index to render
glyph
,
IntBuffer
returns the bitmap width
width
,
IntBuffer
returns the bitmap height
height
,
IntBuffer
returns the horizontal offset in pixel space from the glyph origin to the left of the bitmap
xoff
,
IntBuffer
returns the vertical offset in pixel space from the glyph origin to the top of the bitmap
yoff
)

Same as GetGlyphBitmap, but you can specify a subpixel shift for the character.

public static 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

public static boolean
stbtt_GetGlyphBox(STBTTFontinfo
an STBTTFontinfo struct
info
,
int
the glyph index
glyph_index
,
IntBuffer
returns the left coordinate
x0
,
IntBuffer
returns the bottom coordinate
y0
,
IntBuffer
returns the right coordinate
x1
,
IntBuffer
returns the top coordinate
y1
)

Glyph version of GetCodepointBox, for greater efficiency.

public static boolean
stbtt_GetGlyphBox(STBTTFontinfo info, int glyph_index, int[] x0, int[] y0, int[] x1, int[] y1)

Array version of: GetGlyphBox

public static void
stbtt_GetGlyphHMetrics(STBTTFontinfo
an STBTTFontinfo struct
info
,
int
the glyph index
glyph_index
,
IntBuffer
the offset from the current horizontal position to the next horizontal position
advanceWidth
,
IntBuffer
the offset from the current horizontal position to the left edge of the character
leftSideBearing
)

Glyph version of GetCodepointHMetrics, for greater efficiency.

public static void
stbtt_GetGlyphHMetrics(STBTTFontinfo info, int glyph_index, int[] advanceWidth, int[] leftSideBearing)

Array version of: GetGlyphHMetrics

public static int
stbtt_GetGlyphKernAdvance(STBTTFontinfo
an STBTTFontinfo struct
info
,
int
the first glyph index
glyph1
,
int
the second glyph index
glyph2
)

Glyph version of GetCodepointKernAdvance, for greater efficiency.

public static ByteBuffer
stbtt_GetGlyphSDF(STBTTFontinfo
an STBTTFontinfo struct
font
,
float
controls the size of the resulting SDF bitmap, same as it would be creating a regular bitmap
scale
,
int
the glyph to generate the SDF for
glyph
,
int
extra "pixels" around the character which are filled with the distance to the character (not 0), which allows effects like bit outlines
padding
,
byte
value 0-255 to test the SDF against to reconstruct the character (i.e. the isocontour of the character)
onedge_value
,
float
what value the SDF should increase by when moving one SDF "pixel" away from the edge (on the 0..255 scale). If positive, > onedge_value is inside; if negative, < onedge_value is inside.
pixel_dist_scale
,
IntBuffer
output width of the SDF bitmap (including padding)
width
,
IntBuffer
output height of the SDF bitmap (including padding)
height
,
IntBuffer
output horizontal origin of the character
xoff
,
IntBuffer
output vertical origin of the character
yoff
)

Computes a discretized SDF field for a single character, suitable for storing in a single-channel texture, sampling with bilinear filtering, and testing against larger than some threshold to produce scalable fonts.

public static ByteBuffer
stbtt_GetGlyphSDF(STBTTFontinfo font, float scale, int glyph, int padding, byte onedge_value, float pixel_dist_scale, int[] width, int[] height, int[] xoff, int[] yoff)

Array version of: GetGlyphSDF

public static int
stbtt_GetGlyphShape(STBTTFontinfo
an STBTTFontinfo struct
info
,
int
the unicode codepoint
glyph_index
,
PointerBuffer
returns a pointer to an array of STBTTVertex structs
vertices
)

Glyph version of GetCodepointShape, for greater efficiency.

public static STBTTVertex.Buffer
stbtt_GetGlyphShape(STBTTFontinfo
an STBTTFontinfo struct
info
,
int
the unicode codepoint
glyph_index
)

Glyph version of GetCodepointShape, for greater efficiency.

public static int

Returns:

data size or 0 if SVG not found
stbtt_GetGlyphSVG
(STBTTFontinfo info, int gl, PointerBuffer svg)

Fills svg with the character's SVG data.

public static int
stbtt_GetKerningTable(STBTTFontinfo info, STBTTKerningentry.Buffer table)

Retrieves a complete list of all of the kerning pairs provided by the font.

public static int
public static int
stbtt_GetNumberOfFonts(ByteBuffer
the font data
data
)

Determines the number of fonts in a font file.

public static void
stbtt_GetPackedQuad(STBTTPackedchar.Buffer
an array of STBTTPackedchar structs
chardata
,
int
the bitmap width, in pixels
pw
,
int
the bitmap height, in pixels
ph
,
int
the character index in the chardata array
char_index
,
FloatBuffer
the current x position, in screen pixel space
xpos
,
FloatBuffer
the current y position, in screen pixel space
ypos
,
STBTTAlignedQuad
an STBTTAlignedQuad struct in which to return the quad to draw
q
,
boolean
1 to align the quad to integer coordinates
align_to_integer
)

Computes quad to draw for a given char and advances the current position.

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

public static void
stbtt_GetScaledFontVMetrics(ByteBuffer fontdata, int
the font index (use 0 if you don't know what that is)
index
,
float
the font height, in pixels
size
,
FloatBuffer
returns the coordinate above the baseline the font extends
ascent
,
FloatBuffer
returns the coordinate below the baseline the font extends (i.e. it is typically negative)
descent
,
FloatBuffer
returns the spacing between one row's descent and the next row's ascent
lineGap
)

Query the font vertical metrics without having to create a font first.

public static void
stbtt_GetScaledFontVMetrics(ByteBuffer fontdata, int index, float size, float[] ascent, float[] descent, float[] lineGap)

Array version of: GetScaledFontVMetrics

public static boolean

Returns:

1 on success, 0 on failure
stbtt_InitFont
(STBTTFontinfo
an STBTTFontinfo struct
info
,
ByteBuffer
the font data
data
,
int
the font data offset
offset
)

Given an offset into the file that defines a font, this function builds the necessary cached info for the rest of the system.

public static boolean

Returns:

1 on success, 0 on failure
stbtt_InitFont
(STBTTFontinfo
an STBTTFontinfo struct
info
,
ByteBuffer
the font data
data
)

Given an offset into the file that defines a font, this function builds the necessary cached info for the rest of the system.

public static boolean
stbtt_IsGlyphEmpty(STBTTFontinfo
an STBTTFontinfo struct
info
,
int
the glyph index
glyph_index
)

Returns non-zero if nothing is drawn for this glyph.

public static void
stbtt_MakeCodepointBitmap(STBTTFontinfo
an STBTTFontinfo struct
info
,
ByteBuffer
the bitmap storage
output
,
int
the bitmap width
out_w
,
int
the bitmap height
out_h
,
int
the row stride, in bytes
out_stride
,
float
the horizontal scale
scale_x
,
float
the vertical scale
scale_y
,
int
the unicode codepoint to render
codepoint
)

Same as GetCodepointBitmap, but you pass in storage for the bitmap in the form of output, with row spacing of out_stride bytes.

public static void
stbtt_MakeCodepointBitmapSubpixel(STBTTFontinfo
an STBTTFontinfo struct
info
,
ByteBuffer
the bitmap storage
output
,
int
the bitmap width
out_w
,
int
the bitmap height
out_h
,
int
the row stride, in bytes
out_stride
,
float
the horizontal scale
scale_x
,
float
the vertical scale
scale_y
,
float
the horizontal subpixel shift
shift_x
,
float
the vertical subpixel shift
shift_y
,
int
the unicode codepoint to render
codepoint
)

Same as MakeCodepointBitmap, but you can specify a subpixel shift for the character.

public static void
stbtt_MakeCodepointBitmapSubpixelPrefilter(STBTTFontinfo
an STBTTFontinfo struct
info
,
ByteBuffer
the bitmap storage
output
,
int
the bitmap width
out_w
,
int
the bitmap height
out_h
,
int
the row stride, in bytes
out_stride
,
float
the horizontal scale
scale_x
,
float
the vertical scale
scale_y
,
float
the horizontal subpixel shift
shift_x
,
float
the vertical subpixel shift
shift_y
,
int
the horizontal oversampling amount
oversample_x
,
int
the vertical oversampling amount
oversample_y
,
FloatBuffer
returns the horizontal oversample shift
sub_x
,
FloatBuffer
returns the vertical oversample shift
sub_y
,
int
the unicode codepoint to render
codepoint
)

Same as MakeCodepointBitmapSubpixel, but prefiltering is performed (see PackSetOversampling).

public static void
stbtt_MakeCodepointBitmapSubpixelPrefilter(STBTTFontinfo info, ByteBuffer output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int oversample_x, int oversample_y, float[] sub_x, float[] sub_y, int codepoint)

Array version of: MakeCodepointBitmapSubpixelPrefilter

public static void
stbtt_MakeGlyphBitmap(STBTTFontinfo
an STBTTFontinfo struct
info
,
ByteBuffer
the bitmap storage
output
,
int
the bitmap width
out_w
,
int
the bitmap height
out_h
,
int
the row stride, in bytes
out_stride
,
float
the horizontal scale
scale_x
,
float
the vertical scale
scale_y
,
int
the glyph index to render
glyph
)

Same as GetGlyphBitmap, but you pass in storage for the bitmap in the form of output, with row spacing of out_stride bytes.

public static void
stbtt_MakeGlyphBitmapSubpixel(STBTTFontinfo
an STBTTFontinfo struct
info
,
ByteBuffer
the bitmap storage
output
,
int
the bitmap width
out_w
,
int
the bitmap height
out_h
,
int
the row stride, in bytes
out_stride
,
float
the horizontal scale
scale_x
,
float
the vertical scale
scale_y
,
float
the horizontal subpixel shift
shift_x
,
float
the vertical subpixel shift
shift_y
,
int
the glyph index to render
glyph
)

Same as MakeGlyphBitmap, but you can specify a subpixel shift for the character.

public static void
stbtt_MakeGlyphBitmapSubpixelPrefilter(STBTTFontinfo
an STBTTFontinfo struct
info
,
ByteBuffer
the bitmap storage
output
,
int
the bitmap width
out_w
,
int
the bitmap height
out_h
,
int
the row stride, in bytes
out_stride
,
float
the horizontal scale
scale_x
,
float
the vertical scale
scale_y
,
float
the horizontal subpixel shift
shift_x
,
float
the vertical subpixel shift
shift_y
,
int
the horizontal oversampling amount
oversample_x
,
int
the vertical oversampling amount
oversample_y
,
FloatBuffer
returns the horizontal oversample shift
sub_x
,
FloatBuffer
returns the vertical oversample shift
sub_y
,
int
the glyph index to render
glyph
)

Same as MakeGlyphBitmapSubpixel, but prefiltering is performed (see PackSetOversampling).

public static void
stbtt_MakeGlyphBitmapSubpixelPrefilter(STBTTFontinfo info, ByteBuffer output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int oversample_x, int oversample_y, float[] sub_x, float[] sub_y, int glyph)

Array version of: MakeGlyphBitmapSubpixelPrefilter

public static boolean

Returns:

1 on success, 0 on failure
stbtt_PackBegin
(STBTTPackContext spc, ByteBuffer
a buffer in which to store the bitmap data
pixels
,
int
the bitmap width, in pixels
width
,
int
the bitmap height, in pixels
height
,
int
the distance from one row to the next (or 0 to mean they are packed tightly together)
stride_in_bytes
,
int
the amount of padding to leave between each character (normally you want '1' for bitmaps you'll use as textures with bilinear filtering)
padding
,
long
a pointer to an allocation context
alloc_context
)

Initializes a packing context stored in the passed-in stbtt_pack_context.

public static boolean

Returns:

1 on success, 0 on failure
stbtt_PackBegin
(STBTTPackContext spc, ByteBuffer
a buffer in which to store the bitmap data
pixels
,
int
the bitmap width, in pixels
width
,
int
the bitmap height, in pixels
height
,
int
the distance from one row to the next (or 0 to mean they are packed tightly together)
stride_in_bytes
,
int
the amount of padding to leave between each character (normally you want '1' for bitmaps you'll use as textures with bilinear filtering)
padding
)

Initializes a packing context stored in the passed-in stbtt_pack_context.

public static void
stbtt_PackEnd(STBTTPackContext spc)

Cleans up the packing context and frees all memory.

public static boolean

Returns:

1 on success, 0 on failure
stbtt_PackFontRange
(STBTTPackContext spc, ByteBuffer
the font data
fontdata
,
int
the font index (use 0 if you don't know what that is
font_index
,
float
the full height of the character from ascender to descender, as computed by ScaleForPixelHeight. To use a point size as computed by ScaleForMappingEmToPixels, wrap the font size in STBTT_POINT_SIZE 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
font_size
,
int
the first unicode code point in the range
first_unicode_char_in_range
,
STBTTPackedchar.Buffer
an array of STBTTPackedchar structs
chardata_for_range
)

Creates character bitmaps from the font_index'th font found in fontdata (use font_index=0 if you don't know what that is).

public static boolean

Returns:

1 on success, 0 on failure
stbtt_PackFontRanges
(STBTTPackContext spc, ByteBuffer
the font data
fontdata
,
int
the font index (use 0 if you don't know what that is)
font_index
,
STBTTPackRange.Buffer
an array of STBTTPackRange structs
ranges
)

Creates character bitmaps from multiple ranges of characters stored in ranges.

public static int

Returns:

the number of structs written in rects
stbtt_PackFontRangesGatherRects
(STBTTPackContext spc, STBTTFontinfo
an STBTTFontinfo struct
info
,
STBTTPackRange.Buffer
an array of STBTTPackRange structs
ranges
,
STBRPRect.Buffer
an array of STBRPRect structs. It must be big enough to accommodate all characters in the given ranges.
rects
)

Calling these functions in sequence is roughly equivalent to calling PackFontRanges.

public static void
public static boolean

Returns:

1 on success, 0 on failure
stbtt_PackFontRangesRenderIntoRects
(STBTTPackContext spc, STBTTFontinfo
an STBTTFontinfo struct
info
,
STBTTPackRange.Buffer
an array of STBTTPackRange structs
ranges
,
STBRPRect.Buffer
an array of STBRPRect structs. It must be big enough to accommodate all characters in the given ranges.
rects
)

See PackFontRangesGatherRects.

public static void
stbtt_PackSetOversampling(STBTTPackContext spc, int
the horizontal oversampling amount
h_oversample
,
int
the vertical oversampling amount
v_oversample
)

Oversampling a font increases the quality by allowing higher-quality subpixel positioning, and is especially valuable at smaller text sizes.

public static void
stbtt_PackSetSkipMissingCodepoints(STBTTPackContext spc, boolean
the skip flag
skip
)

If skip != 0, this tells stb_truetype to skip any codepoints for which there is no corresponding glyph.

public static int

Returns:

the point size of the character
STBTT_POINT_SIZE
(int
the full height of a character
font_size
)

Converts the full height of a character from ascender to descender, as computed by ScaleForPixelHeight, to a point size as computed by ScaleForMappingEmToPixels.

public static void
stbtt_Rasterize(STBTTBitmap
1-channel bitmap to draw into
result
,
float
allowable error of curve in pixels
flatness_in_pixels
,
STBTTVertex.Buffer
array of vertices defining shape
vertices
,
float
horizontal scale applied to input vertices
scale_x
,
float
vertical scale applied to input vertices
scale_y
,
float
horizontal translation applied to input vertices
shift_x
,
float
vertical translation applied to input vertices
shift_y
,
int
another horizontal translation applied to input
x_off
,
int
another vertical translation applied to input
y_off
,
boolean
if non-zero, vertically flip shape
invert
)

Rasterize a shape with quadratic beziers into a bitmap.

public static float

Returns:

the scale factor
stbtt_ScaleForMappingEmToPixels
(STBTTFontinfo
an STBTTFontinfo struct
info
,
float
the font height, in pixels
pixels
)

Computes a scale factor to produce a font whose EM size is mapped to pixels tall.

public static float

Returns:

the scale factor
stbtt_ScaleForPixelHeight
(STBTTFontinfo
an STBTTFontinfo struct
info
,
float
the font height, in pixels
pixels
)

Computes a scale factor to produce a font whose "height" is pixels tall.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait