mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-24 00:26:36 +00:00
stb_truetype: implementation is now static + submitted PR to origin.
This commit is contained in:
parent
26174cba85
commit
f1ccd32cb1
@ -237,10 +237,12 @@
|
||||
- window: autofit feedback loop when user relies on any dynamic layout (window width multiplier, column). maybe just clearly drop manual autofit?
|
||||
- window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list.
|
||||
- window: allow resizing of child windows (possibly given min/max for each axis?)
|
||||
- window: background options for child windows, border option (disable ronuding)
|
||||
- window: resizing from any sides? + mouse cursor directives for app.
|
||||
- widgets: display mode: widget-label, label-widget (aligned on column or using fixed size), label-newline-tab-widget etc.
|
||||
- widgets: clip text? hover clipped text shows it in a tooltip or in-place overlay
|
||||
- main: considering adding EndFrame() - optional, else done in Render(). and Init()
|
||||
- main: add IsItemActive()
|
||||
- main: IsItemHovered() returns true even if mouse is active on another widget (e.g. dragging outside of sliders). Maybe not a sensible default? Add parameter or alternate function?
|
||||
- main: IsItemHovered() make it more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes
|
||||
- main: IsItemHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode?
|
||||
@ -260,6 +262,7 @@
|
||||
- combo: turn child handling code into pop up helper
|
||||
- list selection, concept of a selectable "block" (that can be multiple widgets)
|
||||
- menubar, menus
|
||||
- gauge: various forms of gauge/loading bars widgets
|
||||
- color: better color editor.
|
||||
- plot: make it easier for user to draw into the graph (e.g: draw basis, highlight certain points, 2d plots, multiple plots)
|
||||
- plot: "smooth" automatic scale, user give an input 0.0(full user scale) 1.0(full derived from value)
|
||||
@ -359,6 +362,7 @@ namespace IMGUI_STB_NAMESPACE
|
||||
#define STBTT_free(x,u) ((void)(u), ImGui::MemFree(x))
|
||||
#define STBTT_assert(x) IM_ASSERT(x)
|
||||
#ifndef IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
|
||||
#define STBTT_STATIC
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
#endif
|
||||
#include "stb_truetype.h"
|
||||
|
199
stb_truetype.h
199
stb_truetype.h
@ -379,6 +379,12 @@ int main(int arg, char **argv)
|
||||
typedef char stbtt__check_size32[sizeof(stbtt_int32)==4 ? 1 : -1];
|
||||
typedef char stbtt__check_size16[sizeof(stbtt_int16)==2 ? 1 : -1];
|
||||
|
||||
#ifdef STBTT_STATIC
|
||||
#define STBTT_DEF static
|
||||
#else
|
||||
#define STBTT_DEF extern
|
||||
#endif
|
||||
|
||||
// #define your own STBTT_sort() to override this to avoid qsort
|
||||
#ifndef STBTT_sort
|
||||
#include <stdlib.h>
|
||||
@ -448,7 +454,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
|
||||
@ -464,7 +470,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
|
||||
@ -497,8 +503,11 @@ typedef struct
|
||||
|
||||
typedef struct stbtt_pack_context stbtt_pack_context;
|
||||
typedef struct stbtt_fontinfo stbtt_fontinfo;
|
||||
#ifndef STB_RECT_PACK_VERSION
|
||||
typedef struct stbrp_rect stbrp_rect;
|
||||
#endif
|
||||
|
||||
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
|
||||
@ -509,12 +518,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
|
||||
@ -537,19 +546,19 @@ 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 int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects);
|
||||
extern int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects);
|
||||
STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects);
|
||||
STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects);
|
||||
// Those functions are called by stbtt_PackFontRanges(). If you want to
|
||||
// pack multiple fonts or custom data into a same texture, you may copy
|
||||
// the contents of stbtt_PackFontRanges() and create a custom version
|
||||
// using those functions.
|
||||
|
||||
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.
|
||||
//
|
||||
@ -561,7 +570,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
|
||||
@ -587,7 +596,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
|
||||
@ -611,7 +620,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
|
||||
@ -623,7 +632,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
|
||||
@ -635,7 +644,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
|
||||
@ -643,12 +652,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...
|
||||
@ -656,23 +665,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
|
||||
|
||||
|
||||
@ -700,11 +709,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
|
||||
//
|
||||
@ -715,7 +724,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
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
@ -723,10 +732,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).
|
||||
@ -735,39 +744,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
|
||||
@ -777,7 +786,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);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@ -801,7 +810,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
|
||||
@ -812,11 +821,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.
|
||||
//
|
||||
@ -915,10 +924,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
|
||||
|
||||
@ -949,7 +958,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))
|
||||
@ -968,7 +977,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;
|
||||
@ -1025,7 +1034,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;
|
||||
@ -1117,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);
|
||||
}
|
||||
@ -1149,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;
|
||||
@ -1161,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);
|
||||
@ -1191,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;
|
||||
@ -1417,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) {
|
||||
@ -1429,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;
|
||||
@ -1459,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);
|
||||
@ -1486,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);
|
||||
}
|
||||
@ -1508,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)) {
|
||||
@ -1526,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);
|
||||
}
|
||||
@ -1817,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;
|
||||
@ -1886,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;
|
||||
@ -1898,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;
|
||||
@ -1940,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;
|
||||
@ -1964,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);
|
||||
}
|
||||
@ -1995,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
|
||||
@ -2040,7 +2049,7 @@ 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;
|
||||
@ -2097,11 +2106,11 @@ typedef struct
|
||||
unsigned char x;
|
||||
} stbrp_node;
|
||||
|
||||
typedef struct
|
||||
struct stbrp_rect
|
||||
{
|
||||
stbrp_coord x,y;
|
||||
int id,w,h,was_packed;
|
||||
} stbrp_rect;
|
||||
};
|
||||
|
||||
static void stbrp_init_target(stbrp_context *con, int pw, int ph, stbrp_node *nodes, int num_nodes)
|
||||
{
|
||||
@ -2143,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;
|
||||
@ -2174,13 +2183,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);
|
||||
@ -2313,7 +2322,7 @@ static float stbtt__oversample_shift(int oversample)
|
||||
}
|
||||
|
||||
// rects array must be big enough to accommodate all characters in the given ranges
|
||||
int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
|
||||
STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
|
||||
{
|
||||
int i,j,k;
|
||||
|
||||
@ -2343,7 +2352,7 @@ int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, stbtt_fontinfo *inf
|
||||
}
|
||||
|
||||
// rects array must be big enough to accommodate all characters in the given ranges
|
||||
int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
|
||||
STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
|
||||
{
|
||||
float recip_h = 1.0f / spc->h_oversample;
|
||||
float recip_v = 1.0f / spc->v_oversample;
|
||||
@ -2413,7 +2422,7 @@ int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, stbtt_fontinfo
|
||||
return return_value;
|
||||
}
|
||||
|
||||
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;
|
||||
int i,j,n, return_value = 1;
|
||||
@ -2447,7 +2456,7 @@ int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int f
|
||||
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;
|
||||
@ -2458,7 +2467,7 @@ 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;
|
||||
@ -2531,14 +2540,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;
|
||||
@ -2635,7 +2644,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…
Reference in New Issue
Block a user