gosu 0.15.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/COPYING +1 -1
- data/dependencies/SDL/include/SDL.h +138 -0
- data/dependencies/SDL/include/SDL_assert.h +293 -0
- data/dependencies/SDL/include/SDL_atomic.h +295 -0
- data/dependencies/SDL/include/SDL_audio.h +859 -0
- data/dependencies/SDL/include/SDL_bits.h +121 -0
- data/dependencies/SDL/include/SDL_blendmode.h +123 -0
- data/dependencies/SDL/include/SDL_clipboard.h +71 -0
- data/dependencies/SDL/include/SDL_config.h +55 -0
- data/dependencies/SDL/include/SDL_config_android.h +182 -0
- data/dependencies/SDL/include/SDL_config_iphoneos.h +207 -0
- data/dependencies/SDL/include/SDL_config_macosx.h +266 -0
- data/dependencies/SDL/include/SDL_config_minimal.h +85 -0
- data/dependencies/SDL/include/SDL_config_os2.h +188 -0
- data/dependencies/SDL/include/SDL_config_pandora.h +135 -0
- data/dependencies/SDL/include/SDL_config_psp.h +165 -0
- data/dependencies/SDL/include/SDL_config_windows.h +288 -0
- data/dependencies/SDL/include/SDL_config_winrt.h +243 -0
- data/dependencies/SDL/include/SDL_config_wiz.h +149 -0
- data/dependencies/SDL/include/SDL_copying.h +20 -0
- data/dependencies/SDL/include/SDL_cpuinfo.h +299 -0
- data/dependencies/SDL/include/SDL_egl.h +1676 -0
- data/dependencies/SDL/include/SDL_endian.h +263 -0
- data/dependencies/SDL/include/SDL_error.h +112 -0
- data/dependencies/SDL/include/SDL_events.h +827 -0
- data/dependencies/SDL/include/SDL_filesystem.h +136 -0
- data/dependencies/SDL/include/SDL_gamecontroller.h +541 -0
- data/dependencies/SDL/include/SDL_gesture.h +87 -0
- data/dependencies/SDL/include/SDL_haptic.h +1247 -0
- data/dependencies/SDL/include/SDL_hints.h +1578 -0
- data/dependencies/SDL/include/SDL_joystick.h +499 -0
- data/dependencies/SDL/include/SDL_keyboard.h +217 -0
- data/dependencies/SDL/include/SDL_keycode.h +351 -0
- data/dependencies/SDL/include/SDL_loadso.h +81 -0
- data/dependencies/SDL/include/SDL_locale.h +101 -0
- data/dependencies/SDL/include/SDL_log.h +211 -0
- data/dependencies/SDL/include/SDL_main.h +180 -0
- data/dependencies/SDL/include/SDL_messagebox.h +146 -0
- data/dependencies/SDL/include/SDL_metal.h +117 -0
- data/dependencies/SDL/include/SDL_misc.h +75 -0
- data/dependencies/SDL/include/SDL_mouse.h +302 -0
- data/dependencies/SDL/include/SDL_mutex.h +251 -0
- data/dependencies/SDL/include/SDL_name.h +33 -0
- data/dependencies/SDL/include/SDL_opengl.h +2183 -0
- data/dependencies/SDL/include/SDL_opengl_glext.h +11180 -0
- data/dependencies/SDL/include/SDL_opengles.h +39 -0
- data/dependencies/SDL/include/SDL_opengles2.h +52 -0
- data/dependencies/SDL/include/SDL_opengles2_gl2.h +621 -0
- data/dependencies/SDL/include/SDL_opengles2_gl2ext.h +2050 -0
- data/dependencies/SDL/include/SDL_opengles2_gl2platform.h +30 -0
- data/dependencies/SDL/include/SDL_opengles2_khrplatform.h +282 -0
- data/dependencies/SDL/include/SDL_pixels.h +479 -0
- data/dependencies/SDL/include/SDL_platform.h +198 -0
- data/dependencies/SDL/include/SDL_power.h +75 -0
- data/dependencies/SDL/include/SDL_quit.h +58 -0
- data/dependencies/SDL/include/SDL_rect.h +174 -0
- data/dependencies/SDL/include/SDL_render.h +1158 -0
- data/dependencies/SDL/include/SDL_revision.h +2 -0
- data/dependencies/SDL/include/SDL_rwops.h +283 -0
- data/dependencies/SDL/include/SDL_scancode.h +413 -0
- data/dependencies/SDL/include/SDL_sensor.h +267 -0
- data/dependencies/SDL/include/SDL_shape.h +144 -0
- data/dependencies/SDL/include/SDL_stdinc.h +647 -0
- data/dependencies/SDL/include/SDL_surface.h +563 -0
- data/dependencies/SDL/include/SDL_system.h +325 -0
- data/dependencies/SDL/include/SDL_syswm.h +354 -0
- data/dependencies/SDL/include/SDL_test.h +69 -0
- data/dependencies/SDL/include/SDL_test_assert.h +105 -0
- data/dependencies/SDL/include/SDL_test_common.h +218 -0
- data/dependencies/SDL/include/SDL_test_compare.h +69 -0
- data/dependencies/SDL/include/SDL_test_crc32.h +124 -0
- data/dependencies/SDL/include/SDL_test_font.h +81 -0
- data/dependencies/SDL/include/SDL_test_fuzzer.h +384 -0
- data/dependencies/SDL/include/SDL_test_harness.h +134 -0
- data/dependencies/SDL/include/SDL_test_images.h +78 -0
- data/dependencies/SDL/include/SDL_test_log.h +67 -0
- data/dependencies/SDL/include/SDL_test_md5.h +129 -0
- data/dependencies/SDL/include/SDL_test_memory.h +63 -0
- data/dependencies/SDL/include/SDL_test_random.h +115 -0
- data/dependencies/SDL/include/SDL_thread.h +366 -0
- data/dependencies/SDL/include/SDL_timer.h +115 -0
- data/dependencies/SDL/include/SDL_touch.h +102 -0
- data/dependencies/SDL/include/SDL_types.h +29 -0
- data/dependencies/SDL/include/SDL_version.h +162 -0
- data/dependencies/SDL/include/SDL_video.h +1282 -0
- data/dependencies/SDL/include/SDL_vulkan.h +276 -0
- data/dependencies/SDL/include/begin_code.h +166 -0
- data/dependencies/SDL/include/close_code.h +40 -0
- data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
- data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
- data/dependencies/SDL_sound/SDL_sound.c +795 -0
- data/dependencies/SDL_sound/SDL_sound.h +725 -0
- data/dependencies/SDL_sound/SDL_sound_aiff.c +537 -0
- data/dependencies/SDL_sound/SDL_sound_au.c +352 -0
- data/dependencies/SDL_sound/SDL_sound_coreaudio.c +747 -0
- data/dependencies/SDL_sound/SDL_sound_flac.c +182 -0
- data/dependencies/SDL_sound/SDL_sound_internal.h +304 -0
- data/dependencies/SDL_sound/SDL_sound_modplug.c +228 -0
- data/dependencies/SDL_sound/SDL_sound_mp3.c +184 -0
- data/dependencies/SDL_sound/SDL_sound_raw.c +164 -0
- data/dependencies/SDL_sound/SDL_sound_shn.c +1309 -0
- data/dependencies/SDL_sound/SDL_sound_voc.c +550 -0
- data/dependencies/SDL_sound/SDL_sound_vorbis.c +223 -0
- data/dependencies/SDL_sound/SDL_sound_wav.c +783 -0
- data/dependencies/SDL_sound/dr_flac.h +5906 -0
- data/dependencies/SDL_sound/dr_mp3.h +2832 -0
- data/dependencies/SDL_sound/libmodplug/fastmix.c +1748 -0
- data/dependencies/SDL_sound/libmodplug/libmodplug.h +1001 -0
- data/dependencies/SDL_sound/libmodplug/load_669.c +188 -0
- data/dependencies/SDL_sound/libmodplug/load_abc.c +4725 -0
- data/dependencies/SDL_sound/libmodplug/load_amf.c +403 -0
- data/dependencies/SDL_sound/libmodplug/load_ams.c +587 -0
- data/dependencies/SDL_sound/libmodplug/load_dbm.c +357 -0
- data/dependencies/SDL_sound/libmodplug/load_dmf.c +531 -0
- data/dependencies/SDL_sound/libmodplug/load_dsm.c +232 -0
- data/dependencies/SDL_sound/libmodplug/load_far.c +253 -0
- data/dependencies/SDL_sound/libmodplug/load_it.c +796 -0
- data/dependencies/SDL_sound/libmodplug/load_mdl.c +488 -0
- data/dependencies/SDL_sound/libmodplug/load_med.c +757 -0
- data/dependencies/SDL_sound/libmodplug/load_mid.c +1405 -0
- data/dependencies/SDL_sound/libmodplug/load_mod.c +269 -0
- data/dependencies/SDL_sound/libmodplug/load_mt2.c +546 -0
- data/dependencies/SDL_sound/libmodplug/load_mtm.c +142 -0
- data/dependencies/SDL_sound/libmodplug/load_okt.c +192 -0
- data/dependencies/SDL_sound/libmodplug/load_pat.c +1143 -0
- data/dependencies/SDL_sound/libmodplug/load_pat.h +25 -0
- data/dependencies/SDL_sound/libmodplug/load_psm.c +350 -0
- data/dependencies/SDL_sound/libmodplug/load_ptm.c +204 -0
- data/dependencies/SDL_sound/libmodplug/load_s3m.c +325 -0
- data/dependencies/SDL_sound/libmodplug/load_stm.c +180 -0
- data/dependencies/SDL_sound/libmodplug/load_ult.c +206 -0
- data/dependencies/SDL_sound/libmodplug/load_umx.c +51 -0
- data/dependencies/SDL_sound/libmodplug/load_xm.c +554 -0
- data/dependencies/SDL_sound/libmodplug/mmcmp.c +382 -0
- data/dependencies/SDL_sound/libmodplug/modplug.c +170 -0
- data/dependencies/SDL_sound/libmodplug/modplug.h +90 -0
- data/dependencies/SDL_sound/libmodplug/snd_dsp.c +301 -0
- data/dependencies/SDL_sound/libmodplug/snd_flt.c +63 -0
- data/dependencies/SDL_sound/libmodplug/snd_fx.c +2350 -0
- data/dependencies/SDL_sound/libmodplug/sndfile.c +1169 -0
- data/dependencies/SDL_sound/libmodplug/sndmix.c +1034 -0
- data/dependencies/SDL_sound/libmodplug/tables.h +371 -0
- data/{src/stb_vorbis.c → dependencies/SDL_sound/stb_vorbis.h} +128 -23
- data/dependencies/al_soft/AL/al.h +655 -0
- data/dependencies/al_soft/AL/alc.h +270 -0
- data/dependencies/al_soft/AL/alext.h +585 -0
- data/dependencies/al_soft/AL/efx-creative.h +3 -0
- data/dependencies/al_soft/AL/efx-presets.h +402 -0
- data/dependencies/al_soft/AL/efx.h +762 -0
- data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
- data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
- data/{src → dependencies/stb}/stb_image.h +476 -176
- data/{src → dependencies/stb}/stb_image_write.h +253 -131
- data/{src → dependencies/stb}/stb_truetype.h +262 -104
- data/{src → dependencies/utf8proc}/utf8proc.c +47 -29
- data/{src → dependencies/utf8proc}/utf8proc.h +46 -24
- data/{src → dependencies/utf8proc}/utf8proc_data.h +10043 -9609
- data/ext/gosu/extconf.rb +53 -39
- data/{Gosu → include/Gosu}/Audio.hpp +6 -8
- data/include/Gosu/Bitmap.hpp +100 -0
- data/{Gosu → include/Gosu}/Buttons.hpp +104 -44
- data/include/Gosu/Channel.h +25 -0
- data/include/Gosu/Color.h +38 -0
- data/{Gosu → include/Gosu}/Color.hpp +0 -0
- data/{Gosu → include/Gosu}/Directories.hpp +0 -0
- data/include/Gosu/Font.h +36 -0
- data/{Gosu → include/Gosu}/Font.hpp +1 -1
- data/{Gosu → include/Gosu}/Fwd.hpp +0 -5
- data/include/Gosu/Gosu.h +82 -0
- data/{Gosu → include/Gosu}/Gosu.hpp +0 -0
- data/{Gosu → include/Gosu}/Graphics.hpp +0 -0
- data/{Gosu → include/Gosu}/GraphicsBase.hpp +0 -0
- data/{Gosu → include/Gosu}/IO.hpp +0 -0
- data/include/Gosu/Image.h +54 -0
- data/{Gosu → include/Gosu}/Image.hpp +7 -6
- data/{Gosu → include/Gosu}/ImageData.hpp +0 -0
- data/{Gosu → include/Gosu}/Input.hpp +39 -51
- data/{Gosu → include/Gosu}/Inspection.hpp +0 -0
- data/{Gosu → include/Gosu}/Math.hpp +0 -0
- data/{Gosu → include/Gosu}/Platform.hpp +0 -0
- data/include/Gosu/Sample.h +19 -0
- data/include/Gosu/Song.h +24 -0
- data/{Gosu → include/Gosu}/Text.hpp +0 -0
- data/include/Gosu/TextInput.h +30 -0
- data/{Gosu → include/Gosu}/TextInput.hpp +0 -0
- data/{Gosu → include/Gosu}/Timing.hpp +0 -0
- data/{Gosu → include/Gosu}/Utility.hpp +15 -4
- data/{Gosu → include/Gosu}/Version.hpp +2 -2
- data/include/Gosu/Window.h +63 -0
- data/{Gosu → include/Gosu}/Window.hpp +23 -25
- data/lib/OpenAL32.dll +0 -0
- data/lib/SDL2.dll +0 -0
- data/lib/gosu.rb +0 -3
- data/lib/gosu/patches.rb +0 -23
- data/lib/gosu/preview.rb +1 -3
- data/lib/gosu/swig_patches.rb +3 -2
- data/lib64/OpenAL32.dll +0 -0
- data/lib64/SDL2.dll +0 -0
- data/rdoc/gosu.rb +98 -22
- data/src/Audio.cpp +50 -224
- data/src/AudioFile.hpp +20 -37
- data/src/AudioFileAudioToolbox.cpp +237 -0
- data/src/AudioFileSDLSound.cpp +147 -0
- data/src/AudioImpl.cpp +3 -12
- data/src/AudioImpl.hpp +3 -1
- data/src/Bitmap.cpp +85 -83
- data/src/BitmapIO.cpp +52 -58
- data/src/ChannelWrapper.cpp +50 -0
- data/src/ColorWrapper.cpp +126 -0
- data/src/Constants.cpp +338 -0
- data/src/Font.cpp +4 -1
- data/src/FontWrapper.cpp +74 -0
- data/src/GosuWrapper.cpp +251 -0
- data/src/Graphics.cpp +7 -4
- data/src/Image.cpp +13 -16
- data/src/ImageWrapper.cpp +168 -0
- data/src/Input.cpp +412 -164
- data/src/LargeImageData.cpp +2 -1
- data/src/MarkupParser.cpp +2 -1
- data/src/RubyGosu.cxx +912 -172
- data/src/RubyGosu.h +4 -2
- data/src/SampleWrapper.cpp +30 -0
- data/src/SongWrapper.cpp +52 -0
- data/src/TexChunk.cpp +1 -1
- data/src/Text.cpp +1 -0
- data/src/TextBuilder.cpp +3 -1
- data/src/TextInputWrapper.cpp +101 -0
- data/src/Texture.cpp +1 -1
- data/src/TrueTypeFont.cpp +2 -1
- data/src/Utility.cpp +11 -7
- data/src/Window.cpp +30 -39
- data/src/WindowWrapper.cpp +317 -0
- metadata +212 -43
- data/Gosu/AutoLink.hpp +0 -14
- data/Gosu/Bitmap.hpp +0 -113
- data/lib/gosu/zen.rb +0 -89
- data/src/AudioToolboxFile.hpp +0 -210
- data/src/OggFile.hpp +0 -92
- data/src/SndFile.hpp +0 -174
- data/src/WinMain.cpp +0 -64
@@ -1,5 +1,14 @@
|
|
1
|
-
// stb_truetype.h - v1.
|
2
|
-
// authored from 2009-
|
1
|
+
// stb_truetype.h - v1.24 - public domain
|
2
|
+
// authored from 2009-2020 by Sean Barrett / RAD Game Tools
|
3
|
+
//
|
4
|
+
// =======================================================================
|
5
|
+
//
|
6
|
+
// NO SECURITY GUARANTEE -- DO NOT USE THIS ON UNTRUSTED FONT FILES
|
7
|
+
//
|
8
|
+
// This library does no range checking of the offsets found in the file,
|
9
|
+
// meaning an attacker can use it to read arbitrary memory.
|
10
|
+
//
|
11
|
+
// =======================================================================
|
3
12
|
//
|
4
13
|
// This library processes TrueType files:
|
5
14
|
// parse files
|
@@ -32,11 +41,11 @@
|
|
32
41
|
// Daniel Ribeiro Maciel
|
33
42
|
//
|
34
43
|
// Bug/warning reports/fixes:
|
35
|
-
// "Zer" on mollyrocket Fabian "ryg" Giesen
|
36
|
-
// Cass Everitt Martins Mozeiko
|
37
|
-
// stoiko (Haemimont Games) Cap Petschulat
|
38
|
-
// Brian Hook Omar Cornut
|
39
|
-
// Walter van Niftrik
|
44
|
+
// "Zer" on mollyrocket Fabian "ryg" Giesen github:NiLuJe
|
45
|
+
// Cass Everitt Martins Mozeiko github:aloucks
|
46
|
+
// stoiko (Haemimont Games) Cap Petschulat github:oyvindjam
|
47
|
+
// Brian Hook Omar Cornut github:vassvik
|
48
|
+
// Walter van Niftrik Ryan Griege
|
40
49
|
// David Gow Peter LaValle
|
41
50
|
// David Given Sergey Popov
|
42
51
|
// Ivan-Assen Ivanov Giumo X. Clanjor
|
@@ -44,11 +53,16 @@
|
|
44
53
|
// Johan Duparc Thomas Fields
|
45
54
|
// Hou Qiming Derek Vinyard
|
46
55
|
// Rob Loach Cort Stratton
|
47
|
-
// Kenney Phillis Jr.
|
48
|
-
//
|
49
|
-
//
|
56
|
+
// Kenney Phillis Jr. Brian Costabile
|
57
|
+
// Ken Voskuil (kaesve)
|
58
|
+
//
|
50
59
|
// VERSION HISTORY
|
51
60
|
//
|
61
|
+
// 1.24 (2020-02-05) fix warning
|
62
|
+
// 1.23 (2020-02-02) query SVG data for glyphs; query whole kerning table (but only kern not GPOS)
|
63
|
+
// 1.22 (2019-08-11) minimize missing-glyph duplication; fix kerning if both 'GPOS' and 'kern' are defined
|
64
|
+
// 1.21 (2019-02-25) fix warning
|
65
|
+
// 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics()
|
52
66
|
// 1.19 (2018-02-11) GPOS kerning, STBTT_fmod
|
53
67
|
// 1.18 (2018-01-29) add missing function
|
54
68
|
// 1.17 (2017-07-23) make more arguments const; doc fix
|
@@ -75,7 +89,7 @@
|
|
75
89
|
//
|
76
90
|
// USAGE
|
77
91
|
//
|
78
|
-
// Include this file in whatever places
|
92
|
+
// Include this file in whatever places need to refer to it. In ONE C/C++
|
79
93
|
// file, write:
|
80
94
|
// #define STB_TRUETYPE_IMPLEMENTATION
|
81
95
|
// before the #include of this file. This expands out the actual
|
@@ -206,7 +220,7 @@
|
|
206
220
|
//
|
207
221
|
// Advancing for the next character:
|
208
222
|
// Call GlyphHMetrics, and compute 'current_point += SF * advance'.
|
209
|
-
//
|
223
|
+
//
|
210
224
|
//
|
211
225
|
// ADVANCED USAGE
|
212
226
|
//
|
@@ -242,19 +256,6 @@
|
|
242
256
|
// recommend it.
|
243
257
|
//
|
244
258
|
//
|
245
|
-
// SOURCE STATISTICS (based on v0.6c, 2050 LOC)
|
246
|
-
//
|
247
|
-
// Documentation & header file 520 LOC \___ 660 LOC documentation
|
248
|
-
// Sample code 140 LOC /
|
249
|
-
// Truetype parsing 620 LOC ---- 620 LOC TrueType
|
250
|
-
// Software rasterization 240 LOC \ .
|
251
|
-
// Curve tesselation 120 LOC \__ 550 LOC Bitmap creation
|
252
|
-
// Bitmap management 100 LOC /
|
253
|
-
// Baked bitmap interface 70 LOC /
|
254
|
-
// Font name matching & access 150 LOC ---- 150
|
255
|
-
// C runtime library abstraction 60 LOC ---- 60
|
256
|
-
//
|
257
|
-
//
|
258
259
|
// PERFORMANCE MEASUREMENTS FOR 1.06:
|
259
260
|
//
|
260
261
|
// 32-bit 64-bit
|
@@ -344,7 +345,7 @@ int main(int argc, char **argv)
|
|
344
345
|
}
|
345
346
|
return 0;
|
346
347
|
}
|
347
|
-
#endif
|
348
|
+
#endif
|
348
349
|
//
|
349
350
|
// Output:
|
350
351
|
//
|
@@ -358,9 +359,9 @@ int main(int argc, char **argv)
|
|
358
359
|
// :@@. M@M
|
359
360
|
// @@@o@@@@
|
360
361
|
// :M@@V:@@.
|
361
|
-
//
|
362
|
+
//
|
362
363
|
//////////////////////////////////////////////////////////////////////////////
|
363
|
-
//
|
364
|
+
//
|
364
365
|
// Complete program: print "Hello World!" banner, with bugs
|
365
366
|
//
|
366
367
|
#if 0
|
@@ -556,6 +557,8 @@ STBTT_DEF void stbtt_GetBakedQuad(const stbtt_bakedchar *chardata, int pw, int p
|
|
556
557
|
//
|
557
558
|
// It's inefficient; you might want to c&p it and optimize it.
|
558
559
|
|
560
|
+
STBTT_DEF void stbtt_GetScaledFontVMetrics(const unsigned char *fontdata, int index, float size, float *ascent, float *descent, float *lineGap);
|
561
|
+
// Query the font vertical metrics without having to create a font first.
|
559
562
|
|
560
563
|
|
561
564
|
//////////////////////////////////////////////////////////////////////////////
|
@@ -641,6 +644,12 @@ STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h
|
|
641
644
|
// To use with PackFontRangesGather etc., you must set it before calls
|
642
645
|
// call to PackFontRangesGatherRects.
|
643
646
|
|
647
|
+
STBTT_DEF void stbtt_PackSetSkipMissingCodepoints(stbtt_pack_context *spc, int skip);
|
648
|
+
// If skip != 0, this tells stb_truetype to skip any codepoints for which
|
649
|
+
// there is no corresponding glyph. If skip=0, which is the default, then
|
650
|
+
// codepoints without a glyph recived the font's "missing character" glyph,
|
651
|
+
// typically an empty box by convention.
|
652
|
+
|
644
653
|
STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, // same data as above
|
645
654
|
int char_index, // character to display
|
646
655
|
float *xpos, float *ypos, // pointers to current position in screen pixel space
|
@@ -653,7 +662,7 @@ STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, cons
|
|
653
662
|
// Calling these functions in sequence is roughly equivalent to calling
|
654
663
|
// stbtt_PackFontRanges(). If you more control over the packing of multiple
|
655
664
|
// fonts, or if you want to pack custom data into a font texture, take a look
|
656
|
-
// at the source to of stbtt_PackFontRanges() and create a custom version
|
665
|
+
// at the source to of stbtt_PackFontRanges() and create a custom version
|
657
666
|
// using these functions, e.g. call GatherRects multiple times,
|
658
667
|
// building up a single array of rects, then call PackRects once,
|
659
668
|
// then call RenderIntoRects repeatedly. This may result in a
|
@@ -669,6 +678,7 @@ struct stbtt_pack_context {
|
|
669
678
|
int height;
|
670
679
|
int stride_in_bytes;
|
671
680
|
int padding;
|
681
|
+
int skip_missing;
|
672
682
|
unsigned int h_oversample, v_oversample;
|
673
683
|
unsigned char *pixels;
|
674
684
|
void *nodes;
|
@@ -694,7 +704,7 @@ STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index);
|
|
694
704
|
// file will only define one font and it always be at offset 0, so it will
|
695
705
|
// return '0' for index 0, and -1 for all other indices.
|
696
706
|
|
697
|
-
// The following structure is defined
|
707
|
+
// The following structure is defined publicly so you can declare one on
|
698
708
|
// the stack or as a global or etc, but you should treat it as opaque.
|
699
709
|
struct stbtt_fontinfo
|
700
710
|
{
|
@@ -704,7 +714,7 @@ struct stbtt_fontinfo
|
|
704
714
|
|
705
715
|
int numGlyphs; // number of glyphs, needed for range checking
|
706
716
|
|
707
|
-
int loca,head,glyf,hhea,hmtx,kern,gpos; // table locations as offset from start of .ttf
|
717
|
+
int loca,head,glyf,hhea,hmtx,kern,gpos,svg; // table locations as offset from start of .ttf
|
708
718
|
int index_map; // a cmap mapping for our chosen character encoding
|
709
719
|
int indexToLocFormat; // format needed to map from glyph index to glyph
|
710
720
|
|
@@ -733,6 +743,7 @@ STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codep
|
|
733
743
|
// and you want a speed-up, call this function with the character you're
|
734
744
|
// going to process, then use glyph-based functions instead of the
|
735
745
|
// codepoint-based functions.
|
746
|
+
// Returns 0 if the character codepoint is not defined in the font.
|
736
747
|
|
737
748
|
|
738
749
|
//////////////////////////////////////////////////////////////////////////////
|
@@ -786,6 +797,18 @@ STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1,
|
|
786
797
|
STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1);
|
787
798
|
// as above, but takes one or more glyph indices for greater efficiency
|
788
799
|
|
800
|
+
typedef struct stbtt_kerningentry
|
801
|
+
{
|
802
|
+
int glyph1; // use stbtt_FindGlyphIndex
|
803
|
+
int glyph2;
|
804
|
+
int advance;
|
805
|
+
} stbtt_kerningentry;
|
806
|
+
|
807
|
+
STBTT_DEF int stbtt_GetKerningTableLength(const stbtt_fontinfo *info);
|
808
|
+
STBTT_DEF int stbtt_GetKerningTable(const stbtt_fontinfo *info, stbtt_kerningentry* table, int table_length);
|
809
|
+
// Retrieves a complete list of all of the kerning pairs provided by the font
|
810
|
+
// stbtt_GetKerningTable never writes more than table_length entries and returns how many entries it did write.
|
811
|
+
// The table will be sorted by (a.glyph1 == b.glyph1)?(a.glyph2 < b.glyph2):(a.glyph1 < b.glyph1)
|
789
812
|
|
790
813
|
//////////////////////////////////////////////////////////////////////////////
|
791
814
|
//
|
@@ -820,7 +843,7 @@ STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, s
|
|
820
843
|
// returns # of vertices and fills *vertices with the pointer to them
|
821
844
|
// these are expressed in "unscaled" coordinates
|
822
845
|
//
|
823
|
-
// The shape is a series of
|
846
|
+
// The shape is a series of contours. Each one starts with
|
824
847
|
// a STBTT_moveto, then consists of a series of mixed
|
825
848
|
// STBTT_lineto and STBTT_curveto segments. A lineto
|
826
849
|
// draws a line from previous endpoint to its x,y; a curveto
|
@@ -830,6 +853,11 @@ STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, s
|
|
830
853
|
STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices);
|
831
854
|
// frees the data allocated above
|
832
855
|
|
856
|
+
STBTT_DEF int stbtt_GetCodepointSVG(const stbtt_fontinfo *info, int unicode_codepoint, const char **svg);
|
857
|
+
STBTT_DEF int stbtt_GetGlyphSVG(const stbtt_fontinfo *info, int gl, const char **svg);
|
858
|
+
// fills svg with the character's SVG data.
|
859
|
+
// returns data size or 0 if SVG not found.
|
860
|
+
|
833
861
|
//////////////////////////////////////////////////////////////////////////////
|
834
862
|
//
|
835
863
|
// BITMAP RENDERING
|
@@ -916,7 +944,7 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
|
|
916
944
|
STBTT_DEF unsigned char * stbtt_GetCodepointSDF(const stbtt_fontinfo *info, float scale, int codepoint, int padding, unsigned char onedge_value, float pixel_dist_scale, int *width, int *height, int *xoff, int *yoff);
|
917
945
|
// These functions compute a discretized SDF field for a single character, suitable for storing
|
918
946
|
// in a single-channel texture, sampling with bilinear filtering, and testing against
|
919
|
-
// larger than some
|
947
|
+
// larger than some threshold to produce scalable fonts.
|
920
948
|
// info -- the font
|
921
949
|
// scale -- controls the size of the resulting SDF bitmap, same as it would be creating a regular bitmap
|
922
950
|
// glyph/codepoint -- the character to generate the SDF for
|
@@ -959,7 +987,7 @@ STBTT_DEF unsigned char * stbtt_GetCodepointSDF(const stbtt_fontinfo *info, floa
|
|
959
987
|
// and computing from that can allow drop-out prevention).
|
960
988
|
//
|
961
989
|
// The algorithm has not been optimized at all, so expect it to be slow
|
962
|
-
// if computing lots of characters or very large sizes.
|
990
|
+
// if computing lots of characters or very large sizes.
|
963
991
|
|
964
992
|
|
965
993
|
|
@@ -1331,6 +1359,22 @@ static stbtt__buf stbtt__get_subrs(stbtt__buf cff, stbtt__buf fontdict)
|
|
1331
1359
|
return stbtt__cff_get_index(&cff);
|
1332
1360
|
}
|
1333
1361
|
|
1362
|
+
// since most people won't use this, find this table the first time it's needed
|
1363
|
+
static int stbtt__get_svg(stbtt_fontinfo *info)
|
1364
|
+
{
|
1365
|
+
stbtt_uint32 t;
|
1366
|
+
if (info->svg < 0) {
|
1367
|
+
t = stbtt__find_table(info->data, info->fontstart, "SVG ");
|
1368
|
+
if (t) {
|
1369
|
+
stbtt_uint32 offset = ttULONG(info->data + t + 2);
|
1370
|
+
info->svg = t + offset;
|
1371
|
+
} else {
|
1372
|
+
info->svg = 0;
|
1373
|
+
}
|
1374
|
+
}
|
1375
|
+
return info->svg;
|
1376
|
+
}
|
1377
|
+
|
1334
1378
|
static int stbtt_InitFont_internal(stbtt_fontinfo *info, unsigned char *data, int fontstart)
|
1335
1379
|
{
|
1336
1380
|
stbtt_uint32 cmap, t;
|
@@ -1410,6 +1454,8 @@ static int stbtt_InitFont_internal(stbtt_fontinfo *info, unsigned char *data, in
|
|
1410
1454
|
else
|
1411
1455
|
info->numGlyphs = 0xffff;
|
1412
1456
|
|
1457
|
+
info->svg = -1;
|
1458
|
+
|
1413
1459
|
// find a cmap encoding table we understand *now* to avoid searching
|
1414
1460
|
// later. (todo: could make this installable)
|
1415
1461
|
// the same regardless of glyph.
|
@@ -1716,7 +1762,7 @@ static int stbtt__GetGlyphShapeTT(const stbtt_fontinfo *info, int glyph_index, s
|
|
1716
1762
|
if (i != 0)
|
1717
1763
|
num_vertices = stbtt__close_shape(vertices, num_vertices, was_off, start_off, sx,sy,scx,scy,cx,cy);
|
1718
1764
|
|
1719
|
-
// now start the new one
|
1765
|
+
// now start the new one
|
1720
1766
|
start_off = !(flags & 1);
|
1721
1767
|
if (start_off) {
|
1722
1768
|
// if we start off with an off-curve point, then when we need to find a point on the curve
|
@@ -1758,7 +1804,7 @@ static int stbtt__GetGlyphShapeTT(const stbtt_fontinfo *info, int glyph_index, s
|
|
1758
1804
|
}
|
1759
1805
|
}
|
1760
1806
|
num_vertices = stbtt__close_shape(vertices, num_vertices, was_off, start_off, sx,sy,scx,scy,cx,cy);
|
1761
|
-
} else if (numberOfContours
|
1807
|
+
} else if (numberOfContours < 0) {
|
1762
1808
|
// Compound shapes.
|
1763
1809
|
int more = 1;
|
1764
1810
|
stbtt_uint8 *comp = data + g + 10;
|
@@ -1769,7 +1815,7 @@ static int stbtt__GetGlyphShapeTT(const stbtt_fontinfo *info, int glyph_index, s
|
|
1769
1815
|
int comp_num_verts = 0, i;
|
1770
1816
|
stbtt_vertex *comp_verts = 0, *tmp = 0;
|
1771
1817
|
float mtx[6] = {1,0,0,1,0,0}, m, n;
|
1772
|
-
|
1818
|
+
|
1773
1819
|
flags = ttSHORT(comp); comp+=2;
|
1774
1820
|
gidx = ttSHORT(comp); comp+=2;
|
1775
1821
|
|
@@ -1799,7 +1845,7 @@ static int stbtt__GetGlyphShapeTT(const stbtt_fontinfo *info, int glyph_index, s
|
|
1799
1845
|
mtx[2] = ttSHORT(comp)/16384.0f; comp+=2;
|
1800
1846
|
mtx[3] = ttSHORT(comp)/16384.0f; comp+=2;
|
1801
1847
|
}
|
1802
|
-
|
1848
|
+
|
1803
1849
|
// Find transformation scales.
|
1804
1850
|
m = (float) STBTT_sqrt(mtx[0]*mtx[0] + mtx[1]*mtx[1]);
|
1805
1851
|
n = (float) STBTT_sqrt(mtx[2]*mtx[2] + mtx[3]*mtx[3]);
|
@@ -1835,9 +1881,6 @@ static int stbtt__GetGlyphShapeTT(const stbtt_fontinfo *info, int glyph_index, s
|
|
1835
1881
|
// More components ?
|
1836
1882
|
more = flags & (1<<5);
|
1837
1883
|
}
|
1838
|
-
} else if (numberOfContours < 0) {
|
1839
|
-
// @TODO other compound variations?
|
1840
|
-
STBTT_assert(0);
|
1841
1884
|
} else {
|
1842
1885
|
// numberOfCounters == 0, do nothing
|
1843
1886
|
}
|
@@ -2266,6 +2309,48 @@ STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_inde
|
|
2266
2309
|
}
|
2267
2310
|
}
|
2268
2311
|
|
2312
|
+
STBTT_DEF int stbtt_GetKerningTableLength(const stbtt_fontinfo *info)
|
2313
|
+
{
|
2314
|
+
stbtt_uint8 *data = info->data + info->kern;
|
2315
|
+
|
2316
|
+
// we only look at the first table. it must be 'horizontal' and format 0.
|
2317
|
+
if (!info->kern)
|
2318
|
+
return 0;
|
2319
|
+
if (ttUSHORT(data+2) < 1) // number of tables, need at least 1
|
2320
|
+
return 0;
|
2321
|
+
if (ttUSHORT(data+8) != 1) // horizontal flag must be set in format
|
2322
|
+
return 0;
|
2323
|
+
|
2324
|
+
return ttUSHORT(data+10);
|
2325
|
+
}
|
2326
|
+
|
2327
|
+
STBTT_DEF int stbtt_GetKerningTable(const stbtt_fontinfo *info, stbtt_kerningentry* table, int table_length)
|
2328
|
+
{
|
2329
|
+
stbtt_uint8 *data = info->data + info->kern;
|
2330
|
+
int k, length;
|
2331
|
+
|
2332
|
+
// we only look at the first table. it must be 'horizontal' and format 0.
|
2333
|
+
if (!info->kern)
|
2334
|
+
return 0;
|
2335
|
+
if (ttUSHORT(data+2) < 1) // number of tables, need at least 1
|
2336
|
+
return 0;
|
2337
|
+
if (ttUSHORT(data+8) != 1) // horizontal flag must be set in format
|
2338
|
+
return 0;
|
2339
|
+
|
2340
|
+
length = ttUSHORT(data+10);
|
2341
|
+
if (table_length < length)
|
2342
|
+
length = table_length;
|
2343
|
+
|
2344
|
+
for (k = 0; k < length; k++)
|
2345
|
+
{
|
2346
|
+
table[k].glyph1 = ttUSHORT(data+18+(k*6));
|
2347
|
+
table[k].glyph2 = ttUSHORT(data+20+(k*6));
|
2348
|
+
table[k].advance = ttSHORT(data+22+(k*6));
|
2349
|
+
}
|
2350
|
+
|
2351
|
+
return length;
|
2352
|
+
}
|
2353
|
+
|
2269
2354
|
static int stbtt__GetGlyphKernInfoAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2)
|
2270
2355
|
{
|
2271
2356
|
stbtt_uint8 *data = info->data + info->kern;
|
@@ -2463,6 +2548,7 @@ static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, i
|
|
2463
2548
|
if (valueFormat2 != 0) return 0;
|
2464
2549
|
|
2465
2550
|
STBTT_assert(coverageIndex < pairSetCount);
|
2551
|
+
STBTT__NOTUSED(pairSetCount);
|
2466
2552
|
|
2467
2553
|
needle=glyph2;
|
2468
2554
|
r=pairValueCount-1;
|
@@ -2540,8 +2626,7 @@ STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int g1, int
|
|
2540
2626
|
|
2541
2627
|
if (info->gpos)
|
2542
2628
|
xAdvance += stbtt__GetGlyphGPOSInfoAdvance(info, g1, g2);
|
2543
|
-
|
2544
|
-
if (info->kern)
|
2629
|
+
else if (info->kern)
|
2545
2630
|
xAdvance += stbtt__GetGlyphKernInfoAdvance(info, g1, g2);
|
2546
2631
|
|
2547
2632
|
return xAdvance;
|
@@ -2602,6 +2687,45 @@ STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v)
|
|
2602
2687
|
STBTT_free(v, info->userdata);
|
2603
2688
|
}
|
2604
2689
|
|
2690
|
+
STBTT_DEF stbtt_uint8 *stbtt_FindSVGDoc(const stbtt_fontinfo *info, int gl)
|
2691
|
+
{
|
2692
|
+
int i;
|
2693
|
+
stbtt_uint8 *data = info->data;
|
2694
|
+
stbtt_uint8 *svg_doc_list = data + stbtt__get_svg((stbtt_fontinfo *) info);
|
2695
|
+
|
2696
|
+
int numEntries = ttUSHORT(svg_doc_list);
|
2697
|
+
stbtt_uint8 *svg_docs = svg_doc_list + 2;
|
2698
|
+
|
2699
|
+
for(i=0; i<numEntries; i++) {
|
2700
|
+
stbtt_uint8 *svg_doc = svg_docs + (12 * i);
|
2701
|
+
if ((gl >= ttUSHORT(svg_doc)) && (gl <= ttUSHORT(svg_doc + 2)))
|
2702
|
+
return svg_doc;
|
2703
|
+
}
|
2704
|
+
return 0;
|
2705
|
+
}
|
2706
|
+
|
2707
|
+
STBTT_DEF int stbtt_GetGlyphSVG(const stbtt_fontinfo *info, int gl, const char **svg)
|
2708
|
+
{
|
2709
|
+
stbtt_uint8 *data = info->data;
|
2710
|
+
stbtt_uint8 *svg_doc;
|
2711
|
+
|
2712
|
+
if (info->svg == 0)
|
2713
|
+
return 0;
|
2714
|
+
|
2715
|
+
svg_doc = stbtt_FindSVGDoc(info, gl);
|
2716
|
+
if (svg_doc != NULL) {
|
2717
|
+
*svg = (char *) data + info->svg + ttULONG(svg_doc + 4);
|
2718
|
+
return ttULONG(svg_doc + 8);
|
2719
|
+
} else {
|
2720
|
+
return 0;
|
2721
|
+
}
|
2722
|
+
}
|
2723
|
+
|
2724
|
+
STBTT_DEF int stbtt_GetCodepointSVG(const stbtt_fontinfo *info, int unicode_codepoint, const char **svg)
|
2725
|
+
{
|
2726
|
+
return stbtt_GetGlyphSVG(info, stbtt_FindGlyphIndex(info, unicode_codepoint), svg);
|
2727
|
+
}
|
2728
|
+
|
2605
2729
|
//////////////////////////////////////////////////////////////////////////////
|
2606
2730
|
//
|
2607
2731
|
// antialiasing software rasterizer
|
@@ -2727,7 +2851,7 @@ static stbtt__active_edge *stbtt__new_active(stbtt__hheap *hh, stbtt__edge *e, i
|
|
2727
2851
|
float dxdy = (e->x1 - e->x0) / (e->y1 - e->y0);
|
2728
2852
|
STBTT_assert(z != NULL);
|
2729
2853
|
if (!z) return z;
|
2730
|
-
|
2854
|
+
|
2731
2855
|
// round dx down to avoid overshooting
|
2732
2856
|
if (dxdy < 0)
|
2733
2857
|
z->dx = -STBTT_ifloor(STBTT_FIX * -dxdy);
|
@@ -2805,7 +2929,7 @@ static void stbtt__fill_active_edges(unsigned char *scanline, int len, stbtt__ac
|
|
2805
2929
|
}
|
2806
2930
|
}
|
2807
2931
|
}
|
2808
|
-
|
2932
|
+
|
2809
2933
|
e = e->next;
|
2810
2934
|
}
|
2811
2935
|
}
|
@@ -3160,7 +3284,13 @@ static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e,
|
|
3160
3284
|
if (e->y0 != e->y1) {
|
3161
3285
|
stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y_top, userdata);
|
3162
3286
|
if (z != NULL) {
|
3163
|
-
|
3287
|
+
if (j == 0 && off_y != 0) {
|
3288
|
+
if (z->ey < scan_y_top) {
|
3289
|
+
// this can happen due to subpixel positioning and some kind of fp rounding error i think
|
3290
|
+
z->ey = scan_y_top;
|
3291
|
+
}
|
3292
|
+
}
|
3293
|
+
STBTT_assert(z->ey >= scan_y_top); // if we get really unlucky a tiny bit of an edge can be out of bounds
|
3164
3294
|
// insert at front
|
3165
3295
|
z->next = active;
|
3166
3296
|
active = z;
|
@@ -3229,7 +3359,7 @@ static void stbtt__sort_edges_ins_sort(stbtt__edge *p, int n)
|
|
3229
3359
|
|
3230
3360
|
static void stbtt__sort_edges_quicksort(stbtt__edge *p, int n)
|
3231
3361
|
{
|
3232
|
-
/*
|
3362
|
+
/* threshold for transitioning to insertion sort */
|
3233
3363
|
while (n > 12) {
|
3234
3364
|
stbtt__edge t;
|
3235
3365
|
int c01,c12,c,m,i,j;
|
@@ -3364,7 +3494,7 @@ static void stbtt__add_point(stbtt__point *points, int n, float x, float y)
|
|
3364
3494
|
points[n].y = y;
|
3365
3495
|
}
|
3366
3496
|
|
3367
|
-
//
|
3497
|
+
// tessellate until threshold p is happy... @TODO warped to compensate for non-linear stretching
|
3368
3498
|
static int stbtt__tesselate_curve(stbtt__point *points, int *num_points, float x0, float y0, float x1, float y1, float x2, float y2, float objspace_flatness_squared, int n)
|
3369
3499
|
{
|
3370
3500
|
// midpoint
|
@@ -3527,7 +3657,7 @@ STBTT_DEF unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info
|
|
3527
3657
|
{
|
3528
3658
|
int ix0,iy0,ix1,iy1;
|
3529
3659
|
stbtt__bitmap gbm;
|
3530
|
-
stbtt_vertex *vertices;
|
3660
|
+
stbtt_vertex *vertices;
|
3531
3661
|
int num_verts = stbtt_GetGlyphShape(info, glyph, &vertices);
|
3532
3662
|
|
3533
3663
|
if (scale_x == 0) scale_x = scale_y;
|
@@ -3550,7 +3680,7 @@ STBTT_DEF unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info
|
|
3550
3680
|
if (height) *height = gbm.h;
|
3551
3681
|
if (xoff ) *xoff = ix0;
|
3552
3682
|
if (yoff ) *yoff = iy0;
|
3553
|
-
|
3683
|
+
|
3554
3684
|
if (gbm.w && gbm.h) {
|
3555
3685
|
gbm.pixels = (unsigned char *) STBTT_malloc(gbm.w * gbm.h, info->userdata);
|
3556
3686
|
if (gbm.pixels) {
|
@@ -3561,7 +3691,7 @@ STBTT_DEF unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info
|
|
3561
3691
|
}
|
3562
3692
|
STBTT_free(vertices, info->userdata);
|
3563
3693
|
return gbm.pixels;
|
3564
|
-
}
|
3694
|
+
}
|
3565
3695
|
|
3566
3696
|
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)
|
3567
3697
|
{
|
@@ -3573,7 +3703,7 @@ STBTT_DEF void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigne
|
|
3573
3703
|
int ix0,iy0;
|
3574
3704
|
stbtt_vertex *vertices;
|
3575
3705
|
int num_verts = stbtt_GetGlyphShape(info, glyph, &vertices);
|
3576
|
-
stbtt__bitmap gbm;
|
3706
|
+
stbtt__bitmap gbm;
|
3577
3707
|
|
3578
3708
|
stbtt_GetGlyphBitmapBoxSubpixel(info, glyph, scale_x, scale_y, shift_x, shift_y, &ix0,&iy0,0,0);
|
3579
3709
|
gbm.pixels = output;
|
@@ -3595,7 +3725,7 @@ STBTT_DEF void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *
|
|
3595
3725
|
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)
|
3596
3726
|
{
|
3597
3727
|
return stbtt_GetGlyphBitmapSubpixel(info, scale_x, scale_y,shift_x,shift_y, stbtt_FindGlyphIndex(info,codepoint), width,height,xoff,yoff);
|
3598
|
-
}
|
3728
|
+
}
|
3599
3729
|
|
3600
3730
|
STBTT_DEF void stbtt_MakeCodepointBitmapSubpixelPrefilter(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 oversample_x, int oversample_y, float *sub_x, float *sub_y, int codepoint)
|
3601
3731
|
{
|
@@ -3610,7 +3740,7 @@ STBTT_DEF void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, uns
|
|
3610
3740
|
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)
|
3611
3741
|
{
|
3612
3742
|
return stbtt_GetCodepointBitmapSubpixel(info, scale_x, scale_y, 0.0f,0.0f, codepoint, width,height,xoff,yoff);
|
3613
|
-
}
|
3743
|
+
}
|
3614
3744
|
|
3615
3745
|
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)
|
3616
3746
|
{
|
@@ -3735,7 +3865,7 @@ static void stbrp_init_target(stbrp_context *con, int pw, int ph, stbrp_node *no
|
|
3735
3865
|
con->y = 0;
|
3736
3866
|
con->bottom_y = 0;
|
3737
3867
|
STBTT__NOTUSED(nodes);
|
3738
|
-
STBTT__NOTUSED(num_nodes);
|
3868
|
+
STBTT__NOTUSED(num_nodes);
|
3739
3869
|
}
|
3740
3870
|
|
3741
3871
|
static void stbrp_pack_rects(stbrp_context *con, stbrp_rect *rects, int num_rects)
|
@@ -3789,6 +3919,7 @@ STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, in
|
|
3789
3919
|
spc->stride_in_bytes = stride_in_bytes != 0 ? stride_in_bytes : pw;
|
3790
3920
|
spc->h_oversample = 1;
|
3791
3921
|
spc->v_oversample = 1;
|
3922
|
+
spc->skip_missing = 0;
|
3792
3923
|
|
3793
3924
|
stbrp_init_target(context, pw-padding, ph-padding, nodes, num_nodes);
|
3794
3925
|
|
@@ -3814,6 +3945,11 @@ STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h
|
|
3814
3945
|
spc->v_oversample = v_oversample;
|
3815
3946
|
}
|
3816
3947
|
|
3948
|
+
STBTT_DEF void stbtt_PackSetSkipMissingCodepoints(stbtt_pack_context *spc, int skip)
|
3949
|
+
{
|
3950
|
+
spc->skip_missing = skip;
|
3951
|
+
}
|
3952
|
+
|
3817
3953
|
#define STBTT__OVER_MASK (STBTT_MAX_OVERSAMPLE-1)
|
3818
3954
|
|
3819
3955
|
static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_in_bytes, unsigned int kernel_width)
|
@@ -3956,6 +4092,7 @@ static float stbtt__oversample_shift(int oversample)
|
|
3956
4092
|
STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
|
3957
4093
|
{
|
3958
4094
|
int i,j,k;
|
4095
|
+
int missing_glyph_added = 0;
|
3959
4096
|
|
3960
4097
|
k=0;
|
3961
4098
|
for (i=0; i < num_ranges; ++i) {
|
@@ -3967,13 +4104,19 @@ STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stb
|
|
3967
4104
|
int x0,y0,x1,y1;
|
3968
4105
|
int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];
|
3969
4106
|
int glyph = stbtt_FindGlyphIndex(info, codepoint);
|
3970
|
-
|
3971
|
-
|
3972
|
-
|
3973
|
-
|
3974
|
-
|
3975
|
-
|
3976
|
-
|
4107
|
+
if (glyph == 0 && (spc->skip_missing || missing_glyph_added)) {
|
4108
|
+
rects[k].w = rects[k].h = 0;
|
4109
|
+
} else {
|
4110
|
+
stbtt_GetGlyphBitmapBoxSubpixel(info,glyph,
|
4111
|
+
scale * spc->h_oversample,
|
4112
|
+
scale * spc->v_oversample,
|
4113
|
+
0,0,
|
4114
|
+
&x0,&y0,&x1,&y1);
|
4115
|
+
rects[k].w = (stbrp_coord) (x1-x0 + spc->padding + spc->h_oversample-1);
|
4116
|
+
rects[k].h = (stbrp_coord) (y1-y0 + spc->padding + spc->v_oversample-1);
|
4117
|
+
if (glyph == 0)
|
4118
|
+
missing_glyph_added = 1;
|
4119
|
+
}
|
3977
4120
|
++k;
|
3978
4121
|
}
|
3979
4122
|
}
|
@@ -4007,7 +4150,7 @@ STBTT_DEF void stbtt_MakeGlyphBitmapSubpixelPrefilter(const stbtt_fontinfo *info
|
|
4007
4150
|
// rects array must be big enough to accommodate all characters in the given ranges
|
4008
4151
|
STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
|
4009
4152
|
{
|
4010
|
-
int i,j,k, return_value = 1;
|
4153
|
+
int i,j,k, missing_glyph = -1, return_value = 1;
|
4011
4154
|
|
4012
4155
|
// save current values
|
4013
4156
|
int old_h_over = spc->h_oversample;
|
@@ -4026,7 +4169,7 @@ STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const
|
|
4026
4169
|
sub_y = stbtt__oversample_shift(spc->v_oversample);
|
4027
4170
|
for (j=0; j < ranges[i].num_chars; ++j) {
|
4028
4171
|
stbrp_rect *r = &rects[k];
|
4029
|
-
if (r->was_packed) {
|
4172
|
+
if (r->was_packed && r->w != 0 && r->h != 0) {
|
4030
4173
|
stbtt_packedchar *bc = &ranges[i].chardata_for_range[j];
|
4031
4174
|
int advance, lsb, x0,y0,x1,y1;
|
4032
4175
|
int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];
|
@@ -4072,6 +4215,13 @@ STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const
|
|
4072
4215
|
bc->yoff = (float) y0 * recip_v + sub_y;
|
4073
4216
|
bc->xoff2 = (x0 + r->w) * recip_h + sub_x;
|
4074
4217
|
bc->yoff2 = (y0 + r->h) * recip_v + sub_y;
|
4218
|
+
|
4219
|
+
if (glyph == 0)
|
4220
|
+
missing_glyph = j;
|
4221
|
+
} else if (spc->skip_missing) {
|
4222
|
+
return_value = 0;
|
4223
|
+
} else if (r->was_packed && r->w == 0 && r->h == 0 && missing_glyph >= 0) {
|
4224
|
+
ranges[i].chardata_for_range[j] = ranges[i].chardata_for_range[missing_glyph];
|
4075
4225
|
} else {
|
4076
4226
|
return_value = 0; // if any fail, report failure
|
4077
4227
|
}
|
@@ -4110,7 +4260,7 @@ STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, const unsigned char
|
|
4110
4260
|
n = 0;
|
4111
4261
|
for (i=0; i < num_ranges; ++i)
|
4112
4262
|
n += ranges[i].num_chars;
|
4113
|
-
|
4263
|
+
|
4114
4264
|
rects = (stbrp_rect *) STBTT_malloc(sizeof(*rects) * n, spc->user_allocator_context);
|
4115
4265
|
if (rects == NULL)
|
4116
4266
|
return 0;
|
@@ -4121,7 +4271,7 @@ STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, const unsigned char
|
|
4121
4271
|
n = stbtt_PackFontRangesGatherRects(spc, &info, ranges, num_ranges, rects);
|
4122
4272
|
|
4123
4273
|
stbtt_PackFontRangesPackRects(spc, rects, n);
|
4124
|
-
|
4274
|
+
|
4125
4275
|
return_value = stbtt_PackFontRangesRenderIntoRects(spc, &info, ranges, num_ranges, rects);
|
4126
4276
|
|
4127
4277
|
STBTT_free(rects, spc->user_allocator_context);
|
@@ -4140,6 +4290,19 @@ STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, const unsigned char *
|
|
4140
4290
|
return stbtt_PackFontRanges(spc, fontdata, font_index, &range, 1);
|
4141
4291
|
}
|
4142
4292
|
|
4293
|
+
STBTT_DEF void stbtt_GetScaledFontVMetrics(const unsigned char *fontdata, int index, float size, float *ascent, float *descent, float *lineGap)
|
4294
|
+
{
|
4295
|
+
int i_ascent, i_descent, i_lineGap;
|
4296
|
+
float scale;
|
4297
|
+
stbtt_fontinfo info;
|
4298
|
+
stbtt_InitFont(&info, fontdata, stbtt_GetFontOffsetForIndex(fontdata, index));
|
4299
|
+
scale = size > 0 ? stbtt_ScaleForPixelHeight(&info, size) : stbtt_ScaleForMappingEmToPixels(&info, -size);
|
4300
|
+
stbtt_GetFontVMetrics(&info, &i_ascent, &i_descent, &i_lineGap);
|
4301
|
+
*ascent = (float) i_ascent * scale;
|
4302
|
+
*descent = (float) i_descent * scale;
|
4303
|
+
*lineGap = (float) i_lineGap * scale;
|
4304
|
+
}
|
4305
|
+
|
4143
4306
|
STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer)
|
4144
4307
|
{
|
4145
4308
|
float ipw = 1.0f / pw, iph = 1.0f / ph;
|
@@ -4269,7 +4432,7 @@ static int stbtt__compute_crossings_x(float x, float y, int nverts, stbtt_vertex
|
|
4269
4432
|
int x1 = (int) verts[i ].x, y1 = (int) verts[i ].y;
|
4270
4433
|
if (y > STBTT_min(y0,y1) && y < STBTT_max(y0,y1) && x > STBTT_min(x0,x1)) {
|
4271
4434
|
float x_inter = (y - y0) / (y1 - y0) * (x1-x0) + x0;
|
4272
|
-
if (x_inter < x)
|
4435
|
+
if (x_inter < x)
|
4273
4436
|
winding += (y0 < y1) ? 1 : -1;
|
4274
4437
|
}
|
4275
4438
|
}
|
@@ -4295,7 +4458,7 @@ static int stbtt__compute_crossings_x(float x, float y, int nverts, stbtt_vertex
|
|
4295
4458
|
y1 = (int)verts[i ].y;
|
4296
4459
|
if (y > STBTT_min(y0,y1) && y < STBTT_max(y0,y1) && x > STBTT_min(x0,x1)) {
|
4297
4460
|
float x_inter = (y - y0) / (y1 - y0) * (x1-x0) + x0;
|
4298
|
-
if (x_inter < x)
|
4461
|
+
if (x_inter < x)
|
4299
4462
|
winding += (y0 < y1) ? 1 : -1;
|
4300
4463
|
}
|
4301
4464
|
} else {
|
@@ -4307,7 +4470,7 @@ static int stbtt__compute_crossings_x(float x, float y, int nverts, stbtt_vertex
|
|
4307
4470
|
if (hits[1][0] < 0)
|
4308
4471
|
winding += (hits[1][1] < 0 ? -1 : 1);
|
4309
4472
|
}
|
4310
|
-
}
|
4473
|
+
}
|
4311
4474
|
}
|
4312
4475
|
}
|
4313
4476
|
return winding;
|
@@ -4360,12 +4523,7 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
|
|
4360
4523
|
int w,h;
|
4361
4524
|
unsigned char *data;
|
4362
4525
|
|
4363
|
-
|
4364
|
-
if (scale_x == 0) scale_x = scale_y;
|
4365
|
-
if (scale_y == 0) {
|
4366
|
-
if (scale_x == 0) return NULL; // if both scales are 0, return NULL
|
4367
|
-
scale_y = scale_x;
|
4368
|
-
}
|
4526
|
+
if (scale == 0) return NULL;
|
4369
4527
|
|
4370
4528
|
stbtt_GetGlyphBitmapBoxSubpixel(info, glyph, scale, scale, 0.0f,0.0f, &ix0,&iy0,&ix1,&iy1);
|
4371
4529
|
|
@@ -4388,7 +4546,7 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
|
|
4388
4546
|
|
4389
4547
|
// invert for y-downwards bitmaps
|
4390
4548
|
scale_y = -scale_y;
|
4391
|
-
|
4549
|
+
|
4392
4550
|
{
|
4393
4551
|
int x,y,i,j;
|
4394
4552
|
float *precompute;
|
@@ -4537,7 +4695,7 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
|
|
4537
4695
|
STBTT_free(verts, info->userdata);
|
4538
4696
|
}
|
4539
4697
|
return data;
|
4540
|
-
}
|
4698
|
+
}
|
4541
4699
|
|
4542
4700
|
STBTT_DEF unsigned char * stbtt_GetCodepointSDF(const stbtt_fontinfo *info, float scale, int codepoint, int padding, unsigned char onedge_value, float pixel_dist_scale, int *width, int *height, int *xoff, int *yoff)
|
4543
4701
|
{
|
@@ -4555,7 +4713,7 @@ STBTT_DEF void stbtt_FreeSDF(unsigned char *bitmap, void *userdata)
|
|
4555
4713
|
//
|
4556
4714
|
|
4557
4715
|
// check if a utf8 string contains a prefix which is the utf16 string; if so return length of matching utf8 string
|
4558
|
-
static stbtt_int32 stbtt__CompareUTF8toUTF16_bigendian_prefix(stbtt_uint8 *s1, stbtt_int32 len1, stbtt_uint8 *s2, stbtt_int32 len2)
|
4716
|
+
static stbtt_int32 stbtt__CompareUTF8toUTF16_bigendian_prefix(stbtt_uint8 *s1, stbtt_int32 len1, stbtt_uint8 *s2, stbtt_int32 len2)
|
4559
4717
|
{
|
4560
4718
|
stbtt_int32 i=0;
|
4561
4719
|
|
@@ -4594,7 +4752,7 @@ static stbtt_int32 stbtt__CompareUTF8toUTF16_bigendian_prefix(stbtt_uint8 *s1, s
|
|
4594
4752
|
return i;
|
4595
4753
|
}
|
4596
4754
|
|
4597
|
-
static int stbtt_CompareUTF8toUTF16_bigendian_internal(char *s1, int len1, char *s2, int len2)
|
4755
|
+
static int stbtt_CompareUTF8toUTF16_bigendian_internal(char *s1, int len1, char *s2, int len2)
|
4598
4756
|
{
|
4599
4757
|
return len1 == stbtt__CompareUTF8toUTF16_bigendian_prefix((stbtt_uint8*) s1, len1, (stbtt_uint8*) s2, len2);
|
4600
4758
|
}
|
@@ -4723,7 +4881,7 @@ STBTT_DEF int stbtt_BakeFontBitmap(const unsigned char *data, int offset,
|
|
4723
4881
|
|
4724
4882
|
STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index)
|
4725
4883
|
{
|
4726
|
-
return stbtt_GetFontOffsetForIndex_internal((unsigned char *) data, index);
|
4884
|
+
return stbtt_GetFontOffsetForIndex_internal((unsigned char *) data, index);
|
4727
4885
|
}
|
4728
4886
|
|
4729
4887
|
STBTT_DEF int stbtt_GetNumberOfFonts(const unsigned char *data)
|
@@ -4816,38 +4974,38 @@ This software is available under 2 licenses -- choose whichever you prefer.
|
|
4816
4974
|
------------------------------------------------------------------------------
|
4817
4975
|
ALTERNATIVE A - MIT License
|
4818
4976
|
Copyright (c) 2017 Sean Barrett
|
4819
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4820
|
-
this software and associated documentation files (the "Software"), to deal in
|
4821
|
-
the Software without restriction, including without limitation the rights to
|
4822
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
4823
|
-
of the Software, and to permit persons to whom the Software is furnished to do
|
4977
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4978
|
+
this software and associated documentation files (the "Software"), to deal in
|
4979
|
+
the Software without restriction, including without limitation the rights to
|
4980
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
4981
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
4824
4982
|
so, subject to the following conditions:
|
4825
|
-
The above copyright notice and this permission notice shall be included in all
|
4983
|
+
The above copyright notice and this permission notice shall be included in all
|
4826
4984
|
copies or substantial portions of the Software.
|
4827
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
4828
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
4829
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
4830
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
4831
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
4832
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
4985
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
4986
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
4987
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
4988
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
4989
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
4990
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
4833
4991
|
SOFTWARE.
|
4834
4992
|
------------------------------------------------------------------------------
|
4835
4993
|
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
4836
4994
|
This is free and unencumbered software released into the public domain.
|
4837
|
-
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
4838
|
-
software, either in source code form or as a compiled binary, for any purpose,
|
4995
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
4996
|
+
software, either in source code form or as a compiled binary, for any purpose,
|
4839
4997
|
commercial or non-commercial, and by any means.
|
4840
|
-
In jurisdictions that recognize copyright laws, the author or authors of this
|
4841
|
-
software dedicate any and all copyright interest in the software to the public
|
4842
|
-
domain. We make this dedication for the benefit of the public at large and to
|
4843
|
-
the detriment of our heirs and successors. We intend this dedication to be an
|
4844
|
-
overt act of relinquishment in perpetuity of all present and future rights to
|
4998
|
+
In jurisdictions that recognize copyright laws, the author or authors of this
|
4999
|
+
software dedicate any and all copyright interest in the software to the public
|
5000
|
+
domain. We make this dedication for the benefit of the public at large and to
|
5001
|
+
the detriment of our heirs and successors. We intend this dedication to be an
|
5002
|
+
overt act of relinquishment in perpetuity of all present and future rights to
|
4845
5003
|
this software under copyright law.
|
4846
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
4847
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
4848
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
4849
|
-
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
4850
|
-
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
5004
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
5005
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
5006
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
5007
|
+
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
5008
|
+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
4851
5009
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
4852
5010
|
------------------------------------------------------------------------------
|
4853
5011
|
*/
|