gosu 1.4.6 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/COPYING +2 -1
- data/dependencies/SDL/include/SDL3/SDL.h +91 -0
- data/dependencies/SDL/include/SDL3/SDL_assert.h +710 -0
- data/dependencies/SDL/include/SDL3/SDL_asyncio.h +550 -0
- data/dependencies/SDL/include/SDL3/SDL_atomic.h +692 -0
- data/dependencies/SDL/include/SDL3/SDL_audio.h +2382 -0
- data/dependencies/SDL/include/SDL3/SDL_begin_code.h +553 -0
- data/dependencies/SDL/include/{SDL_bits.h → SDL3/SDL_bits.h} +47 -27
- data/dependencies/SDL/include/{SDL_blendmode.h → SDL3/SDL_blendmode.h} +59 -55
- data/dependencies/SDL/include/SDL3/SDL_camera.h +535 -0
- data/dependencies/SDL/include/SDL3/SDL_clipboard.h +331 -0
- data/dependencies/SDL/include/{close_code.h → SDL3/SDL_close_code.h} +9 -8
- data/dependencies/SDL/include/{SDL_types.h → SDL3/SDL_copying.h} +2 -9
- data/dependencies/SDL/include/SDL3/SDL_cpuinfo.h +374 -0
- data/dependencies/SDL/include/SDL3/SDL_dialog.h +343 -0
- data/dependencies/SDL/include/SDL3/SDL_dlopennote.h +234 -0
- data/dependencies/SDL/include/{SDL_egl.h → SDL3/SDL_egl.h} +11 -8
- data/dependencies/SDL/include/SDL3/SDL_endian.h +645 -0
- data/dependencies/SDL/include/SDL3/SDL_error.h +226 -0
- data/dependencies/SDL/include/SDL3/SDL_events.h +1651 -0
- data/dependencies/SDL/include/SDL3/SDL_filesystem.h +537 -0
- data/dependencies/SDL/include/SDL3/SDL_gamepad.h +1657 -0
- data/dependencies/SDL/include/SDL3/SDL_gpu.h +4637 -0
- data/dependencies/SDL/include/SDL3/SDL_guid.h +106 -0
- data/dependencies/SDL/include/SDL3/SDL_haptic.h +1461 -0
- data/dependencies/SDL/include/SDL3/SDL_hidapi.h +571 -0
- data/dependencies/SDL/include/SDL3/SDL_hints.h +5041 -0
- data/dependencies/SDL/include/SDL3/SDL_init.h +508 -0
- data/dependencies/SDL/include/SDL3/SDL_intrin.h +410 -0
- data/dependencies/SDL/include/SDL3/SDL_iostream.h +1379 -0
- data/dependencies/SDL/include/SDL3/SDL_joystick.h +1385 -0
- data/dependencies/SDL/include/SDL3/SDL_keyboard.h +615 -0
- data/dependencies/SDL/include/SDL3/SDL_keycode.h +348 -0
- data/dependencies/SDL/include/SDL3/SDL_loadso.h +145 -0
- data/dependencies/SDL/include/{SDL_locale.h → SDL3/SDL_locale.h} +40 -24
- data/dependencies/SDL/include/SDL3/SDL_log.h +541 -0
- data/dependencies/SDL/include/SDL3/SDL_main.h +704 -0
- data/dependencies/SDL/include/SDL3/SDL_main_impl.h +149 -0
- data/dependencies/SDL/include/{SDL_messagebox.h → SDL3/SDL_messagebox.h} +85 -48
- data/dependencies/SDL/include/{SDL_metal.h → SDL3/SDL_metal.h} +29 -29
- data/dependencies/SDL/include/{SDL_misc.h → SDL3/SDL_misc.h} +13 -12
- data/dependencies/SDL/include/SDL3/SDL_mouse.h +813 -0
- data/dependencies/SDL/include/SDL3/SDL_mutex.h +1117 -0
- data/dependencies/SDL/include/SDL3/SDL_oldnames.h +1339 -0
- data/dependencies/SDL/include/{SDL_opengl.h → SDL3/SDL_opengl.h} +1247 -278
- data/dependencies/SDL/include/{SDL_opengl_glext.h → SDL3/SDL_opengl_glext.h} +5 -1
- data/dependencies/SDL/include/{SDL_opengles.h → SDL3/SDL_opengles.h} +6 -7
- data/dependencies/SDL/include/{SDL_opengles2.h → SDL3/SDL_opengles2.h} +10 -11
- data/dependencies/SDL/include/SDL3/SDL_pen.h +198 -0
- data/dependencies/SDL/include/SDL3/SDL_pixels.h +1441 -0
- data/dependencies/SDL/include/{SDL_test_log.h → SDL3/SDL_platform.h} +25 -26
- data/dependencies/SDL/include/SDL3/SDL_platform_defines.h +497 -0
- data/dependencies/SDL/include/{SDL_power.h → SDL3/SDL_power.h} +40 -20
- data/dependencies/SDL/include/SDL3/SDL_process.h +441 -0
- data/dependencies/SDL/include/SDL3/SDL_properties.h +572 -0
- data/dependencies/SDL/include/SDL3/SDL_rect.h +528 -0
- data/dependencies/SDL/include/SDL3/SDL_render.h +3034 -0
- data/dependencies/SDL/include/SDL3/SDL_revision.h +56 -0
- data/dependencies/SDL/include/{SDL_scancode.h → SDL3/SDL_scancode.h} +60 -68
- data/dependencies/SDL/include/SDL3/SDL_sensor.h +321 -0
- data/dependencies/SDL/include/SDL3/SDL_stdinc.h +6186 -0
- data/dependencies/SDL/include/SDL3/SDL_storage.h +686 -0
- data/dependencies/SDL/include/SDL3/SDL_surface.h +1769 -0
- data/dependencies/SDL/include/SDL3/SDL_system.h +840 -0
- data/dependencies/SDL/include/{SDL_test.h → SDL3/SDL_test.h} +16 -22
- data/dependencies/SDL/include/{SDL_test_assert.h → SDL3/SDL_test_assert.h} +27 -34
- data/dependencies/SDL/include/{SDL_test_common.h → SDL3/SDL_test_common.h} +109 -52
- data/dependencies/SDL/include/{SDL_test_compare.h → SDL3/SDL_test_compare.h} +22 -14
- data/dependencies/SDL/include/{SDL_test_crc32.h → SDL3/SDL_test_crc32.h} +27 -30
- data/dependencies/SDL/include/{SDL_test_font.h → SDL3/SDL_test_font.h} +50 -49
- data/dependencies/SDL/include/{SDL_test_fuzzer.h → SDL3/SDL_test_fuzzer.h} +64 -79
- data/dependencies/SDL/include/{SDL_test_harness.h → SDL3/SDL_test_harness.h} +47 -30
- data/dependencies/SDL/include/SDL3/SDL_test_log.h +83 -0
- data/dependencies/SDL/include/{SDL_test_md5.h → SDL3/SDL_test_md5.h} +21 -28
- data/dependencies/SDL/include/{SDL_test_memory.h → SDL3/SDL_test_memory.h} +19 -16
- data/dependencies/SDL/include/SDL3/SDL_thread.h +602 -0
- data/dependencies/SDL/include/SDL3/SDL_time.h +249 -0
- data/dependencies/SDL/include/SDL3/SDL_timer.h +454 -0
- data/dependencies/SDL/include/SDL3/SDL_touch.h +184 -0
- data/dependencies/SDL/include/SDL3/SDL_tray.h +544 -0
- data/dependencies/SDL/include/SDL3/SDL_version.h +198 -0
- data/dependencies/SDL/include/SDL3/SDL_video.h +3497 -0
- data/dependencies/SDL/include/SDL3/SDL_vulkan.h +287 -0
- data/dependencies/SDL/lib/x64/libSDL3.dll.a +0 -0
- data/dependencies/SDL/lib/x86/libSDL3.dll.a +0 -0
- data/dependencies/SDL_sound/SDL3_sound/SDL_sound.h +755 -0
- data/dependencies/SDL_sound/SDL_sound.c +136 -215
- data/dependencies/SDL_sound/SDL_sound_aiff.c +55 -54
- data/dependencies/SDL_sound/SDL_sound_au.c +32 -32
- data/dependencies/SDL_sound/SDL_sound_coreaudio.c +24 -41
- data/dependencies/SDL_sound/SDL_sound_flac.c +32 -12
- data/dependencies/SDL_sound/SDL_sound_internal.h +33 -48
- data/dependencies/SDL_sound/SDL_sound_modplug.c +21 -29
- data/dependencies/SDL_sound/SDL_sound_mp3.c +35 -13
- data/dependencies/SDL_sound/SDL_sound_raw.c +14 -15
- data/dependencies/SDL_sound/SDL_sound_shn.c +82 -82
- data/dependencies/SDL_sound/SDL_sound_voc.c +30 -30
- data/dependencies/SDL_sound/SDL_sound_vorbis.c +34 -25
- data/dependencies/SDL_sound/SDL_sound_wav.c +86 -82
- data/dependencies/SDL_sound/dr_flac.h +1890 -1301
- data/dependencies/SDL_sound/dr_mp3.h +1098 -660
- data/dependencies/SDL_sound/libmodplug/fastmix.c +1 -1
- data/dependencies/SDL_sound/libmodplug/libmodplug.h +5 -4
- data/dependencies/SDL_sound/libmodplug/load_ams.c +6 -3
- data/dependencies/SDL_sound/libmodplug/load_dsm.c +2 -1
- data/dependencies/SDL_sound/libmodplug/load_mt2.c +2 -2
- data/dependencies/SDL_sound/libmodplug/modplug.h +2 -1
- data/dependencies/SDL_sound/libmodplug/snd_fx.c +3 -3
- data/dependencies/SDL_sound/libmodplug/sndfile.c +3 -0
- data/dependencies/SDL_sound/libmodplug/sndmix.c +7 -3
- data/dependencies/SDL_sound/stb_vorbis.h +397 -342
- data/dependencies/mojoAL/AL/alc.h +2 -2
- data/dependencies/mojoAL/mojoal.c +2120 -1885
- data/dependencies/stb/stb_image.h +1190 -1379
- data/dependencies/stb/stb_image_write.h +329 -129
- data/dependencies/stb/stb_truetype.h +304 -60
- data/dependencies/utf8proc/utf8proc.c +133 -75
- data/dependencies/utf8proc/utf8proc.h +131 -50
- data/dependencies/utf8proc/utf8proc_data.h +16213 -15658
- data/ext/gosu-ffi/extconf.rb +103 -0
- data/ext/gosu-ffi/gosu-ffi.def +467 -0
- data/ffi/Gosu.cpp +330 -0
- data/ffi/Gosu.h +84 -0
- data/ffi/Gosu_Channel.cpp +62 -0
- data/ffi/Gosu_Channel.h +17 -0
- data/ffi/Gosu_Color.cpp +176 -0
- data/ffi/Gosu_Color.h +31 -0
- data/ffi/Gosu_Constants.cpp +334 -0
- data/ffi/Gosu_FFI.h +34 -0
- data/ffi/Gosu_FFI_internal.h +160 -0
- data/ffi/Gosu_Font.cpp +97 -0
- data/ffi/Gosu_Font.h +32 -0
- data/ffi/Gosu_Image.cpp +239 -0
- data/ffi/Gosu_Image.h +71 -0
- data/ffi/Gosu_Sample.cpp +29 -0
- data/ffi/Gosu_Sample.h +14 -0
- data/ffi/Gosu_Song.cpp +69 -0
- data/ffi/Gosu_Song.h +18 -0
- data/ffi/Gosu_TextInput.cpp +94 -0
- data/ffi/Gosu_TextInput.h +25 -0
- data/ffi/Gosu_Window.cpp +314 -0
- data/ffi/Gosu_Window.h +78 -0
- data/include/Gosu/Audio.hpp +6 -11
- data/include/Gosu/Bitmap.hpp +38 -53
- data/include/Gosu/Buffer.hpp +54 -0
- data/include/Gosu/Color.hpp +29 -36
- data/include/Gosu/Directories.hpp +25 -28
- data/include/Gosu/Drawable.hpp +58 -0
- data/include/Gosu/Font.hpp +6 -5
- data/include/Gosu/Fwd.hpp +4 -6
- data/include/Gosu/Gosu.hpp +5 -5
- data/include/Gosu/Graphics.hpp +53 -61
- data/include/Gosu/GraphicsBase.hpp +1 -11
- data/include/Gosu/Image.hpp +12 -15
- data/include/Gosu/Math.hpp +50 -72
- data/include/Gosu/Transform.hpp +32 -0
- data/include/Gosu/Utility.hpp +77 -1
- data/include/Gosu/Version.hpp +2 -2
- data/include/Gosu/Window.hpp +15 -9
- data/lib/SDL3.dll +0 -0
- data/lib/gosu/channel.rb +50 -0
- data/lib/gosu/color.rb +173 -0
- data/lib/gosu/compat.rb +130 -17
- data/lib/gosu/constants.rb +386 -0
- data/lib/gosu/ffi.rb +269 -0
- data/lib/gosu/font.rb +62 -0
- data/lib/gosu/gl_tex_info.rb +33 -0
- data/lib/gosu/gosu.rb +250 -0
- data/lib/gosu/image.rb +179 -0
- data/lib/gosu/numeric.rb +17 -0
- data/lib/gosu/preview.rb +6 -6
- data/lib/gosu/sample.rb +25 -0
- data/lib/gosu/song.rb +57 -0
- data/lib/gosu/text_input.rb +83 -0
- data/lib/gosu/window.rb +249 -0
- data/lib/gosu.rb +29 -8
- data/lib64/SDL3.dll +0 -0
- data/rdoc/gosu.rb +2 -2
- data/src/Audio.cpp +30 -24
- data/src/AudioFile.hpp +5 -4
- data/src/AudioFileAudioToolbox.cpp +8 -8
- data/src/AudioFileSDLSound.cpp +12 -15
- data/src/BinPacker.cpp +188 -0
- data/src/BinPacker.hpp +55 -0
- data/src/Bitmap.cpp +172 -143
- data/src/BitmapIO.cpp +60 -86
- data/src/Buffer.cpp +150 -0
- data/src/ClipRectStack.cpp +38 -0
- data/src/ClipRectStack.hpp +17 -83
- data/src/Color.cpp +75 -80
- data/src/Directories.cpp +47 -0
- data/src/DirectoriesUIKit.cpp +50 -0
- data/src/DrawOp.hpp +20 -18
- data/src/DrawOpQueue.hpp +27 -33
- data/src/Drawable.cpp +95 -0
- data/src/EmptyDrawable.hpp +38 -0
- data/src/FPS.cpp +31 -0
- data/src/Font.cpp +104 -74
- data/src/GosuGLView.cpp +13 -11
- data/src/GosuViewController.cpp +2 -10
- data/src/Graphics.cpp +86 -145
- data/src/GraphicsImpl.hpp +14 -68
- data/src/Image.cpp +41 -35
- data/src/Input.cpp +73 -78
- data/src/Macro.cpp +46 -29
- data/src/Macro.hpp +23 -17
- data/src/MarkupParser.cpp +5 -5
- data/src/Math.cpp +48 -22
- data/src/OffScreenTarget.cpp +47 -50
- data/src/OffScreenTarget.hpp +13 -11
- data/src/OpenGLContext.cpp +116 -0
- data/src/OpenGLContext.hpp +41 -0
- data/src/RenderState.hpp +49 -71
- data/src/Resolution.cpp +65 -53
- data/src/TexChunk.cpp +35 -80
- data/src/TexChunk.hpp +44 -35
- data/src/Text.cpp +1 -1
- data/src/TextBuilder.cpp +35 -21
- data/src/TextBuilder.hpp +6 -9
- data/src/TextInput.cpp +9 -9
- data/src/Texture.cpp +62 -80
- data/src/Texture.hpp +25 -23
- data/src/TiledDrawable.cpp +149 -0
- data/src/TiledDrawable.hpp +47 -0
- data/src/TimingApple.cpp +1 -1
- data/src/Transform.cpp +45 -50
- data/src/TransformStack.hpp +16 -16
- data/src/TrueTypeFont.cpp +59 -51
- data/src/TrueTypeFont.hpp +6 -7
- data/src/TrueTypeFontApple.cpp +28 -19
- data/src/TrueTypeFontUnix.cpp +39 -32
- data/src/TrueTypeFontWin.cpp +30 -30
- data/src/Utility.cpp +113 -37
- data/src/UtilityWin.cpp +49 -0
- data/src/Window.cpp +121 -151
- data/src/WindowUIKit.cpp +14 -14
- metadata +165 -118
- data/dependencies/SDL/include/SDL.h +0 -233
- data/dependencies/SDL/include/SDL_assert.h +0 -320
- data/dependencies/SDL/include/SDL_atomic.h +0 -415
- data/dependencies/SDL/include/SDL_audio.h +0 -1500
- data/dependencies/SDL/include/SDL_clipboard.h +0 -141
- data/dependencies/SDL/include/SDL_config.h +0 -331
- data/dependencies/SDL/include/SDL_cpuinfo.h +0 -594
- data/dependencies/SDL/include/SDL_endian.h +0 -348
- data/dependencies/SDL/include/SDL_error.h +0 -163
- data/dependencies/SDL/include/SDL_events.h +0 -1166
- data/dependencies/SDL/include/SDL_filesystem.h +0 -149
- data/dependencies/SDL/include/SDL_gamecontroller.h +0 -1074
- data/dependencies/SDL/include/SDL_gesture.h +0 -117
- data/dependencies/SDL/include/SDL_guid.h +0 -100
- data/dependencies/SDL/include/SDL_haptic.h +0 -1341
- data/dependencies/SDL/include/SDL_hidapi.h +0 -451
- data/dependencies/SDL/include/SDL_hints.h +0 -2569
- data/dependencies/SDL/include/SDL_joystick.h +0 -1066
- data/dependencies/SDL/include/SDL_keyboard.h +0 -353
- data/dependencies/SDL/include/SDL_keycode.h +0 -358
- data/dependencies/SDL/include/SDL_loadso.h +0 -115
- data/dependencies/SDL/include/SDL_log.h +0 -404
- data/dependencies/SDL/include/SDL_main.h +0 -275
- data/dependencies/SDL/include/SDL_mouse.h +0 -465
- data/dependencies/SDL/include/SDL_mutex.h +0 -471
- data/dependencies/SDL/include/SDL_name.h +0 -33
- data/dependencies/SDL/include/SDL_pixels.h +0 -644
- data/dependencies/SDL/include/SDL_platform.h +0 -261
- data/dependencies/SDL/include/SDL_quit.h +0 -58
- data/dependencies/SDL/include/SDL_rect.h +0 -376
- data/dependencies/SDL/include/SDL_render.h +0 -1919
- data/dependencies/SDL/include/SDL_revision.h +0 -7
- data/dependencies/SDL/include/SDL_rwops.h +0 -841
- data/dependencies/SDL/include/SDL_sensor.h +0 -322
- data/dependencies/SDL/include/SDL_shape.h +0 -155
- data/dependencies/SDL/include/SDL_stdinc.h +0 -830
- data/dependencies/SDL/include/SDL_surface.h +0 -997
- data/dependencies/SDL/include/SDL_system.h +0 -623
- data/dependencies/SDL/include/SDL_syswm.h +0 -386
- data/dependencies/SDL/include/SDL_test_images.h +0 -78
- data/dependencies/SDL/include/SDL_test_random.h +0 -115
- data/dependencies/SDL/include/SDL_thread.h +0 -464
- data/dependencies/SDL/include/SDL_timer.h +0 -222
- data/dependencies/SDL/include/SDL_touch.h +0 -150
- data/dependencies/SDL/include/SDL_version.h +0 -204
- data/dependencies/SDL/include/SDL_video.h +0 -2150
- data/dependencies/SDL/include/SDL_vulkan.h +0 -215
- data/dependencies/SDL/include/begin_code.h +0 -187
- 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.h +0 -725
- data/ext/gosu/extconf.rb +0 -119
- data/include/Gosu/IO.hpp +0 -254
- data/include/Gosu/ImageData.hpp +0 -53
- data/include/Gosu/Inspection.hpp +0 -7
- data/lib/SDL2.dll +0 -0
- data/lib/gosu/patches.rb +0 -66
- data/lib/gosu/run.rb +0 -20
- data/lib/gosu/swig_patches.rb +0 -110
- data/lib64/SDL2.dll +0 -0
- data/src/BlockAllocator.cpp +0 -131
- data/src/BlockAllocator.hpp +0 -32
- data/src/DirectoriesApple.cpp +0 -69
- data/src/DirectoriesUnix.cpp +0 -46
- data/src/DirectoriesWin.cpp +0 -65
- data/src/EmptyImageData.hpp +0 -52
- data/src/FileUnix.cpp +0 -99
- data/src/FileWin.cpp +0 -88
- data/src/IO.cpp +0 -60
- data/src/Iconv.hpp +0 -51
- data/src/Inspection.cpp +0 -27
- data/src/LargeImageData.cpp +0 -215
- data/src/LargeImageData.hpp +0 -39
- data/src/Log.hpp +0 -19
- data/src/RubyGosu.cxx +0 -13100
- data/src/RubyGosu.h +0 -49
- data/src/WinUtility.cpp +0 -61
- data/src/WinUtility.hpp +0 -27
- /data/dependencies/SDL/include/{SDL_opengles2_gl2.h → SDL3/SDL_opengles2_gl2.h} +0 -0
- /data/dependencies/SDL/include/{SDL_opengles2_gl2ext.h → SDL3/SDL_opengles2_gl2ext.h} +0 -0
- /data/dependencies/SDL/include/{SDL_opengles2_gl2platform.h → SDL3/SDL_opengles2_gl2platform.h} +0 -0
- /data/dependencies/SDL/include/{SDL_opengles2_khrplatform.h → SDL3/SDL_opengles2_khrplatform.h} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// stb_truetype.h - v1.
|
|
1
|
+
// stb_truetype.h - v1.28 - public domain
|
|
2
2
|
// authored from 2009-2021 by Sean Barrett / RAD Game Tools
|
|
3
3
|
//
|
|
4
4
|
// =======================================================================
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
// Cass Everitt Martins Mozeiko github:aloucks
|
|
46
46
|
// stoiko (Haemimont Games) Cap Petschulat github:oyvindjam
|
|
47
47
|
// Brian Hook Omar Cornut github:vassvik
|
|
48
|
-
// Walter van Niftrik Ryan Griege
|
|
48
|
+
// Walter van Niftrik Ryan Griege github:Cerallin
|
|
49
49
|
// David Gow Peter LaValle
|
|
50
50
|
// David Given Sergey Popov
|
|
51
51
|
// Ivan-Assen Ivanov Giumo X. Clanjor
|
|
@@ -54,10 +54,14 @@
|
|
|
54
54
|
// Hou Qiming Derek Vinyard
|
|
55
55
|
// Rob Loach Cort Stratton
|
|
56
56
|
// Kenney Phillis Jr. Brian Costabile
|
|
57
|
-
// Ken Voskuil (kaesve)
|
|
57
|
+
// Ken Voskuil (kaesve) Yakov Galka
|
|
58
|
+
// Neil Bickford Matthias Dorfelt
|
|
59
|
+
// Isaac "Atridas" Serrano
|
|
58
60
|
//
|
|
59
61
|
// VERSION HISTORY
|
|
60
62
|
//
|
|
63
|
+
// 1.28 (2026-11-12) several fixes
|
|
64
|
+
// 1.27 (2026-11-08) many fixes, support vertical layout, underlines, font name
|
|
61
65
|
// 1.26 (2021-08-28) fix broken rasterizer
|
|
62
66
|
// 1.25 (2021-07-11) many fixes
|
|
63
67
|
// 1.24 (2020-02-05) fix warning
|
|
@@ -201,10 +205,10 @@
|
|
|
201
205
|
// Baseline:
|
|
202
206
|
// You need to select a y-coordinate that is the baseline of where
|
|
203
207
|
// your text will appear. Call GetFontBoundingBox to get the baseline-relative
|
|
204
|
-
// bounding box for all characters. SF
|
|
208
|
+
// bounding box for all characters. SF*y1 will be the distance in pixels
|
|
205
209
|
// that the worst-case character could extend above the baseline, so if
|
|
206
210
|
// you want the top edge of characters to appear at the top of the
|
|
207
|
-
// screen where y=0, then you would set the baseline to SF
|
|
211
|
+
// screen where y=0, then you would set the baseline to SF*y1.
|
|
208
212
|
//
|
|
209
213
|
// Current point:
|
|
210
214
|
// Set the current point where the first character will appear. The
|
|
@@ -215,10 +219,10 @@
|
|
|
215
219
|
// the current point based on that.
|
|
216
220
|
//
|
|
217
221
|
// Displaying a character:
|
|
218
|
-
//
|
|
219
|
-
// relative to <current_point, baseline>. I.e. if it returns x0,y0,
|
|
220
|
-
// then the character should be displayed in the rectangle from
|
|
221
|
-
// <current_point+
|
|
222
|
+
// Call a function to compute the bounding box of the character. It will contain
|
|
223
|
+
// signed values relative to <current_point, baseline>. I.e. if it returns x0,y0,
|
|
224
|
+
// x1,y1, then the character should be displayed in the rectangle from
|
|
225
|
+
// <current_point+x0,baseline+y0> to <current_point+x1,baseline+y1>.
|
|
222
226
|
//
|
|
223
227
|
// Advancing for the next character:
|
|
224
228
|
// Call GlyphHMetrics, and compute 'current_point += SF * advance'.
|
|
@@ -230,10 +234,10 @@
|
|
|
230
234
|
//
|
|
231
235
|
// - Use the functions with Subpixel at the end to allow your characters
|
|
232
236
|
// to have subpixel positioning. Since the font is anti-aliased, not
|
|
233
|
-
// hinted, this is very
|
|
237
|
+
// hinted, this is very important for quality. (This is not possible with
|
|
234
238
|
// baked fonts.)
|
|
235
239
|
//
|
|
236
|
-
// - Kerning is
|
|
240
|
+
// - Kerning is supported, and if you're supporting subpixel rendering
|
|
237
241
|
// then kerning is worth using to give your text a polished look.
|
|
238
242
|
//
|
|
239
243
|
// Performance:
|
|
@@ -322,7 +326,7 @@ void my_stbtt_print(float x, float y, char *text)
|
|
|
322
326
|
//
|
|
323
327
|
//////////////////////////////////////////////////////////////////////////////
|
|
324
328
|
//
|
|
325
|
-
//
|
|
329
|
+
// Compilable program (does no cleanup): get a single bitmap, print as ASCII art
|
|
326
330
|
//
|
|
327
331
|
#if 0
|
|
328
332
|
#include <stdio.h>
|
|
@@ -337,10 +341,10 @@ int main(int argc, char **argv)
|
|
|
337
341
|
unsigned char *bitmap;
|
|
338
342
|
int w,h,i,j,c = (argc > 1 ? atoi(argv[1]) : 'a'), s = (argc > 2 ? atoi(argv[2]) : 20);
|
|
339
343
|
|
|
340
|
-
fread(ttf_buffer, 1, 1<<25, fopen(argc > 3 ? argv[3] : "c:/windows/fonts/arialbd.ttf", "rb"));
|
|
344
|
+
fread(ttf_buffer, 1, 1<<25, fopen(argc > 3 ? argv[3] : "c:/windows/fonts/arialbd.ttf", "rb")); // fclose() omitted for clarity
|
|
341
345
|
|
|
342
346
|
stbtt_InitFont(&font, ttf_buffer, stbtt_GetFontOffsetForIndex(ttf_buffer,0));
|
|
343
|
-
bitmap = stbtt_GetCodepointBitmap(&font, 0,stbtt_ScaleForPixelHeight(&font, s), c, &w, &h, 0,0);
|
|
347
|
+
bitmap = stbtt_GetCodepointBitmap(&font, 0,stbtt_ScaleForPixelHeight(&font, s), c, &w, &h, 0,0); // stbtt_FreeBitmap() omitted for clarity
|
|
344
348
|
|
|
345
349
|
for (j=0; j < h; ++j) {
|
|
346
350
|
for (i=0; i < w; ++i)
|
|
@@ -366,7 +370,7 @@ int main(int argc, char **argv)
|
|
|
366
370
|
//
|
|
367
371
|
//////////////////////////////////////////////////////////////////////////////
|
|
368
372
|
//
|
|
369
|
-
// Complete program: print "Hello World!" banner, with bugs
|
|
373
|
+
// Complete program: print "Hello World!" banner, with bugs & no cleanup
|
|
370
374
|
//
|
|
371
375
|
#if 0
|
|
372
376
|
char buffer[24<<20];
|
|
@@ -620,7 +624,7 @@ typedef struct
|
|
|
620
624
|
{
|
|
621
625
|
float font_size;
|
|
622
626
|
int first_unicode_codepoint_in_range; // if non-zero, then the chars are continuous, and this is the first codepoint
|
|
623
|
-
int *array_of_unicode_codepoints;
|
|
627
|
+
const int *array_of_unicode_codepoints; // if non-zero, then this is an array of unicode codepoints
|
|
624
628
|
int num_chars;
|
|
625
629
|
stbtt_packedchar *chardata_for_range; // output
|
|
626
630
|
unsigned char h_oversample, v_oversample; // don't set these, they're used internally
|
|
@@ -651,7 +655,7 @@ STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h
|
|
|
651
655
|
STBTT_DEF void stbtt_PackSetSkipMissingCodepoints(stbtt_pack_context *spc, int skip);
|
|
652
656
|
// If skip != 0, this tells stb_truetype to skip any codepoints for which
|
|
653
657
|
// there is no corresponding glyph. If skip=0, which is the default, then
|
|
654
|
-
// codepoints without a glyph
|
|
658
|
+
// codepoints without a glyph received the font's "missing character" glyph,
|
|
655
659
|
// typically an empty box by convention.
|
|
656
660
|
|
|
657
661
|
STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, // same data as above
|
|
@@ -718,7 +722,7 @@ struct stbtt_fontinfo
|
|
|
718
722
|
|
|
719
723
|
int numGlyphs; // number of glyphs, needed for range checking
|
|
720
724
|
|
|
721
|
-
int loca,head,glyf,hhea,hmtx,kern,gpos,svg; // table locations as offset from start of .ttf
|
|
725
|
+
int loca,head,glyf,hhea,hmtx,vhea,vmtx,kern,gpos,svg; // table locations as offset from start of .ttf
|
|
722
726
|
int index_map; // a cmap mapping for our chosen character encoding
|
|
723
727
|
int indexToLocFormat; // format needed to map from glyph index to glyph
|
|
724
728
|
|
|
@@ -740,7 +744,7 @@ STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, in
|
|
|
740
744
|
|
|
741
745
|
//////////////////////////////////////////////////////////////////////////////
|
|
742
746
|
//
|
|
743
|
-
// CHARACTER TO GLYPH-INDEX
|
|
747
|
+
// CHARACTER TO GLYPH-INDEX CONVERSION
|
|
744
748
|
|
|
745
749
|
STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint);
|
|
746
750
|
// If you're going to perform multiple operations on the same character
|
|
@@ -763,6 +767,10 @@ STBTT_DEF float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float pixe
|
|
|
763
767
|
// scale = pixels / (ascent - descent)
|
|
764
768
|
// so if you prefer to measure height by the ascent only, use a similar calculation.
|
|
765
769
|
|
|
770
|
+
STBTT_DEF float stbtt_ScaleForPixelWidth(const stbtt_fontinfo *info, float pixels);
|
|
771
|
+
// computes a scale factor to produce a font whose width is 'pixels' wide.
|
|
772
|
+
// Width is measured as the distance from the left-side-bearing to the right-side-bearing
|
|
773
|
+
|
|
766
774
|
STBTT_DEF float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels);
|
|
767
775
|
// computes a scale factor to produce a font whose EM size is mapped to
|
|
768
776
|
// 'pixels' tall. This is probably what traditional APIs compute, but
|
|
@@ -776,6 +784,9 @@ STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, in
|
|
|
776
784
|
// these are expressed in unscaled coordinates, so you must multiply by
|
|
777
785
|
// the scale factor for a given size
|
|
778
786
|
|
|
787
|
+
STBTT_DEF void stbtt_GetFontHMetrics(const stbtt_fontinfo *info, int *vertTypoAscender, int *vertTypoDescender, int *vertTypoLineGap);
|
|
788
|
+
|
|
789
|
+
|
|
779
790
|
STBTT_DEF int stbtt_GetFontVMetricsOS2(const stbtt_fontinfo *info, int *typoAscent, int *typoDescent, int *typoLineGap);
|
|
780
791
|
// analogous to GetFontVMetrics, but returns the "typographic" values from the OS/2
|
|
781
792
|
// table (specific to MS/Windows TTF files).
|
|
@@ -785,6 +796,11 @@ STBTT_DEF int stbtt_GetFontVMetricsOS2(const stbtt_fontinfo *info, int *typoAsc
|
|
|
785
796
|
STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1);
|
|
786
797
|
// the bounding box around all possible characters
|
|
787
798
|
|
|
799
|
+
STBTT_DEF int stbtt_GetFontUnderlineMetrics(const stbtt_fontinfo *info, int *position, int *thickness);
|
|
800
|
+
// the underline position and thickness as defined in the "post" table
|
|
801
|
+
//
|
|
802
|
+
// Returns 1 on success (table present), 0 on failure.
|
|
803
|
+
|
|
788
804
|
STBTT_DEF void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing);
|
|
789
805
|
// leftSideBearing is the offset from the current horizontal position to the left edge of the character
|
|
790
806
|
// advanceWidth is the offset from the current horizontal position to the next horizontal position
|
|
@@ -797,6 +813,7 @@ STBTT_DEF int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, i
|
|
|
797
813
|
// Gets the bounding box of the visible part of the glyph, in unscaled coordinates
|
|
798
814
|
|
|
799
815
|
STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing);
|
|
816
|
+
STBTT_DEF void stbtt_GetGlyphVMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceHeight, int *topSideBearing);
|
|
800
817
|
STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2);
|
|
801
818
|
STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1);
|
|
802
819
|
// as above, but takes one or more glyph indices for greater efficiency
|
|
@@ -881,7 +898,7 @@ STBTT_DEF unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, fl
|
|
|
881
898
|
// xoff/yoff are the offset it pixel space from the glyph origin to the top-left of the bitmap
|
|
882
899
|
|
|
883
900
|
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);
|
|
884
|
-
// the same as
|
|
901
|
+
// the same as stbtt_GetCodepointBitmap, but you can specify a subpixel
|
|
885
902
|
// shift for the character
|
|
886
903
|
|
|
887
904
|
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);
|
|
@@ -1038,9 +1055,12 @@ STBTT_DEF const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *l
|
|
|
1038
1055
|
// and puts the length in bytes in *length.
|
|
1039
1056
|
//
|
|
1040
1057
|
// some of the values for the IDs are below; for more see the truetype spec:
|
|
1041
|
-
//
|
|
1058
|
+
// https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html
|
|
1042
1059
|
// http://www.microsoft.com/typography/otspec/name.htm
|
|
1043
1060
|
|
|
1061
|
+
STBTT_DEF int stbtt_GetFontNameDefault(const stbtt_fontinfo *font, char *output_buffer, size_t output_buffer_len);
|
|
1062
|
+
// return the default english full name of the font as utf-8
|
|
1063
|
+
|
|
1044
1064
|
enum { // platformID
|
|
1045
1065
|
STBTT_PLATFORM_ID_UNICODE =0,
|
|
1046
1066
|
STBTT_PLATFORM_ID_MAC =1,
|
|
@@ -1384,6 +1404,7 @@ static int stbtt_InitFont_internal(stbtt_fontinfo *info, unsigned char *data, in
|
|
|
1384
1404
|
{
|
|
1385
1405
|
stbtt_uint32 cmap, t;
|
|
1386
1406
|
stbtt_int32 i,numTables;
|
|
1407
|
+
stbtt_uint32 symbol_map=0;
|
|
1387
1408
|
|
|
1388
1409
|
info->data = data;
|
|
1389
1410
|
info->fontstart = fontstart;
|
|
@@ -1395,6 +1416,8 @@ static int stbtt_InitFont_internal(stbtt_fontinfo *info, unsigned char *data, in
|
|
|
1395
1416
|
info->glyf = stbtt__find_table(data, fontstart, "glyf"); // required
|
|
1396
1417
|
info->hhea = stbtt__find_table(data, fontstart, "hhea"); // required
|
|
1397
1418
|
info->hmtx = stbtt__find_table(data, fontstart, "hmtx"); // required
|
|
1419
|
+
info->vhea = stbtt__find_table(data, fontstart, "vhea"); // not required
|
|
1420
|
+
info->vmtx = stbtt__find_table(data, fontstart, "vmtx"); // not required
|
|
1398
1421
|
info->kern = stbtt__find_table(data, fontstart, "kern"); // not required
|
|
1399
1422
|
info->gpos = stbtt__find_table(data, fontstart, "GPOS"); // not required
|
|
1400
1423
|
|
|
@@ -1477,6 +1500,9 @@ static int stbtt_InitFont_internal(stbtt_fontinfo *info, unsigned char *data, in
|
|
|
1477
1500
|
// MS/Unicode
|
|
1478
1501
|
info->index_map = cmap + ttULONG(data+encoding_record+4);
|
|
1479
1502
|
break;
|
|
1503
|
+
case STBTT_MS_EID_SYMBOL:
|
|
1504
|
+
symbol_map = cmap + ttULONG(data+encoding_record+4);
|
|
1505
|
+
break;
|
|
1480
1506
|
}
|
|
1481
1507
|
break;
|
|
1482
1508
|
case STBTT_PLATFORM_ID_UNICODE:
|
|
@@ -1486,6 +1512,9 @@ static int stbtt_InitFont_internal(stbtt_fontinfo *info, unsigned char *data, in
|
|
|
1486
1512
|
break;
|
|
1487
1513
|
}
|
|
1488
1514
|
}
|
|
1515
|
+
if (info->index_map == 0)
|
|
1516
|
+
info->index_map = symbol_map;
|
|
1517
|
+
|
|
1489
1518
|
if (info->index_map == 0)
|
|
1490
1519
|
return 0;
|
|
1491
1520
|
|
|
@@ -1499,6 +1528,7 @@ STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codep
|
|
|
1499
1528
|
stbtt_uint32 index_map = info->index_map;
|
|
1500
1529
|
|
|
1501
1530
|
stbtt_uint16 format = ttUSHORT(data + index_map + 0);
|
|
1531
|
+
|
|
1502
1532
|
if (format == 0) { // apple byte encoding
|
|
1503
1533
|
stbtt_int32 bytes = ttUSHORT(data + index_map + 2);
|
|
1504
1534
|
if (unicode_codepoint < bytes-6)
|
|
@@ -1544,19 +1574,35 @@ STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codep
|
|
|
1544
1574
|
search += 2;
|
|
1545
1575
|
|
|
1546
1576
|
{
|
|
1547
|
-
stbtt_uint16 offset, start, last;
|
|
1577
|
+
stbtt_uint16 offset, start, last, index;
|
|
1578
|
+
stbtt_int16 delta;
|
|
1548
1579
|
stbtt_uint16 item = (stbtt_uint16) ((search - endCount) >> 1);
|
|
1549
1580
|
|
|
1581
|
+
// get the actual range for this segment
|
|
1550
1582
|
start = ttUSHORT(data + index_map + 14 + segcount*2 + 2 + 2*item);
|
|
1551
1583
|
last = ttUSHORT(data + endCount + 2*item);
|
|
1552
1584
|
if (unicode_codepoint < start || unicode_codepoint > last)
|
|
1553
1585
|
return 0;
|
|
1554
1586
|
|
|
1555
1587
|
offset = ttUSHORT(data + index_map + 14 + segcount*6 + 2 + 2*item);
|
|
1588
|
+
delta = ttSHORT(data + index_map + 14 + segcount*4 + 2 + 2*item);
|
|
1589
|
+
|
|
1590
|
+
// "if idRangeOffset is 0, the idDelta value is added directly to the character code"
|
|
1556
1591
|
if (offset == 0)
|
|
1557
|
-
return (stbtt_uint16) (unicode_codepoint +
|
|
1592
|
+
return (stbtt_uint16) (unicode_codepoint + delta);
|
|
1593
|
+
|
|
1594
|
+
// "If the idRangeOffset value for the segment is not 0, ..."
|
|
1595
|
+
// "glyphIndexAddress = idRangeOffset[i] + 2 * (c - startCode[i]) + (Ptr) &idRangeOffset[i]"
|
|
1596
|
+
index = ttUSHORT(data + offset + (unicode_codepoint-start)*2 + index_map + 14 + segcount*6 + 2 + 2*item);
|
|
1558
1597
|
|
|
1559
|
-
|
|
1598
|
+
// "Once the glyph indexing operation is complete, the glyph ID at the indicated address
|
|
1599
|
+
// is checked. If it's not 0 (that is, if it's not the missing glyph), the value is added
|
|
1600
|
+
// to idDelta[i] to get the actual glyph ID to use."
|
|
1601
|
+
if (index != 0) {
|
|
1602
|
+
index = (stbtt_uint16) (index + delta);
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
return index;
|
|
1560
1606
|
}
|
|
1561
1607
|
} else if (format == 12 || format == 13) {
|
|
1562
1608
|
stbtt_uint32 ngroups = ttULONG(data+index_map+12);
|
|
@@ -1625,7 +1671,7 @@ static int stbtt__GetGlyphInfoT2(const stbtt_fontinfo *info, int glyph_index, in
|
|
|
1625
1671
|
STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1)
|
|
1626
1672
|
{
|
|
1627
1673
|
if (info->cff.size) {
|
|
1628
|
-
stbtt__GetGlyphInfoT2(info, glyph_index, x0, y0, x1, y1);
|
|
1674
|
+
return stbtt__GetGlyphInfoT2(info, glyph_index, x0, y0, x1, y1);
|
|
1629
1675
|
} else {
|
|
1630
1676
|
int g = stbtt__GetGlyfOffset(info, glyph_index);
|
|
1631
1677
|
if (g < 0) return 0;
|
|
@@ -1767,8 +1813,8 @@ static int stbtt__GetGlyphShapeTT(const stbtt_fontinfo *info, int glyph_index, s
|
|
|
1767
1813
|
if (i != 0)
|
|
1768
1814
|
num_vertices = stbtt__close_shape(vertices, num_vertices, was_off, start_off, sx,sy,scx,scy,cx,cy);
|
|
1769
1815
|
|
|
1770
|
-
// now start the new one
|
|
1771
|
-
start_off = !(flags & 1);
|
|
1816
|
+
// now start the new one... avoid looking ahead if we're at the end of a contour
|
|
1817
|
+
start_off = !(flags & 1) && i < ttUSHORT(endPtsOfContours+j*2);
|
|
1772
1818
|
if (start_off) {
|
|
1773
1819
|
// if we start off with an off-curve point, then when we need to find a point on the curve
|
|
1774
1820
|
// where we can start, and we need to save some state for when we wraparound.
|
|
@@ -1851,23 +1897,35 @@ static int stbtt__GetGlyphShapeTT(const stbtt_fontinfo *info, int glyph_index, s
|
|
|
1851
1897
|
mtx[3] = ttSHORT(comp)/16384.0f; comp+=2;
|
|
1852
1898
|
}
|
|
1853
1899
|
|
|
1854
|
-
// Find transformation scales.
|
|
1900
|
+
// Find transformation scales. Per TrueType spec, these are used
|
|
1901
|
+
// ONLY to rescale the offsets (mtx[4], mtx[5]) when
|
|
1902
|
+
// SCALED_COMPONENT_OFFSET (flag bit 11, 0x800) is set. They must
|
|
1903
|
+
// NOT scale the linear part of the transform — doing so squares
|
|
1904
|
+
// the scale factor and is the cause of composite sub-components
|
|
1905
|
+
// rendering at wrong sizes in COLR emoji fonts (OpenMoji, Noto
|
|
1906
|
+
// Color Emoji, Microsoft Fluent Emoji).
|
|
1855
1907
|
m = (float) STBTT_sqrt(mtx[0]*mtx[0] + mtx[1]*mtx[1]);
|
|
1856
1908
|
n = (float) STBTT_sqrt(mtx[2]*mtx[2] + mtx[3]*mtx[3]);
|
|
1909
|
+
// Default: UNSCALED offsets (Microsoft convention; matches modern
|
|
1910
|
+
// font tooling). Only SCALED_COMPONENT_OFFSET (bit 11) set without
|
|
1911
|
+
// UNSCALED_COMPONENT_OFFSET (bit 12) triggers the offset rescale.
|
|
1912
|
+
if ((flags & (1<<11)) && !(flags & (1<<12))) {
|
|
1913
|
+
mtx[4] *= m; mtx[5] *= n;
|
|
1914
|
+
}
|
|
1857
1915
|
|
|
1858
1916
|
// Get indexed glyph.
|
|
1859
1917
|
comp_num_verts = stbtt_GetGlyphShape(info, gidx, &comp_verts);
|
|
1860
1918
|
if (comp_num_verts > 0) {
|
|
1861
|
-
// Transform vertices.
|
|
1919
|
+
// Transform vertices: v' = M·v + t. No double-scaling.
|
|
1862
1920
|
for (i = 0; i < comp_num_verts; ++i) {
|
|
1863
1921
|
stbtt_vertex* v = &comp_verts[i];
|
|
1864
1922
|
stbtt_vertex_type x,y;
|
|
1865
1923
|
x=v->x; y=v->y;
|
|
1866
|
-
v->x = (stbtt_vertex_type)(
|
|
1867
|
-
v->y = (stbtt_vertex_type)(
|
|
1924
|
+
v->x = (stbtt_vertex_type)(mtx[0]*x + mtx[2]*y + mtx[4]);
|
|
1925
|
+
v->y = (stbtt_vertex_type)(mtx[1]*x + mtx[3]*y + mtx[5]);
|
|
1868
1926
|
x=v->cx; y=v->cy;
|
|
1869
|
-
v->cx = (stbtt_vertex_type)(
|
|
1870
|
-
v->cy = (stbtt_vertex_type)(
|
|
1927
|
+
v->cx = (stbtt_vertex_type)(mtx[0]*x + mtx[2]*y + mtx[4]);
|
|
1928
|
+
v->cy = (stbtt_vertex_type)(mtx[1]*x + mtx[3]*y + mtx[5]);
|
|
1871
1929
|
}
|
|
1872
1930
|
// Append vertices.
|
|
1873
1931
|
tmp = (stbtt_vertex*)STBTT_malloc((num_vertices+comp_num_verts)*sizeof(stbtt_vertex), info->userdata);
|
|
@@ -2003,7 +2061,7 @@ static stbtt__buf stbtt__cid_get_glyph_subrs(const stbtt_fontinfo *info, int gly
|
|
|
2003
2061
|
start = end;
|
|
2004
2062
|
}
|
|
2005
2063
|
}
|
|
2006
|
-
if (fdselector == -1) stbtt__new_buf(NULL, 0);
|
|
2064
|
+
if (fdselector == -1) return stbtt__new_buf(NULL, 0);
|
|
2007
2065
|
return stbtt__get_subrs(info->cff, stbtt__cff_index_get(info->fontdicts, fdselector));
|
|
2008
2066
|
}
|
|
2009
2067
|
|
|
@@ -2314,6 +2372,12 @@ STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_inde
|
|
|
2314
2372
|
}
|
|
2315
2373
|
}
|
|
2316
2374
|
|
|
2375
|
+
STBTT_DEF void stbtt_GetGlyphVMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceHeight, int *topSideBearing)
|
|
2376
|
+
{
|
|
2377
|
+
if (advanceHeight) *advanceHeight = ttSHORT(info->data + info->vmtx + 4*glyph_index);
|
|
2378
|
+
if (topSideBearing) *topSideBearing = ttSHORT(info->data + info->vmtx + 4*glyph_index + 2);
|
|
2379
|
+
}
|
|
2380
|
+
|
|
2317
2381
|
STBTT_DEF int stbtt_GetKerningTableLength(const stbtt_fontinfo *info)
|
|
2318
2382
|
{
|
|
2319
2383
|
stbtt_uint8 *data = info->data + info->kern;
|
|
@@ -2506,7 +2570,7 @@ static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, in
|
|
|
2506
2570
|
data = info->data + info->gpos;
|
|
2507
2571
|
|
|
2508
2572
|
if (ttUSHORT(data+0) != 1) return 0; // Major version 1
|
|
2509
|
-
if (ttUSHORT(data+2)
|
|
2573
|
+
if (ttUSHORT(data+2) > 1) return 0; // Minor version 0, or 1
|
|
2510
2574
|
|
|
2511
2575
|
lookupListOffset = ttUSHORT(data+8);
|
|
2512
2576
|
lookupList = data + lookupListOffset;
|
|
@@ -2519,15 +2583,28 @@ static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, in
|
|
|
2519
2583
|
stbtt_uint16 lookupType = ttUSHORT(lookupTable);
|
|
2520
2584
|
stbtt_uint16 subTableCount = ttUSHORT(lookupTable + 4);
|
|
2521
2585
|
stbtt_uint8 *subTableOffsets = lookupTable + 6;
|
|
2522
|
-
if (lookupType != 2
|
|
2586
|
+
if (lookupType != 2 && // Pair Adjustment Positioning Subtable
|
|
2587
|
+
lookupType != 9) // Positioning Subtable Extension
|
|
2523
2588
|
continue;
|
|
2524
2589
|
|
|
2525
2590
|
for (sti=0; sti<subTableCount; sti++) {
|
|
2526
2591
|
stbtt_uint16 subtableOffset = ttUSHORT(subTableOffsets + 2 * sti);
|
|
2527
2592
|
stbtt_uint8 *table = lookupTable + subtableOffset;
|
|
2528
|
-
stbtt_uint16 posFormat
|
|
2529
|
-
stbtt_uint16 coverageOffset
|
|
2530
|
-
stbtt_int32 coverageIndex
|
|
2593
|
+
stbtt_uint16 posFormat;
|
|
2594
|
+
stbtt_uint16 coverageOffset;
|
|
2595
|
+
stbtt_int32 coverageIndex;
|
|
2596
|
+
if (lookupType == 9) {
|
|
2597
|
+
stbtt_uint32 exOffset;
|
|
2598
|
+
if (ttUSHORT(table + 0) != 1) // Format 1
|
|
2599
|
+
continue;
|
|
2600
|
+
if (ttUSHORT(table + 2) != 2) // PairPos Subtable
|
|
2601
|
+
continue;
|
|
2602
|
+
exOffset = ttULONG(table + 4);
|
|
2603
|
+
table += exOffset;
|
|
2604
|
+
}
|
|
2605
|
+
posFormat = ttUSHORT(table);
|
|
2606
|
+
coverageOffset = ttUSHORT(table + 2);
|
|
2607
|
+
coverageIndex = stbtt__GetCoverageIndex(table + coverageOffset, glyph1);
|
|
2531
2608
|
if (coverageIndex == -1) continue;
|
|
2532
2609
|
|
|
2533
2610
|
switch (posFormat) {
|
|
@@ -2536,8 +2613,10 @@ static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, in
|
|
|
2536
2613
|
int straw, needle;
|
|
2537
2614
|
stbtt_uint16 valueFormat1 = ttUSHORT(table + 4);
|
|
2538
2615
|
stbtt_uint16 valueFormat2 = ttUSHORT(table + 6);
|
|
2539
|
-
if (valueFormat1 == 4
|
|
2540
|
-
|
|
2616
|
+
if ((valueFormat1 == 4 ||
|
|
2617
|
+
valueFormat1 == 68) &&
|
|
2618
|
+
valueFormat2 == 0) { // Support more formats?
|
|
2619
|
+
stbtt_int32 valueRecordPairSizeInBytes = valueFormat1 == 68 ? 4 : 2;
|
|
2541
2620
|
stbtt_uint16 pairSetCount = ttUSHORT(table + 8);
|
|
2542
2621
|
stbtt_uint16 pairPosOffset = ttUSHORT(table + 10 + 2 * coverageIndex);
|
|
2543
2622
|
stbtt_uint8 *pairValueTable = table + pairPosOffset;
|
|
@@ -2575,7 +2654,9 @@ static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, in
|
|
|
2575
2654
|
case 2: {
|
|
2576
2655
|
stbtt_uint16 valueFormat1 = ttUSHORT(table + 4);
|
|
2577
2656
|
stbtt_uint16 valueFormat2 = ttUSHORT(table + 6);
|
|
2578
|
-
if (valueFormat1 == 4
|
|
2657
|
+
if ((valueFormat1 == 4 ||
|
|
2658
|
+
valueFormat1 == 68) &&
|
|
2659
|
+
valueFormat2 == 0) { // Support more formats?
|
|
2579
2660
|
stbtt_uint16 classDef1Offset = ttUSHORT(table + 8);
|
|
2580
2661
|
stbtt_uint16 classDef2Offset = ttUSHORT(table + 10);
|
|
2581
2662
|
int glyph1class = stbtt__GetGlyphClass(table + classDef1Offset, glyph1);
|
|
@@ -2585,13 +2666,16 @@ static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, in
|
|
|
2585
2666
|
stbtt_uint16 class2Count = ttUSHORT(table + 14);
|
|
2586
2667
|
stbtt_uint8 *class1Records, *class2Records;
|
|
2587
2668
|
stbtt_int16 xAdvance;
|
|
2669
|
+
stbtt_int32 valueRecordPairSizeInBytes;
|
|
2588
2670
|
|
|
2589
2671
|
if (glyph1class < 0 || glyph1class >= class1Count) return 0; // malformed
|
|
2590
2672
|
if (glyph2class < 0 || glyph2class >= class2Count) return 0; // malformed
|
|
2591
2673
|
|
|
2674
|
+
valueRecordPairSizeInBytes = valueFormat1 == 68 ? 4 : 2;
|
|
2675
|
+
|
|
2592
2676
|
class1Records = table + 16;
|
|
2593
|
-
class2Records = class1Records +
|
|
2594
|
-
xAdvance = ttSHORT(class2Records +
|
|
2677
|
+
class2Records = class1Records + valueRecordPairSizeInBytes * (glyph1class * class2Count);
|
|
2678
|
+
xAdvance = ttSHORT(class2Records + valueRecordPairSizeInBytes * glyph2class);
|
|
2595
2679
|
return xAdvance;
|
|
2596
2680
|
} else
|
|
2597
2681
|
return 0;
|
|
@@ -2612,9 +2696,10 @@ STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int g1, int
|
|
|
2612
2696
|
int xAdvance = 0;
|
|
2613
2697
|
|
|
2614
2698
|
if (info->gpos)
|
|
2615
|
-
xAdvance
|
|
2616
|
-
|
|
2617
|
-
|
|
2699
|
+
xAdvance = stbtt__GetGlyphGPOSInfoAdvance(info, g1, g2);
|
|
2700
|
+
|
|
2701
|
+
if (info->kern && xAdvance == 0)
|
|
2702
|
+
xAdvance = stbtt__GetGlyphKernInfoAdvance(info, g1, g2);
|
|
2618
2703
|
|
|
2619
2704
|
return xAdvance;
|
|
2620
2705
|
}
|
|
@@ -2631,6 +2716,11 @@ STBTT_DEF void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepo
|
|
|
2631
2716
|
stbtt_GetGlyphHMetrics(info, stbtt_FindGlyphIndex(info,codepoint), advanceWidth, leftSideBearing);
|
|
2632
2717
|
}
|
|
2633
2718
|
|
|
2719
|
+
STBTT_DEF void stbtt_GetCodepointVMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceHeight, int *topSideBearing)
|
|
2720
|
+
{
|
|
2721
|
+
stbtt_GetGlyphVMetrics(info, stbtt_FindGlyphIndex(info,codepoint), advanceHeight, topSideBearing);
|
|
2722
|
+
}
|
|
2723
|
+
|
|
2634
2724
|
STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap)
|
|
2635
2725
|
{
|
|
2636
2726
|
if (ascent ) *ascent = ttSHORT(info->data+info->hhea + 4);
|
|
@@ -2638,6 +2728,13 @@ STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, in
|
|
|
2638
2728
|
if (lineGap) *lineGap = ttSHORT(info->data+info->hhea + 8);
|
|
2639
2729
|
}
|
|
2640
2730
|
|
|
2731
|
+
STBTT_DEF void stbtt_GetFontHMetrics(const stbtt_fontinfo *info, int *vertTypoAscender, int *vertTypoDescender, int *vertTypoLineGap)
|
|
2732
|
+
{
|
|
2733
|
+
if (vertTypoAscender ) *vertTypoAscender = ttSHORT(info->data+info->vhea + 4);
|
|
2734
|
+
if (vertTypoDescender) *vertTypoDescender = ttSHORT(info->data+info->vhea + 6);
|
|
2735
|
+
if (vertTypoLineGap) *vertTypoLineGap = ttSHORT(info->data+info->vhea + 8);
|
|
2736
|
+
}
|
|
2737
|
+
|
|
2641
2738
|
STBTT_DEF int stbtt_GetFontVMetricsOS2(const stbtt_fontinfo *info, int *typoAscent, int *typoDescent, int *typoLineGap)
|
|
2642
2739
|
{
|
|
2643
2740
|
int tab = stbtt__find_table(info->data, info->fontstart, "OS/2");
|
|
@@ -2657,12 +2754,28 @@ STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int
|
|
|
2657
2754
|
*y1 = ttSHORT(info->data + info->head + 42);
|
|
2658
2755
|
}
|
|
2659
2756
|
|
|
2757
|
+
STBTT_DEF int stbtt_GetFontUnderlineMetrics(const stbtt_fontinfo *info, int *position, int *thickness)
|
|
2758
|
+
{
|
|
2759
|
+
int tab = stbtt__find_table(info->data, info->fontstart, "post");
|
|
2760
|
+
if (!tab)
|
|
2761
|
+
return 0;
|
|
2762
|
+
*position = ttSHORT(info->data + tab + 8);
|
|
2763
|
+
*thickness = ttSHORT(info->data + tab + 10);
|
|
2764
|
+
return 1;
|
|
2765
|
+
}
|
|
2766
|
+
|
|
2660
2767
|
STBTT_DEF float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float height)
|
|
2661
2768
|
{
|
|
2662
2769
|
int fheight = ttSHORT(info->data + info->hhea + 4) - ttSHORT(info->data + info->hhea + 6);
|
|
2663
2770
|
return (float) height / fheight;
|
|
2664
2771
|
}
|
|
2665
2772
|
|
|
2773
|
+
STBTT_DEF float stbtt_ScaleForPixelWidth(const stbtt_fontinfo *info, float width)
|
|
2774
|
+
{
|
|
2775
|
+
int fwidth = ttSHORT(info->data + info->hhea + 10) - ttSHORT(info->data + info->hhea + 12);
|
|
2776
|
+
return (float) width / fwidth;
|
|
2777
|
+
}
|
|
2778
|
+
|
|
2666
2779
|
STBTT_DEF float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels)
|
|
2667
2780
|
{
|
|
2668
2781
|
int unitsPerEm = ttUSHORT(info->data + info->head + 18);
|
|
@@ -3195,8 +3308,10 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill,
|
|
|
3195
3308
|
|
|
3196
3309
|
// check if final y_crossing is blown up; no test case for this
|
|
3197
3310
|
if (y_final > y_bottom) {
|
|
3311
|
+
int denom = (x2 - (x1+1));
|
|
3198
3312
|
y_final = y_bottom;
|
|
3199
|
-
|
|
3313
|
+
if (denom != 0)
|
|
3314
|
+
dy = (y_final - y_crossing ) / denom; // if denom=0, y_final = y_crossing, so y_final <= y_bottom
|
|
3200
3315
|
}
|
|
3201
3316
|
|
|
3202
3317
|
// in second pixel, area covered by line segment found in first pixel
|
|
@@ -4207,7 +4322,7 @@ STBTT_DEF void stbtt_MakeGlyphBitmapSubpixelPrefilter(const stbtt_fontinfo *info
|
|
|
4207
4322
|
// rects array must be big enough to accommodate all characters in the given ranges
|
|
4208
4323
|
STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
|
|
4209
4324
|
{
|
|
4210
|
-
int i,j,k, missing_glyph = -1, return_value = 1;
|
|
4325
|
+
int i,j,k, missing_range = -1, missing_glyph = -1, return_value = 1;
|
|
4211
4326
|
|
|
4212
4327
|
// save current values
|
|
4213
4328
|
int old_h_over = spc->h_oversample;
|
|
@@ -4273,12 +4388,14 @@ STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const
|
|
|
4273
4388
|
bc->xoff2 = (x0 + r->w) * recip_h + sub_x;
|
|
4274
4389
|
bc->yoff2 = (y0 + r->h) * recip_v + sub_y;
|
|
4275
4390
|
|
|
4276
|
-
if (glyph == 0)
|
|
4391
|
+
if (glyph == 0) {
|
|
4392
|
+
missing_range = i;
|
|
4277
4393
|
missing_glyph = j;
|
|
4394
|
+
}
|
|
4278
4395
|
} else if (spc->skip_missing) {
|
|
4279
4396
|
return_value = 0;
|
|
4280
4397
|
} else if (r->was_packed && r->w == 0 && r->h == 0 && missing_glyph >= 0) {
|
|
4281
|
-
ranges[i].chardata_for_range[j] = ranges[
|
|
4398
|
+
ranges[i].chardata_for_range[j] = ranges[missing_range].chardata_for_range[missing_glyph];
|
|
4282
4399
|
} else {
|
|
4283
4400
|
return_value = 0; // if any fail, report failure
|
|
4284
4401
|
}
|
|
@@ -4302,7 +4419,7 @@ STBTT_DEF void stbtt_PackFontRangesPackRects(stbtt_pack_context *spc, stbrp_rect
|
|
|
4302
4419
|
STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)
|
|
4303
4420
|
{
|
|
4304
4421
|
stbtt_fontinfo info;
|
|
4305
|
-
int i,j,n, return_value
|
|
4422
|
+
int i, j, n, return_value;
|
|
4306
4423
|
//stbrp_context *context = (stbrp_context *) spc->pack_info;
|
|
4307
4424
|
stbrp_rect *rects;
|
|
4308
4425
|
|
|
@@ -4459,7 +4576,7 @@ static int stbtt__ray_intersect_bezier(float orig[2], float ray[2], float q0[2],
|
|
|
4459
4576
|
}
|
|
4460
4577
|
}
|
|
4461
4578
|
|
|
4462
|
-
static int
|
|
4579
|
+
static int stbtt__equal(float *a, float *b)
|
|
4463
4580
|
{
|
|
4464
4581
|
return (a[0] == b[0] && a[1] == b[1]);
|
|
4465
4582
|
}
|
|
@@ -4507,7 +4624,7 @@ static int stbtt__compute_crossings_x(float x, float y, int nverts, stbtt_vertex
|
|
|
4507
4624
|
q1[1] = (float)y1;
|
|
4508
4625
|
q2[0] = (float)x2;
|
|
4509
4626
|
q2[1] = (float)y2;
|
|
4510
|
-
if (
|
|
4627
|
+
if (stbtt__equal(q0,q1) || stbtt__equal(q1,q2)) {
|
|
4511
4628
|
x0 = (int)verts[i-1].x;
|
|
4512
4629
|
y0 = (int)verts[i-1].y;
|
|
4513
4630
|
x1 = (int)verts[i ].x;
|
|
@@ -4584,8 +4701,13 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
|
|
|
4584
4701
|
stbtt_GetGlyphBitmapBoxSubpixel(info, glyph, scale, scale, 0.0f,0.0f, &ix0,&iy0,&ix1,&iy1);
|
|
4585
4702
|
|
|
4586
4703
|
// if empty, return NULL
|
|
4587
|
-
if (ix0 == ix1 || iy0 == iy1)
|
|
4704
|
+
if (ix0 == ix1 || iy0 == iy1) {
|
|
4705
|
+
if (width) *width = 0;
|
|
4706
|
+
if (height) *height = 0;
|
|
4707
|
+
if (xoff) *xoff = 0;
|
|
4708
|
+
if (yoff) *yoff = 0;
|
|
4588
4709
|
return NULL;
|
|
4710
|
+
}
|
|
4589
4711
|
|
|
4590
4712
|
ix0 -= padding;
|
|
4591
4713
|
iy0 -= padding;
|
|
@@ -4604,6 +4726,8 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
|
|
|
4604
4726
|
scale_y = -scale_y;
|
|
4605
4727
|
|
|
4606
4728
|
{
|
|
4729
|
+
// distance from singular values (in the same units as the pixel grid)
|
|
4730
|
+
const float eps = 1./1024, eps2 = eps*eps;
|
|
4607
4731
|
int x,y,i,j;
|
|
4608
4732
|
float *precompute;
|
|
4609
4733
|
stbtt_vertex *verts;
|
|
@@ -4616,15 +4740,15 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
|
|
|
4616
4740
|
float x0 = verts[i].x*scale_x, y0 = verts[i].y*scale_y;
|
|
4617
4741
|
float x1 = verts[j].x*scale_x, y1 = verts[j].y*scale_y;
|
|
4618
4742
|
float dist = (float) STBTT_sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0));
|
|
4619
|
-
precompute[i] = (dist
|
|
4743
|
+
precompute[i] = (dist < eps) ? 0.0f : 1.0f / dist;
|
|
4620
4744
|
} else if (verts[i].type == STBTT_vcurve) {
|
|
4621
4745
|
float x2 = verts[j].x *scale_x, y2 = verts[j].y *scale_y;
|
|
4622
4746
|
float x1 = verts[i].cx*scale_x, y1 = verts[i].cy*scale_y;
|
|
4623
4747
|
float x0 = verts[i].x *scale_x, y0 = verts[i].y *scale_y;
|
|
4624
4748
|
float bx = x0 - 2*x1 + x2, by = y0 - 2*y1 + y2;
|
|
4625
4749
|
float len2 = bx*bx + by*by;
|
|
4626
|
-
if (len2
|
|
4627
|
-
precompute[i] = 1.0f /
|
|
4750
|
+
if (len2 >= eps2)
|
|
4751
|
+
precompute[i] = 1.0f / len2;
|
|
4628
4752
|
else
|
|
4629
4753
|
precompute[i] = 0.0f;
|
|
4630
4754
|
} else
|
|
@@ -4689,8 +4813,8 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
|
|
|
4689
4813
|
float a = 3*(ax*bx + ay*by);
|
|
4690
4814
|
float b = 2*(ax*ax + ay*ay) + (mx*bx+my*by);
|
|
4691
4815
|
float c = mx*ax+my*ay;
|
|
4692
|
-
if (a
|
|
4693
|
-
if (b
|
|
4816
|
+
if (STBTT_fabs(a) < eps2) { // if a is 0, it's linear
|
|
4817
|
+
if (STBTT_fabs(b) >= eps2) {
|
|
4694
4818
|
res[num++] = -c/b;
|
|
4695
4819
|
}
|
|
4696
4820
|
} else {
|
|
@@ -4840,6 +4964,126 @@ STBTT_DEF const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *l
|
|
|
4840
4964
|
return NULL;
|
|
4841
4965
|
}
|
|
4842
4966
|
|
|
4967
|
+
// convert utf16 to utf8 and return the length required to output NUL-terminated; buffer_len of 0 means to just query length
|
|
4968
|
+
// if you pass a buffer that's too small, it'll NULL terminate and return the actual length computed
|
|
4969
|
+
STBTT_DEF int stbtt__ConvertUTF16BEtoUTF8(char *buffer, size_t buffer_len, unsigned char *src, size_t src_len_raw)
|
|
4970
|
+
{
|
|
4971
|
+
int src_len = (int) src_len_raw;
|
|
4972
|
+
int write_max = 0;
|
|
4973
|
+
int i = 0, write, off = 0;
|
|
4974
|
+
write = (buffer_len != 0);
|
|
4975
|
+
write_max = (int) (buffer_len-1);
|
|
4976
|
+
|
|
4977
|
+
if ((size_t) src_len != src_len_raw)
|
|
4978
|
+
return -1;
|
|
4979
|
+
|
|
4980
|
+
if (write) {
|
|
4981
|
+
if (write_max < 0 || ((size_t) write_max+1 != buffer_len && write_max != 0))
|
|
4982
|
+
return -1;
|
|
4983
|
+
}
|
|
4984
|
+
|
|
4985
|
+
if (buffer_len == 1) {
|
|
4986
|
+
buffer[0] = 0;
|
|
4987
|
+
return 1;
|
|
4988
|
+
}
|
|
4989
|
+
|
|
4990
|
+
while (off < src_len) {
|
|
4991
|
+
stbtt_uint16 ch = src[off+0]*256 + src[off+1];
|
|
4992
|
+
off += 2;
|
|
4993
|
+
if (ch < 0x80) {
|
|
4994
|
+
if (write) {
|
|
4995
|
+
if (i >= write_max) { buffer[i] = 0; return i+1; }
|
|
4996
|
+
buffer[i] = (char) ch;
|
|
4997
|
+
}
|
|
4998
|
+
++i;
|
|
4999
|
+
} else if (ch < 0x800) {
|
|
5000
|
+
if (write) {
|
|
5001
|
+
if (i+1 >= write_max) { buffer[i] = 0; return i+1; }
|
|
5002
|
+
buffer[i+0] = (char) ( 0xc0 + (ch >> 6) );
|
|
5003
|
+
buffer[i+1] = (char) ( 0x80 + (ch & 0x3f) );
|
|
5004
|
+
}
|
|
5005
|
+
i += 2;
|
|
5006
|
+
} else if (ch >= 0xd800 && ch < 0xdc00) {
|
|
5007
|
+
stbtt_uint32 c;
|
|
5008
|
+
stbtt_uint16 ch2 = src[off+0]*256 + src[off+1];
|
|
5009
|
+
off += 2;
|
|
5010
|
+
if (write) {
|
|
5011
|
+
if (i+3 >= write_max) { buffer[i] = 0; return i+1; }
|
|
5012
|
+
c = ((ch - 0xd800) << 10) + (ch2 - 0xdc00) + 0x10000;
|
|
5013
|
+
buffer[i+0] = (char) ( 0xf0 + (c >> 18) );
|
|
5014
|
+
buffer[i+1] = (char) ( 0x80 + ((c >> 12) & 0x3f) );
|
|
5015
|
+
buffer[i+2] = (char) ( 0x80 + ((c >> 6) & 0x3f) );
|
|
5016
|
+
buffer[i+3] = (char) ( 0x80 + ((c ) & 0x3f) );
|
|
5017
|
+
}
|
|
5018
|
+
i += 4;
|
|
5019
|
+
} else if (ch >= 0xdc00 && ch < 0xe000) {
|
|
5020
|
+
if (write)
|
|
5021
|
+
buffer[i] = 0;
|
|
5022
|
+
return -1;
|
|
5023
|
+
} else {
|
|
5024
|
+
if (write) {
|
|
5025
|
+
if (i+2 >= write_max) { buffer[i] = 0; return i+1; }
|
|
5026
|
+
buffer[i+0] = (char) ( 0xe0 + (ch >> 12) );
|
|
5027
|
+
buffer[i+1] = (char) ( 0x80 + ((ch >> 6) & 0x3f) );
|
|
5028
|
+
buffer[i+2] = (char) ( 0x80 + ((ch ) & 0x3f) );
|
|
5029
|
+
}
|
|
5030
|
+
i += 3;
|
|
5031
|
+
}
|
|
5032
|
+
}
|
|
5033
|
+
if (write) {
|
|
5034
|
+
STBTT_assert(i <= write_max);
|
|
5035
|
+
buffer[i] = 0;
|
|
5036
|
+
}
|
|
5037
|
+
return i+1;
|
|
5038
|
+
}
|
|
5039
|
+
|
|
5040
|
+
// Returns the english full name of the font as UTF-8
|
|
5041
|
+
STBTT_DEF int stbtt_GetFontNameDefault(const stbtt_fontinfo *font, char *buffer, size_t buffer_len)
|
|
5042
|
+
{
|
|
5043
|
+
stbtt_int32 i,count,stringOffset;
|
|
5044
|
+
stbtt_uint8 *fc = font->data;
|
|
5045
|
+
stbtt_uint32 offset = font->fontstart;
|
|
5046
|
+
stbtt_uint32 nm = stbtt__find_table(fc, offset, "name");
|
|
5047
|
+
if (!nm) return -1;
|
|
5048
|
+
|
|
5049
|
+
count = ttUSHORT(fc+nm+2);
|
|
5050
|
+
stringOffset = nm + ttUSHORT(fc+nm+4);
|
|
5051
|
+
for (i=0; i < count; ++i) {
|
|
5052
|
+
char* str;
|
|
5053
|
+
stbtt_uint16 platformId;
|
|
5054
|
+
stbtt_uint16 encodingId;
|
|
5055
|
+
stbtt_uint16 languageId;
|
|
5056
|
+
size_t length;
|
|
5057
|
+
stbtt_uint32 loc = nm + 6 + 12 * i;
|
|
5058
|
+
if (ttUSHORT(fc+loc+6) != 4) continue;
|
|
5059
|
+
platformId = ttUSHORT(fc+loc+0);
|
|
5060
|
+
encodingId = ttUSHORT(fc+loc+2);
|
|
5061
|
+
languageId = ttUSHORT(fc+loc+4);
|
|
5062
|
+
if (!(platformId == STBTT_PLATFORM_ID_MAC && languageId == STBTT_MAC_LANG_ENGLISH) && !(platformId == STBTT_PLATFORM_ID_MICROSOFT && languageId == STBTT_MS_LANG_ENGLISH))
|
|
5063
|
+
continue;
|
|
5064
|
+
|
|
5065
|
+
length = ttUSHORT(fc+loc+8);
|
|
5066
|
+
str = (char *) (fc+stringOffset+ttUSHORT(fc+loc+10));
|
|
5067
|
+
if (platformId == STBTT_PLATFORM_ID_UNICODE || (platformId == STBTT_PLATFORM_ID_MICROSOFT && (encodingId == 1 || encodingId == 10)))
|
|
5068
|
+
return stbtt__ConvertUTF16BEtoUTF8(buffer, buffer_len, (unsigned char *) str, length);
|
|
5069
|
+
else {
|
|
5070
|
+
if (buffer == NULL)
|
|
5071
|
+
return (int) length;
|
|
5072
|
+
|
|
5073
|
+
if (length < buffer_len) {
|
|
5074
|
+
memcpy(buffer, str, length);
|
|
5075
|
+
buffer[length] = 0;
|
|
5076
|
+
return (int) length;
|
|
5077
|
+
} else {
|
|
5078
|
+
memcpy(buffer, str, buffer_len-1);
|
|
5079
|
+
buffer[buffer_len-1] = 0;
|
|
5080
|
+
return (int) length;
|
|
5081
|
+
}
|
|
5082
|
+
}
|
|
5083
|
+
}
|
|
5084
|
+
return -1;
|
|
5085
|
+
}
|
|
5086
|
+
|
|
4843
5087
|
static int stbtt__matchpair(stbtt_uint8 *fc, stbtt_uint32 nm, stbtt_uint8 *name, stbtt_int32 nlen, stbtt_int32 target_id, stbtt_int32 next_id)
|
|
4844
5088
|
{
|
|
4845
5089
|
stbtt_int32 i;
|