Updated to latest version
This commit is contained in:
parent
7db895ab5d
commit
05fe1c22ed
2 changed files with 148 additions and 114 deletions
|
@ -1,4 +1,4 @@
|
|||
// stb_rect_pack.h - v0.05 - public domain - rectangle packing
|
||||
// stb_rect_pack.h - v0.06 - public domain - rectangle packing
|
||||
// Sean Barrett 2014
|
||||
//
|
||||
// Useful for e.g. packing rectangular textures into an atlas.
|
||||
|
@ -13,6 +13,7 @@
|
|||
// More docs to come.
|
||||
//
|
||||
// No memory allocations; uses qsort() and assert() from stdlib.
|
||||
// Can override those by defining STBRP_SORT and STBRP_ASSERT.
|
||||
//
|
||||
// This library currently uses the Skyline Bottom-Left algorithm.
|
||||
//
|
||||
|
@ -20,8 +21,18 @@
|
|||
// implement them to the same API, but with a different init
|
||||
// function.
|
||||
//
|
||||
// Credits
|
||||
//
|
||||
// Library
|
||||
// Sean Barrett
|
||||
// Minor features
|
||||
// Martins Mozeiko
|
||||
// Bugfixes / warning fixes
|
||||
// [your name could be here]
|
||||
//
|
||||
// Version history:
|
||||
//
|
||||
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
|
||||
// 0.05: added STBRP_ASSERT to allow replacing assert
|
||||
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
|
||||
// 0.01: initial release
|
||||
|
@ -169,7 +180,10 @@ struct stbrp_context
|
|||
//
|
||||
|
||||
#ifdef STB_RECT_PACK_IMPLEMENTATION
|
||||
#ifndef STBRP_SORT
|
||||
#include <stdlib.h>
|
||||
#define STBRP_SORT qsort
|
||||
#endif
|
||||
|
||||
#ifndef STBRP_ASSERT
|
||||
#include <assert.h>
|
||||
|
@ -524,7 +538,7 @@ STBRP_DEF void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int n
|
|||
}
|
||||
|
||||
// sort according to heuristic
|
||||
qsort(rects, num_rects, sizeof(rects[0]), rect_height_compare);
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
|
||||
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
|
||||
|
@ -537,7 +551,7 @@ STBRP_DEF void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int n
|
|||
}
|
||||
|
||||
// unsort
|
||||
qsort(rects, num_rects, sizeof(rects[0]), rect_original_order);
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
|
||||
|
||||
// set was_packed flags
|
||||
for (i=0; i < num_rects; ++i)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// stb_truetype.h - v1.02 - public domain
|
||||
// stb_truetype.h - v1.05 - public domain
|
||||
// authored from 2009-2014 by Sean Barrett / RAD Game Tools
|
||||
//
|
||||
// This library processes TrueType files:
|
||||
|
@ -34,12 +34,20 @@
|
|||
// Johan Duparc
|
||||
// Hou Qiming
|
||||
// Fabian "ryg" Giesen
|
||||
// Martins Mozeiko
|
||||
// Cap Petschulat
|
||||
// Omar Cornut
|
||||
// github:aloucks
|
||||
// Peter LaValle
|
||||
//
|
||||
// Misc other:
|
||||
// Ryan Gordon
|
||||
//
|
||||
// VERSION HISTORY
|
||||
//
|
||||
// 1.05 (2015-04-15) fix misplaced definitions for STBTT_STATIC
|
||||
// 1.04 (2015-04-15) typo in example
|
||||
// 1.03 (2015-04-12) STBTT_STATIC, fix memory leak in new packing, various fixes
|
||||
// 1.02 (2014-12-10) fix various warnings & compile issues w/ stb_rect_pack, C++
|
||||
// 1.01 (2014-12-08) fix subpixel position when oversampling to exactly match
|
||||
// non-oversampled; STBTT_POINT_SIZE for packed case only
|
||||
|
@ -83,6 +91,9 @@
|
|||
// before the #include of this file. This expands out the actual
|
||||
// implementation into that C/C++ file.
|
||||
//
|
||||
// To make the implementation private to the file that generates the implementation,
|
||||
// #define STBTT_STATIC
|
||||
//
|
||||
// Simple 3D API (don't ship this, but it's fine for tools and quick start)
|
||||
// stbtt_BakeFontBitmap() -- bake a font to a bitmap for use as texture
|
||||
// stbtt_GetBakedQuad() -- compute quad to draw for a given char
|
||||
|
@ -222,16 +233,16 @@
|
|||
#define STB_TRUETYPE_IMPLEMENTATION // force following include to generate implementation
|
||||
#include "stb_truetype.h"
|
||||
|
||||
char ttf_buffer[1<<20];
|
||||
unsigned char ttf_buffer[1<<20];
|
||||
unsigned char temp_bitmap[512*512];
|
||||
|
||||
stbtt_bakedchar cdata[96]; // ASCII 32..126 is 95 glyphs
|
||||
GLstbtt_uint ftex;
|
||||
GLuint ftex;
|
||||
|
||||
void my_stbtt_initfont(void)
|
||||
{
|
||||
fread(ttf_buffer, 1, 1<<20, fopen("c:/windows/fonts/times.ttf", "rb"));
|
||||
stbtt_BakeFontBitmap(data,0, 32.0, temp_bitmap,512,512, 32,96, cdata); // no guarantee this fits!
|
||||
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);
|
||||
|
@ -243,6 +254,7 @@ void my_stbtt_initfont(void)
|
|||
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) {
|
||||
|
@ -428,6 +440,12 @@ int main(int arg, char **argv)
|
|||
#ifndef __STB_INCLUDE_STB_TRUETYPE_H__
|
||||
#define __STB_INCLUDE_STB_TRUETYPE_H__
|
||||
|
||||
#ifdef STBTT_STATIC
|
||||
#define STBTT_DEF static
|
||||
#else
|
||||
#define STBTT_DEF extern
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -445,7 +463,7 @@ typedef struct
|
|||
float xoff,yoff,xadvance;
|
||||
} stbtt_bakedchar;
|
||||
|
||||
extern int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)
|
||||
STBTT_DEF int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)
|
||||
float pixel_height, // height of font in pixels
|
||||
unsigned char *pixels, int pw, int ph, // bitmap to be filled in
|
||||
int first_char, int num_chars, // characters to bake
|
||||
|
@ -461,7 +479,7 @@ typedef struct
|
|||
float x1,y1,s1,t1; // bottom-right
|
||||
} stbtt_aligned_quad;
|
||||
|
||||
extern void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, // same data as above
|
||||
STBTT_DEF void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, // same data as above
|
||||
int char_index, // character to display
|
||||
float *xpos, float *ypos, // pointers to current position in screen pixel space
|
||||
stbtt_aligned_quad *q, // output: quad to draw
|
||||
|
@ -494,7 +512,7 @@ typedef struct
|
|||
|
||||
typedef struct stbtt_pack_context stbtt_pack_context;
|
||||
|
||||
extern int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int width, int height, int stride_in_bytes, int padding, void *alloc_context);
|
||||
STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int width, int height, int stride_in_bytes, int padding, void *alloc_context);
|
||||
// Initializes a packing context stored in the passed-in stbtt_pack_context.
|
||||
// Future calls using this context will pack characters into the bitmap passed
|
||||
// in here: a 1-channel bitmap that is weight x height. stride_in_bytes is
|
||||
|
@ -505,12 +523,12 @@ extern int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int
|
|||
//
|
||||
// Returns 0 on failure, 1 on success.
|
||||
|
||||
extern void stbtt_PackEnd (stbtt_pack_context *spc);
|
||||
STBTT_DEF void stbtt_PackEnd (stbtt_pack_context *spc);
|
||||
// Cleans up the packing context and frees all memory.
|
||||
|
||||
#define STBTT_POINT_SIZE(x) (-(x))
|
||||
|
||||
extern int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,
|
||||
STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,
|
||||
int first_unicode_char_in_range, int num_chars_in_range, stbtt_packedchar *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). It creates num_chars_in_range
|
||||
|
@ -533,13 +551,13 @@ typedef struct
|
|||
stbtt_packedchar *chardata_for_range; // output
|
||||
} stbtt_pack_range;
|
||||
|
||||
extern int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges);
|
||||
STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges);
|
||||
// Creates character bitmaps from multiple ranges of characters stored in
|
||||
// ranges. This will usually create a better-packed bitmap than multiple
|
||||
// calls to stbtt_PackFontRange.
|
||||
|
||||
|
||||
extern void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample);
|
||||
STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample);
|
||||
// Oversampling a font increases the quality by allowing higher-quality subpixel
|
||||
// positioning, and is especially valuable at smaller text sizes.
|
||||
//
|
||||
|
@ -551,7 +569,7 @@ extern void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_ov
|
|||
// oversampled textures with bilinear filtering. Look at the readme in
|
||||
// stb/tests/oversample for information about oversampled fonts
|
||||
|
||||
extern void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, // same data as above
|
||||
STBTT_DEF void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, // same data as above
|
||||
int char_index, // character to display
|
||||
float *xpos, float *ypos, // pointers to current position in screen pixel space
|
||||
stbtt_aligned_quad *q, // output: quad to draw
|
||||
|
@ -577,7 +595,7 @@ struct stbtt_pack_context {
|
|||
//
|
||||
//
|
||||
|
||||
extern int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index);
|
||||
STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *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
|
||||
|
@ -601,7 +619,7 @@ typedef struct stbtt_fontinfo
|
|||
int indexToLocFormat; // format needed to map from glyph index to glyph
|
||||
} stbtt_fontinfo;
|
||||
|
||||
extern int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset);
|
||||
STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *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
|
||||
// the stbtt_fontinfo yourself, and stbtt_InitFont will fill it out. You don't
|
||||
|
@ -613,7 +631,7 @@ extern int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int o
|
|||
//
|
||||
// CHARACTER TO GLYPH-INDEX CONVERSIOn
|
||||
|
||||
int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint);
|
||||
STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *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
|
||||
|
@ -625,7 +643,7 @@ int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint);
|
|||
// CHARACTER PROPERTIES
|
||||
//
|
||||
|
||||
extern float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float pixels);
|
||||
STBTT_DEF float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float pixels);
|
||||
// computes a scale factor to produce a font whose "height" is 'pixels' tall.
|
||||
// Height is measured as the distance from the highest ascender to the lowest
|
||||
// descender; in other words, it's equivalent to calling stbtt_GetFontVMetrics
|
||||
|
@ -633,12 +651,12 @@ extern float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float pixels)
|
|||
// scale = pixels / (ascent - descent)
|
||||
// so if you prefer to measure height by the ascent only, use a similar calculation.
|
||||
|
||||
extern float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels);
|
||||
STBTT_DEF float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels);
|
||||
// computes a scale factor to produce a font whose EM size is mapped to
|
||||
// 'pixels' tall. This is probably what traditional APIs compute, but
|
||||
// I'm not positive.
|
||||
|
||||
extern void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap);
|
||||
STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap);
|
||||
// ascent is the coordinate above the baseline the font extends; descent
|
||||
// is the coordinate below the baseline the font extends (i.e. it is typically negative)
|
||||
// lineGap is the spacing between one row's descent and the next row's ascent...
|
||||
|
@ -646,23 +664,23 @@ extern void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *
|
|||
// these are expressed in unscaled coordinates, so you must multiply by
|
||||
// the scale factor for a given size
|
||||
|
||||
extern void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1);
|
||||
STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1);
|
||||
// the bounding box around all possible characters
|
||||
|
||||
extern void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing);
|
||||
STBTT_DEF void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing);
|
||||
// leftSideBearing is the offset from the current horizontal position to the left edge of the character
|
||||
// advanceWidth is the offset from the current horizontal position to the next horizontal position
|
||||
// these are expressed in unscaled coordinates
|
||||
|
||||
extern int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2);
|
||||
STBTT_DEF int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2);
|
||||
// an additional amount to add to the 'advance' value between ch1 and ch2
|
||||
|
||||
extern int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1);
|
||||
STBTT_DEF int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1);
|
||||
// Gets the bounding box of the visible part of the glyph, in unscaled coordinates
|
||||
|
||||
extern void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing);
|
||||
extern int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2);
|
||||
extern int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1);
|
||||
STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing);
|
||||
STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2);
|
||||
STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1);
|
||||
// as above, but takes one or more glyph indices for greater efficiency
|
||||
|
||||
|
||||
|
@ -690,11 +708,11 @@ extern int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *
|
|||
} stbtt_vertex;
|
||||
#endif
|
||||
|
||||
extern int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index);
|
||||
STBTT_DEF int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index);
|
||||
// returns non-zero if nothing is drawn for this glyph
|
||||
|
||||
extern int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices);
|
||||
extern int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **vertices);
|
||||
STBTT_DEF int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices);
|
||||
STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **vertices);
|
||||
// returns # of vertices and fills *vertices with the pointer to them
|
||||
// these are expressed in "unscaled" coordinates
|
||||
//
|
||||
|
@ -705,7 +723,7 @@ extern int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbt
|
|||
// draws a quadratic bezier from previous endpoint to
|
||||
// its x,y, using cx,cy as the bezier control point.
|
||||
|
||||
extern void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices);
|
||||
STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices);
|
||||
// frees the data allocated above
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -713,10 +731,10 @@ extern void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices);
|
|||
// BITMAP RENDERING
|
||||
//
|
||||
|
||||
extern void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata);
|
||||
STBTT_DEF void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata);
|
||||
// frees the bitmap allocated below
|
||||
|
||||
extern unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff);
|
||||
STBTT_DEF unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff);
|
||||
// allocates a large-enough single-channel 8bpp bitmap and renders the
|
||||
// specified character/glyph at the specified scale into it, with
|
||||
// antialiasing. 0 is no coverage (transparent), 255 is fully covered (opaque).
|
||||
|
@ -725,39 +743,39 @@ extern unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float
|
|||
//
|
||||
// xoff/yoff are the offset it pixel space from the glyph origin to the top-left of the bitmap
|
||||
|
||||
extern unsigned char *stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int *width, int *height, int *xoff, int *yoff);
|
||||
STBTT_DEF unsigned char *stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int *width, int *height, int *xoff, int *yoff);
|
||||
// the same as stbtt_GetCodepoitnBitmap, but you can specify a subpixel
|
||||
// shift for the character
|
||||
|
||||
extern void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint);
|
||||
STBTT_DEF void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint);
|
||||
// the same as stbtt_GetCodepointBitmap, but you pass in storage for the bitmap
|
||||
// in the form of 'output', with row spacing of 'out_stride' bytes. the bitmap
|
||||
// is clipped to out_w/out_h bytes. Call stbtt_GetCodepointBitmapBox to get the
|
||||
// width and height and positioning info for it first.
|
||||
|
||||
extern void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint);
|
||||
STBTT_DEF void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *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 as stbtt_MakeCodepointBitmap, but you can specify a subpixel
|
||||
// shift for the character
|
||||
|
||||
extern void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1);
|
||||
STBTT_DEF void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *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).
|
||||
// (Note that the bitmap uses y-increases-down, but the shape uses
|
||||
// y-increases-up, so CodepointBitmapBox and CodepointBox are inverted.)
|
||||
|
||||
extern void stbtt_GetCodepointBitmapBoxSubpixel(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1);
|
||||
STBTT_DEF void stbtt_GetCodepointBitmapBoxSubpixel(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1);
|
||||
// same as stbtt_GetCodepointBitmapBox, but you can specify a subpixel
|
||||
// shift for the character
|
||||
|
||||
// the following functions are equivalent to the above functions, but operate
|
||||
// on glyph indices instead of Unicode codepoints (for efficiency)
|
||||
extern unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff);
|
||||
extern unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff);
|
||||
extern void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph);
|
||||
extern void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph);
|
||||
extern void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1);
|
||||
extern void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y,float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1);
|
||||
STBTT_DEF unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff);
|
||||
STBTT_DEF unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff);
|
||||
STBTT_DEF void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph);
|
||||
STBTT_DEF void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph);
|
||||
STBTT_DEF void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1);
|
||||
STBTT_DEF void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y,float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1);
|
||||
|
||||
|
||||
// @TODO: don't expose this structure
|
||||
|
@ -767,7 +785,7 @@ typedef struct
|
|||
unsigned char *pixels;
|
||||
} stbtt__bitmap;
|
||||
|
||||
extern void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata);
|
||||
STBTT_DEF void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
@ -791,7 +809,7 @@ extern void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stb
|
|||
// You have to have called stbtt_InitFont() first.
|
||||
|
||||
|
||||
extern int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *name, int flags);
|
||||
STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *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
|
||||
|
@ -802,11 +820,11 @@ extern int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *nam
|
|||
#define STBTT_MACSTYLE_UNDERSCORE 4
|
||||
#define STBTT_MACSTYLE_NONE 8 // <= not same as 0, this makes us check the bitfield is 0
|
||||
|
||||
extern int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2);
|
||||
STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2);
|
||||
// returns 1/0 whether the first string interpreted as utf8 is identical to
|
||||
// the second string interpreted as big-endian utf16... useful for strings from next func
|
||||
|
||||
extern const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID);
|
||||
STBTT_DEF const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, 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.
|
||||
//
|
||||
|
@ -905,10 +923,10 @@ typedef int stbtt__test_oversample_pow2[(STBTT_MAX_OVERSAMPLE & (STBTT_MAX_OVERS
|
|||
|
||||
#else
|
||||
|
||||
stbtt_uint16 ttUSHORT(const stbtt_uint8 *p) { return p[0]*256 + p[1]; }
|
||||
stbtt_int16 ttSHORT(const stbtt_uint8 *p) { return p[0]*256 + p[1]; }
|
||||
stbtt_uint32 ttULONG(const stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }
|
||||
stbtt_int32 ttLONG(const stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }
|
||||
static stbtt_uint16 ttUSHORT(const stbtt_uint8 *p) { return p[0]*256 + p[1]; }
|
||||
static stbtt_int16 ttSHORT(const stbtt_uint8 *p) { return p[0]*256 + p[1]; }
|
||||
static stbtt_uint32 ttULONG(const stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }
|
||||
static stbtt_int32 ttLONG(const stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -939,7 +957,7 @@ static stbtt_uint32 stbtt__find_table(stbtt_uint8 *data, stbtt_uint32 fontstart,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int stbtt_GetFontOffsetForIndex(const unsigned char *font_collection, int index)
|
||||
STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *font_collection, int index)
|
||||
{
|
||||
// if it's just a font, there's only one valid index
|
||||
if (stbtt__isfont(font_collection))
|
||||
|
@ -958,7 +976,7 @@ int stbtt_GetFontOffsetForIndex(const unsigned char *font_collection, int index)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data2, int fontstart)
|
||||
STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data2, int fontstart)
|
||||
{
|
||||
stbtt_uint8 *data = (stbtt_uint8 *) data2;
|
||||
stbtt_uint32 cmap, t;
|
||||
|
@ -1015,7 +1033,7 @@ int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data2, int fontsta
|
|||
return 1;
|
||||
}
|
||||
|
||||
int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint)
|
||||
STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint)
|
||||
{
|
||||
stbtt_uint8 *data = info->data;
|
||||
stbtt_uint32 index_map = info->index_map;
|
||||
|
@ -1040,7 +1058,6 @@ int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint)
|
|||
stbtt_uint16 searchRange = ttUSHORT(data+index_map+8) >> 1;
|
||||
stbtt_uint16 entrySelector = ttUSHORT(data+index_map+10);
|
||||
stbtt_uint16 rangeShift = ttUSHORT(data+index_map+12) >> 1;
|
||||
stbtt_uint16 item, offset, start, end;
|
||||
|
||||
// do a binary search of the segments
|
||||
stbtt_uint32 endCount = index_map + 14;
|
||||
|
@ -1057,8 +1074,8 @@ int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint)
|
|||
// now decrement to bias correctly to find smallest
|
||||
search -= 2;
|
||||
while (entrySelector) {
|
||||
stbtt_uint16 end;
|
||||
searchRange >>= 1;
|
||||
start = ttUSHORT(data + search + searchRange*2 + segcount*2 + 2);
|
||||
end = ttUSHORT(data + search + searchRange*2);
|
||||
if (unicode_codepoint > end)
|
||||
search += searchRange*2;
|
||||
|
@ -1066,19 +1083,21 @@ int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint)
|
|||
}
|
||||
search += 2;
|
||||
|
||||
item = (stbtt_uint16) ((search - endCount) >> 1);
|
||||
{
|
||||
stbtt_uint16 offset, start;
|
||||
stbtt_uint16 item = (stbtt_uint16) ((search - endCount) >> 1);
|
||||
|
||||
STBTT_assert(unicode_codepoint <= ttUSHORT(data + endCount + 2*item));
|
||||
start = ttUSHORT(data + index_map + 14 + segcount*2 + 2 + 2*item);
|
||||
end = ttUSHORT(data + index_map + 14 + 2 + 2*item);
|
||||
if (unicode_codepoint < start)
|
||||
return 0;
|
||||
STBTT_assert(unicode_codepoint <= ttUSHORT(data + endCount + 2*item));
|
||||
start = ttUSHORT(data + index_map + 14 + segcount*2 + 2 + 2*item);
|
||||
if (unicode_codepoint < start)
|
||||
return 0;
|
||||
|
||||
offset = ttUSHORT(data + index_map + 14 + segcount*6 + 2 + 2*item);
|
||||
if (offset == 0)
|
||||
return (stbtt_uint16) (unicode_codepoint + ttSHORT(data + index_map + 14 + segcount*4 + 2 + 2*item));
|
||||
offset = ttUSHORT(data + index_map + 14 + segcount*6 + 2 + 2*item);
|
||||
if (offset == 0)
|
||||
return (stbtt_uint16) (unicode_codepoint + ttSHORT(data + index_map + 14 + segcount*4 + 2 + 2*item));
|
||||
|
||||
return ttUSHORT(data + offset + (unicode_codepoint-start)*2 + index_map + 14 + segcount*6 + 2 + 2*item);
|
||||
return ttUSHORT(data + offset + (unicode_codepoint-start)*2 + index_map + 14 + segcount*6 + 2 + 2*item);
|
||||
}
|
||||
} else if (format == 12 || format == 13) {
|
||||
stbtt_uint32 ngroups = ttULONG(data+index_map+12);
|
||||
stbtt_int32 low,high;
|
||||
|
@ -1107,7 +1126,7 @@ int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices)
|
||||
STBTT_DEF int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices)
|
||||
{
|
||||
return stbtt_GetGlyphShape(info, stbtt_FindGlyphIndex(info, unicode_codepoint), vertices);
|
||||
}
|
||||
|
@ -1139,7 +1158,7 @@ static int stbtt__GetGlyfOffset(const stbtt_fontinfo *info, int glyph_index)
|
|||
return g1==g2 ? -1 : g1; // if length is 0, return -1
|
||||
}
|
||||
|
||||
int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1)
|
||||
STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1)
|
||||
{
|
||||
int g = stbtt__GetGlyfOffset(info, glyph_index);
|
||||
if (g < 0) return 0;
|
||||
|
@ -1151,12 +1170,12 @@ int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int
|
|||
return 1;
|
||||
}
|
||||
|
||||
int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1)
|
||||
STBTT_DEF int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1)
|
||||
{
|
||||
return stbtt_GetGlyphBox(info, stbtt_FindGlyphIndex(info,codepoint), x0,y0,x1,y1);
|
||||
}
|
||||
|
||||
int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index)
|
||||
STBTT_DEF int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index)
|
||||
{
|
||||
stbtt_int16 numberOfContours;
|
||||
int g = stbtt__GetGlyfOffset(info, glyph_index);
|
||||
|
@ -1181,7 +1200,7 @@ static int stbtt__close_shape(stbtt_vertex *vertices, int num_vertices, int was_
|
|||
return num_vertices;
|
||||
}
|
||||
|
||||
int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices)
|
||||
STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices)
|
||||
{
|
||||
stbtt_int16 numberOfContours;
|
||||
stbtt_uint8 *endPtsOfContours;
|
||||
|
@ -1407,7 +1426,7 @@ int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_verte
|
|||
return num_vertices;
|
||||
}
|
||||
|
||||
void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing)
|
||||
STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing)
|
||||
{
|
||||
stbtt_uint16 numOfLongHorMetrics = ttUSHORT(info->data+info->hhea + 34);
|
||||
if (glyph_index < numOfLongHorMetrics) {
|
||||
|
@ -1419,7 +1438,7 @@ void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *ad
|
|||
}
|
||||
}
|
||||
|
||||
int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2)
|
||||
STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2)
|
||||
{
|
||||
stbtt_uint8 *data = info->data + info->kern;
|
||||
stbtt_uint32 needle, straw;
|
||||
|
@ -1449,26 +1468,26 @@ int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph
|
|||
return 0;
|
||||
}
|
||||
|
||||
int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2)
|
||||
STBTT_DEF int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2)
|
||||
{
|
||||
if (!info->kern) // if no kerning table, don't waste time looking up both codepoint->glyphs
|
||||
return 0;
|
||||
return stbtt_GetGlyphKernAdvance(info, stbtt_FindGlyphIndex(info,ch1), stbtt_FindGlyphIndex(info,ch2));
|
||||
}
|
||||
|
||||
void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing)
|
||||
STBTT_DEF void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing)
|
||||
{
|
||||
stbtt_GetGlyphHMetrics(info, stbtt_FindGlyphIndex(info,codepoint), advanceWidth, leftSideBearing);
|
||||
}
|
||||
|
||||
void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap)
|
||||
STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap)
|
||||
{
|
||||
if (ascent ) *ascent = ttSHORT(info->data+info->hhea + 4);
|
||||
if (descent) *descent = ttSHORT(info->data+info->hhea + 6);
|
||||
if (lineGap) *lineGap = ttSHORT(info->data+info->hhea + 8);
|
||||
}
|
||||
|
||||
void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1)
|
||||
STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1)
|
||||
{
|
||||
*x0 = ttSHORT(info->data + info->head + 36);
|
||||
*y0 = ttSHORT(info->data + info->head + 38);
|
||||
|
@ -1476,19 +1495,19 @@ void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int
|
|||
*y1 = ttSHORT(info->data + info->head + 42);
|
||||
}
|
||||
|
||||
float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float height)
|
||||
STBTT_DEF float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float height)
|
||||
{
|
||||
int fheight = ttSHORT(info->data + info->hhea + 4) - ttSHORT(info->data + info->hhea + 6);
|
||||
return (float) height / fheight;
|
||||
}
|
||||
|
||||
float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels)
|
||||
STBTT_DEF float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels)
|
||||
{
|
||||
int unitsPerEm = ttUSHORT(info->data + info->head + 18);
|
||||
return pixels / unitsPerEm;
|
||||
}
|
||||
|
||||
void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v)
|
||||
STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v)
|
||||
{
|
||||
STBTT_free(v, info->userdata);
|
||||
}
|
||||
|
@ -1498,7 +1517,7 @@ void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v)
|
|||
// antialiasing software rasterizer
|
||||
//
|
||||
|
||||
void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y,float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1)
|
||||
STBTT_DEF void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y,float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1)
|
||||
{
|
||||
int x0,y0,x1,y1;
|
||||
if (!stbtt_GetGlyphBox(font, glyph, &x0,&y0,&x1,&y1)) {
|
||||
|
@ -1516,17 +1535,17 @@ void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, floa
|
|||
}
|
||||
}
|
||||
|
||||
void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1)
|
||||
STBTT_DEF void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1)
|
||||
{
|
||||
stbtt_GetGlyphBitmapBoxSubpixel(font, glyph, scale_x, scale_y,0.0f,0.0f, ix0, iy0, ix1, iy1);
|
||||
}
|
||||
|
||||
void stbtt_GetCodepointBitmapBoxSubpixel(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1)
|
||||
STBTT_DEF void stbtt_GetCodepointBitmapBoxSubpixel(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1)
|
||||
{
|
||||
stbtt_GetGlyphBitmapBoxSubpixel(font, stbtt_FindGlyphIndex(font,codepoint), scale_x, scale_y,shift_x,shift_y, ix0,iy0,ix1,iy1);
|
||||
}
|
||||
|
||||
void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1)
|
||||
STBTT_DEF void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1)
|
||||
{
|
||||
stbtt_GetCodepointBitmapBoxSubpixel(font, codepoint, scale_x, scale_y,0.0f,0.0f, ix0,iy0,ix1,iy1);
|
||||
}
|
||||
|
@ -1807,7 +1826,7 @@ static int stbtt__tesselate_curve(stbtt__point *points, int *num_points, float x
|
|||
}
|
||||
|
||||
// returns number of contours
|
||||
stbtt__point *stbtt_FlattenCurves(stbtt_vertex *vertices, int num_verts, float objspace_flatness, int **contour_lengths, int *num_contours, void *userdata)
|
||||
static stbtt__point *stbtt_FlattenCurves(stbtt_vertex *vertices, int num_verts, float objspace_flatness, int **contour_lengths, int *num_contours, void *userdata)
|
||||
{
|
||||
stbtt__point *points=0;
|
||||
int num_points=0;
|
||||
|
@ -1876,7 +1895,7 @@ error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata)
|
||||
STBTT_DEF void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata)
|
||||
{
|
||||
float scale = scale_x > scale_y ? scale_y : scale_x;
|
||||
int winding_count, *winding_lengths;
|
||||
|
@ -1888,12 +1907,12 @@ void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vert
|
|||
}
|
||||
}
|
||||
|
||||
void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata)
|
||||
STBTT_DEF void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata)
|
||||
{
|
||||
STBTT_free(bitmap, userdata);
|
||||
}
|
||||
|
||||
unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff)
|
||||
STBTT_DEF unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff)
|
||||
{
|
||||
int ix0,iy0,ix1,iy1;
|
||||
stbtt__bitmap gbm;
|
||||
|
@ -1930,12 +1949,12 @@ unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float sc
|
|||
return gbm.pixels;
|
||||
}
|
||||
|
||||
unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff)
|
||||
STBTT_DEF unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff)
|
||||
{
|
||||
return stbtt_GetGlyphBitmapSubpixel(info, scale_x, scale_y, 0.0f, 0.0f, glyph, width, height, xoff, yoff);
|
||||
}
|
||||
|
||||
void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph)
|
||||
STBTT_DEF void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph)
|
||||
{
|
||||
int ix0,iy0;
|
||||
stbtt_vertex *vertices;
|
||||
|
@ -1954,27 +1973,27 @@ void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *ou
|
|||
STBTT_free(vertices, info->userdata);
|
||||
}
|
||||
|
||||
void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph)
|
||||
STBTT_DEF void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph)
|
||||
{
|
||||
stbtt_MakeGlyphBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, 0.0f,0.0f, glyph);
|
||||
}
|
||||
|
||||
unsigned char *stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int *width, int *height, int *xoff, int *yoff)
|
||||
STBTT_DEF unsigned char *stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int *width, int *height, int *xoff, int *yoff)
|
||||
{
|
||||
return stbtt_GetGlyphBitmapSubpixel(info, scale_x, scale_y,shift_x,shift_y, stbtt_FindGlyphIndex(info,codepoint), width,height,xoff,yoff);
|
||||
}
|
||||
|
||||
void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint)
|
||||
STBTT_DEF void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint)
|
||||
{
|
||||
stbtt_MakeGlyphBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, stbtt_FindGlyphIndex(info,codepoint));
|
||||
}
|
||||
|
||||
unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff)
|
||||
STBTT_DEF unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff)
|
||||
{
|
||||
return stbtt_GetCodepointBitmapSubpixel(info, scale_x, scale_y, 0.0f,0.0f, codepoint, width,height,xoff,yoff);
|
||||
}
|
||||
|
||||
void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint)
|
||||
STBTT_DEF void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint)
|
||||
{
|
||||
stbtt_MakeCodepointBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, 0.0f,0.0f, codepoint);
|
||||
}
|
||||
|
@ -1985,7 +2004,7 @@ void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output
|
|||
//
|
||||
// This is SUPER-CRAPPY packing to keep source code small
|
||||
|
||||
extern int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)
|
||||
STBTT_DEF int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)
|
||||
float pixel_height, // height of font in pixels
|
||||
unsigned char *pixels, int pw, int ph, // bitmap to be filled in
|
||||
int first_char, int num_chars, // characters to bake
|
||||
|
@ -2030,13 +2049,13 @@ extern int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font
|
|||
return bottom_y;
|
||||
}
|
||||
|
||||
void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int opengl_fillrule)
|
||||
STBTT_DEF void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int opengl_fillrule)
|
||||
{
|
||||
float d3d_bias = opengl_fillrule ? 0 : -0.5f;
|
||||
float ipw = 1.0f / pw, iph = 1.0f / ph;
|
||||
stbtt_bakedchar *b = chardata + char_index;
|
||||
int round_x = STBTT_ifloor((*xpos + b->xoff) + 0.5);
|
||||
int round_y = STBTT_ifloor((*ypos + b->yoff) + 0.5);
|
||||
int round_x = STBTT_ifloor((*xpos + b->xoff) + 0.5f);
|
||||
int round_y = STBTT_ifloor((*ypos + b->yoff) + 0.5f);
|
||||
|
||||
q->x0 = round_x + d3d_bias;
|
||||
q->y0 = round_y + d3d_bias;
|
||||
|
@ -2133,7 +2152,7 @@ static void stbrp_pack_rects(stbrp_context *con, stbrp_rect *rects, int num_rect
|
|||
// This is SUPER-AWESOME (tm Ryan Gordon) packing using stb_rect_pack.h. If
|
||||
// stb_rect_pack.h isn't available, it uses the BakeFontBitmap strategy.
|
||||
|
||||
int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int pw, int ph, int stride_in_bytes, int padding, void *alloc_context)
|
||||
STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int pw, int ph, int stride_in_bytes, int padding, void *alloc_context)
|
||||
{
|
||||
stbrp_context *context = (stbrp_context *) STBTT_malloc(sizeof(*context) ,alloc_context);
|
||||
int num_nodes = pw - padding;
|
||||
|
@ -2163,13 +2182,13 @@ int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int pw, int
|
|||
return 1;
|
||||
}
|
||||
|
||||
void stbtt_PackEnd (stbtt_pack_context *spc)
|
||||
STBTT_DEF void stbtt_PackEnd (stbtt_pack_context *spc)
|
||||
{
|
||||
STBTT_free(spc->nodes , spc->user_allocator_context);
|
||||
STBTT_free(spc->pack_info, spc->user_allocator_context);
|
||||
}
|
||||
|
||||
void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample)
|
||||
STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample)
|
||||
{
|
||||
STBTT_assert(h_oversample <= STBTT_MAX_OVERSAMPLE);
|
||||
STBTT_assert(v_oversample <= STBTT_MAX_OVERSAMPLE);
|
||||
|
@ -2189,7 +2208,7 @@ static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_i
|
|||
for (j=0; j < h; ++j) {
|
||||
int i;
|
||||
unsigned int total;
|
||||
memset(buffer, 0, kernel_width);
|
||||
STBTT_memset(buffer, 0, kernel_width);
|
||||
|
||||
total = 0;
|
||||
|
||||
|
@ -2243,7 +2262,7 @@ static void stbtt__v_prefilter(unsigned char *pixels, int w, int h, int stride_i
|
|||
for (j=0; j < w; ++j) {
|
||||
int i;
|
||||
unsigned int total;
|
||||
memset(buffer, 0, kernel_width);
|
||||
STBTT_memset(buffer, 0, kernel_width);
|
||||
|
||||
total = 0;
|
||||
|
||||
|
@ -2301,7 +2320,7 @@ static float stbtt__oversample_shift(int oversample)
|
|||
return (float)-(oversample - 1) / (2.0f * (float)oversample);
|
||||
}
|
||||
|
||||
int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)
|
||||
STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)
|
||||
{
|
||||
stbtt_fontinfo info;
|
||||
float recip_h = 1.0f / spc->h_oversample;
|
||||
|
@ -2407,10 +2426,11 @@ int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int f
|
|||
}
|
||||
}
|
||||
|
||||
STBTT_free(rects, spc->user_allocator_context);
|
||||
return return_value;
|
||||
}
|
||||
|
||||
int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,
|
||||
STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,
|
||||
int first_unicode_char_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range)
|
||||
{
|
||||
stbtt_pack_range range;
|
||||
|
@ -2421,14 +2441,14 @@ int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int fo
|
|||
return stbtt_PackFontRanges(spc, fontdata, font_index, &range, 1);
|
||||
}
|
||||
|
||||
void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer)
|
||||
STBTT_DEF void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer)
|
||||
{
|
||||
float ipw = 1.0f / pw, iph = 1.0f / ph;
|
||||
stbtt_packedchar *b = chardata + char_index;
|
||||
|
||||
if (align_to_integer) {
|
||||
float x = (float) STBTT_ifloor((*xpos + b->xoff) + 0.5);
|
||||
float y = (float) STBTT_ifloor((*ypos + b->yoff) + 0.5);
|
||||
float x = (float) STBTT_ifloor((*xpos + b->xoff) + 0.5f);
|
||||
float y = (float) STBTT_ifloor((*ypos + b->yoff) + 0.5f);
|
||||
q->x0 = x;
|
||||
q->y0 = y;
|
||||
q->x1 = x + b->xoff2 - b->xoff;
|
||||
|
@ -2494,14 +2514,14 @@ static stbtt_int32 stbtt__CompareUTF8toUTF16_bigendian_prefix(const stbtt_uint8
|
|||
return i;
|
||||
}
|
||||
|
||||
int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2)
|
||||
STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2)
|
||||
{
|
||||
return len1 == stbtt__CompareUTF8toUTF16_bigendian_prefix((const stbtt_uint8*) s1, len1, (const stbtt_uint8*) s2, len2);
|
||||
}
|
||||
|
||||
// returns results in whatever encoding you request... but note that 2-byte encodings
|
||||
// will be BIG-ENDIAN... use stbtt_CompareUTF8toUTF16_bigendian() to compare
|
||||
const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID)
|
||||
STBTT_DEF const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID)
|
||||
{
|
||||
stbtt_int32 i,count,stringOffset;
|
||||
stbtt_uint8 *fc = font->data;
|
||||
|
@ -2598,7 +2618,7 @@ static int stbtt__matches(stbtt_uint8 *fc, stbtt_uint32 offset, stbtt_uint8 *nam
|
|||
return 0;
|
||||
}
|
||||
|
||||
int stbtt_FindMatchingFont(const unsigned char *font_collection, const char *name_utf8, stbtt_int32 flags)
|
||||
STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *font_collection, const char *name_utf8, stbtt_int32 flags)
|
||||
{
|
||||
stbtt_int32 i;
|
||||
for (i=0;;++i) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue