aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/main.lua98
-rw-r--r--src/libjin/3rdparty/stb/stb_image.h2
-rw-r--r--src/libjin/3rdparty/stb/stb_truetype.h476
-rw-r--r--src/libjin/Graphics/Font.h20
-rw-r--r--src/lua/embed/boot.lua.h2
5 files changed, 445 insertions, 153 deletions
diff --git a/bin/main.lua b/bin/main.lua
index 96898cf..eeec09e 100644
--- a/bin/main.lua
+++ b/bin/main.lua
@@ -1,30 +1,25 @@
-local boundary = {
- x = 200,
- y = 100,
- w = 100,
- h = 80,
-}
-
-local bg = {
- x = 200,
- y = 100,
- w = 300,
- h = 200
-}
-local p = {
- x = boundary.x + 10,
- y = boundary.y + 10,
- speed = 100,
-}
-
+io.stdout:setvbuf("no")
+local shader
+local img
+local img2
+local canvas
+local sw, sh = jin.graphics.getSize()
function jin.core.onLoad()
-
+ local str = jin.filesystem.read("metaball.shader")
+ shader = jin.graphics.newShader(str)
+ local w, h = 256, 240
+ local bitmap = jin.graphics.newBitmap(w, h, {255, 255, 0, 255})
+ local b = bitmap:clone()
+ bitmap = nil
+ -- local bitmap2 = jin.graphics.newBitmap("img2.bmp")
+ img = jin.graphics.newTexture(b)
+ -- img2 = jin.graphics.newTexture(bitmap2)
+ canvas = jin.graphics.newCanvas(200, 200)
end
-
-local function clamp(x, a, b)
- return math.min(math.max(x, a), b)
-end
-
+-- extern vec3 iResolution;
+-- extern number iGlobalTime;
+-- extern vec4 iMouse;
+local mx, my = 0, 0
function jin.core.onEvent(e)
if e.type == "Quit" then
jin.core.stop()
@@ -32,41 +27,26 @@ function jin.core.onEvent(e)
if e.type == "KeyDown" then
if e.key == "Escape" then
jin.core.stop()
- end
- if e.key == "Left" then
- p.x = p.x - p.speed
- elseif e.key == "Right" then
- p.x = p.x + p.speed
- elseif e.key == "Up" then
- p.y = p.y - p.speed
- elseif e.key == "Down" then
- p.y = p.y + p.speed
end
- p.x = clamp(p.x, boundary.x, boundary.x + boundary.w)
- p.y = clamp(p.y, boundary.y, boundary.y + boundary.h)
- end
-end
-
-local function updateBg()
- local x0 = boundary.x
- local x1 = boundary.x + boundary.w
- local tx = (p.x - x0) / (x1 - x0)
- bg.x = tx * (x1 - x0 - bg.w) + x0
- local y0 = boundary.y
- local y1 = boundary.y + boundary.h
- local ty = (p.y - y0) / (y1 - y0)
- bg.y = ty * (y1 - y0 - bg.h) + y0
-end
-
-function jin.core.onUpdate(dt)
- updateBg()
+ end
+ if e.type == "MouseMotion" then
+ -- if e.button == "left" then
+ mx = e.x
+ my = e.y
+ -- end
+ end
end
+local dt = 0
function jin.core.onDraw()
- jin.graphics.setColor(100, 100, 100, 255)
- jin.graphics.rect("fill", bg.x, bg.y, bg.w, bg.h)
- jin.graphics.setColor(255,255,255,255)
- jin.graphics.rect("line", boundary.x, boundary.y, boundary.w, boundary.h)
- jin.graphics.setColor(255,0,0,255)
- jin.graphics.rect("fill", p.x, p.y, 3, 3)
-end
+ dt = dt + 0.1
+ jin.graphics.bindCanvas(canvas)
+ jin.graphics.useShader(shader)
+ shader:sendNumber("iGlobalTime", dt )
+ shader:sendVec3("iResolution", {sw, sh, 1})
+ shader:sendVec4("iMouse", {mx, my, mx, my})
+ jin.graphics.draw(img, 0, 0, 1, 1)
+ jin.graphics.unuseShader()
+ jin.graphics.unbindCanvas()
+ jin.graphics.draw(canvas, 0, 0, 2, 2)
+end \ No newline at end of file
diff --git a/src/libjin/3rdparty/stb/stb_image.h b/src/libjin/3rdparty/stb/stb_image.h
index 72e0ae6..9624869 100644
--- a/src/libjin/3rdparty/stb/stb_image.h
+++ b/src/libjin/3rdparty/stb/stb_image.h
@@ -22,7 +22,7 @@
JPEG baseline & progressive (12 bpc/arithmetic not supported, same as stock IJG lib)
PNG 1/2/4/8/16-bit-per-channel
-
+
TGA (not sure what subset, if a subset)
BMP non-1bpp, non-RLE
PSD (composited view only, no extra channels, 8/16 bit-per-channel)
diff --git a/src/libjin/3rdparty/stb/stb_truetype.h b/src/libjin/3rdparty/stb/stb_truetype.h
index cb8f4c2..927ee21 100644
--- a/src/libjin/3rdparty/stb/stb_truetype.h
+++ b/src/libjin/3rdparty/stb/stb_truetype.h
@@ -1,4 +1,4 @@
-// stb_truetype.h - v1.16 - public domain
+// stb_truetype.h - v1.19 - public domain
// authored from 2009-2016 by Sean Barrett / RAD Game Tools
//
// This library processes TrueType files:
@@ -22,39 +22,36 @@
// Mikko Mononen: compound shape support, more cmap formats
// Tor Andersson: kerning, subpixel rendering
// Dougall Johnson: OpenType / Type 2 font handling
+// Daniel Ribeiro Maciel: basic GPOS-based kerning
//
// Misc other:
// Ryan Gordon
// Simon Glass
// github:IntellectualKitty
+// Imanol Celaya
+// Daniel Ribeiro Maciel
//
// Bug/warning reports/fixes:
-// "Zer" on mollyrocket
-// Cass Everitt
-// stoiko (Haemimont Games)
-// Brian Hook
-// Walter van Niftrik
-// David Gow
-// David Given
-// Ivan-Assen Ivanov
-// Anthony Pesch
-// Johan Duparc
-// Hou Qiming
-// Fabian "ryg" Giesen
-// Martins Mozeiko
-// Cap Petschulat
-// Omar Cornut
-// github:aloucks
-// Peter LaValle
-// Sergey Popov
-// Giumo X. Clanjor
-// Higor Euripedes
-// Thomas Fields
-// Derek Vinyard
-// Cort Stratton
-//
+// "Zer" on mollyrocket Fabian "ryg" Giesen
+// Cass Everitt Martins Mozeiko
+// stoiko (Haemimont Games) Cap Petschulat
+// Brian Hook Omar Cornut
+// Walter van Niftrik github:aloucks
+// David Gow Peter LaValle
+// David Given Sergey Popov
+// Ivan-Assen Ivanov Giumo X. Clanjor
+// Anthony Pesch Higor Euripedes
+// Johan Duparc Thomas Fields
+// Hou Qiming Derek Vinyard
+// Rob Loach Cort Stratton
+// Kenney Phillis Jr. github:oyvindjam
+// Brian Costabile github:vassvik
+//
// VERSION HISTORY
//
+// 1.19 (2018-02-11) GPOS kerning, STBTT_fmod
+// 1.18 (2018-01-29) add missing function
+// 1.17 (2017-07-23) make more arguments const; doc fix
// 1.16 (2017-07-12) SDF support
// 1.15 (2017-03-03) make more arguments const
// 1.14 (2017-01-16) num-fonts-in-TTC function
@@ -94,7 +91,7 @@
// Improved 3D API (more shippable):
// #include "stb_rect_pack.h" -- optional, but you really want it
// stbtt_PackBegin()
-// stbtt_PackSetOversample() -- for improved quality on small fonts
+// stbtt_PackSetOversampling() -- for improved quality on small fonts
// stbtt_PackFontRanges() -- pack and renders
// stbtt_PackEnd()
// stbtt_GetPackedQuad()
@@ -112,6 +109,7 @@
// Character advance/positioning
// stbtt_GetCodepointHMetrics()
// stbtt_GetFontVMetrics()
+// stbtt_GetFontVMetricsOS2()
// stbtt_GetCodepointKernAdvance()
//
// Starting with version 1.06, the rasterizer was replaced with a new,
@@ -167,7 +165,7 @@
// measurement for describing font size, defined as 72 points per inch.
// stb_truetype provides a point API for compatibility. However, true
// "per inch" conventions don't make much sense on computer displays
-// since they different monitors have different number of pixels per
+// since different monitors have different number of pixels per
// inch. For example, Windows traditionally uses a convention that
// there are 96 pixels per inch, thus making 'inch' measurements have
// nothing to do with inches, and thus effectively defining a point to
@@ -177,6 +175,39 @@
// for non-commercial fonts, thus making fonts scaled in points
// according to the TrueType spec incoherently sized in practice.
//
+// DETAILED USAGE:
+//
+// Scale:
+// Select how high you want the font to be, in points or pixels.
+// Call ScaleForPixelHeight or ScaleForMappingEmToPixels to compute
+// a scale factor SF that will be used by all other functions.
+//
+// Baseline:
+// You need to select a y-coordinate that is the baseline of where
+// your text will appear. Call GetFontBoundingBox to get the baseline-relative
+// bounding box for all characters. SF*-y0 will be the distance in pixels
+// that the worst-case character could extend above the baseline, so if
+// you want the top edge of characters to appear at the top of the
+// screen where y=0, then you would set the baseline to SF*-y0.
+//
+// Current point:
+// Set the current point where the first character will appear. The
+// first character could extend left of the current point; this is font
+// dependent. You can either choose a current point that is the leftmost
+// point and hope, or add some padding, or check the bounding box or
+// left-side-bearing of the first character to be displayed and set
+// the current point based on that.
+//
+// Displaying a character:
+// Compute the bounding box of the character. It will contain signed values
+// relative to <current_point, baseline>. I.e. if it returns x0,y0,x1,y1,
+// then the character should be displayed in the rectangle from
+// <current_point+SF*x0, baseline+SF*y0> to <current_point+SF*x1,baseline+SF*y1).
+//
+// Advancing for the next character:
+// Call GlyphHMetrics, and compute 'current_point += SF * advance'.
+//
+//
// ADVANCED USAGE
//
// Quality:
@@ -258,7 +289,7 @@ void my_stbtt_initfont(void)
glGenTextures(1, &ftex);
glBindTexture(GL_TEXTURE_2D, ftex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 512, 512, 0, GL_ALPHA, GL_UNSIGNED_BYTE, temp_bitmap);
-
+ // can free temp_bitmap at this point
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
@@ -362,7 +393,7 @@ int main(int arg, char **argv)
// "alpha blend" that into the working buffer
xpos += (advance * scale);
if (text[ch + 1])
- xpos += scale*stbtt_GetCodepointKernAdvance(&font, text[ch], text[ch + 1]);
+ xpos += scale * stbtt_GetCodepointKernAdvance(&font, text[ch], text[ch + 1]);
++ch;
}
@@ -383,7 +414,8 @@ int main(int arg, char **argv)
//// INTEGRATION WITH YOUR CODEBASE
////
//// The following sections allow you to supply alternate definitions
-//// of C library functions used by stb_truetype.
+//// of C library functions used by stb_truetype, e.g. if you don't
+//// link with the C runtime library.
#ifdef STB_TRUETYPE_IMPLEMENTATION
// #define your own (u)stbtt_int8/16/32 before including to override this
@@ -399,7 +431,7 @@ typedef signed int stbtt_int32;
typedef char stbtt__check_size32[sizeof(stbtt_int32) == 4 ? 1 : -1];
typedef char stbtt__check_size16[sizeof(stbtt_int16) == 2 ? 1 : -1];
-// #define your own STBTT_ifloor/STBTT_iceil() to avoid math.h
+// e.g. #define your own STBTT_ifloor/STBTT_iceil() to avoid math.h
#ifndef STBTT_ifloor
#include <math.h>
#define STBTT_ifloor(x) ((int) floor(x))
@@ -412,15 +444,15 @@ typedef char stbtt__check_size16[sizeof(stbtt_int16) == 2 ? 1 : -1];
#define STBTT_pow(x,y) pow(x,y)
#endif
-#ifndef STBTT_cos
+#ifndef STBTT_fmod
#include <math.h>
-#define STBTT_cos(x) cos(x)
-#define STBTT_acos(x) acos(x)
+#define STBTT_fmod(x,y) fmod(x,y)
#endif
-#ifndef STBTT_fabs
+#ifndef STBTT_cos
#include <math.h>
-#define STBTT_fabs(x) fabs(x)
+#define STBTT_cos(x) cos(x)
+#define STBTT_acos(x) acos(x)
#endif
#ifndef STBTT_fabs
@@ -562,7 +594,7 @@ extern "C" {
#define STBTT_POINT_SIZE(x) (-(x))
- STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,
+ STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, float font_size,
int first_unicode_char_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range);
// Creates character bitmaps from the font_index'th font found in fontdata (use
// font_index=0 if you don't know what that is). It creates num_chars_in_range
@@ -587,7 +619,7 @@ extern "C" {
unsigned char h_oversample, v_oversample; // don't set these, they're used internally
} stbtt_pack_range;
- STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges);
+ STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges);
// Creates character bitmaps from multiple ranges of characters stored in
// ranges. This will usually create a better-packed bitmap than multiple
// calls to stbtt_PackFontRange. Note that you can call this multiple
@@ -672,7 +704,7 @@ extern "C" {
int numGlyphs; // number of glyphs, needed for range checking
- int loca, head, glyf, hhea, hmtx, kern; // table locations as offset from start of .ttf
+ int loca, head, glyf, hhea, hmtx, kern, gpos; // table locations as offset from start of .ttf
int index_map; // a cmap mapping for our chosen character encoding
int indexToLocFormat; // format needed to map from glyph index to glyph
@@ -729,6 +761,12 @@ extern "C" {
// these are expressed in unscaled coordinates, so you must multiply by
// the scale factor for a given size
+ STBTT_DEF int stbtt_GetFontVMetricsOS2(const stbtt_fontinfo *info, int *typoAscent, int *typoDescent, int *typoLineGap);
+ // analogous to GetFontVMetrics, but returns the "typographic" values from the OS/2
+ // table (specific to MS/Windows TTF files).
+ //
+ // Returns 1 on success (table present), 0 on failure.
+
STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1);
// the bounding box around all possible characters
@@ -1310,6 +1348,7 @@ static int stbtt_InitFont_internal(stbtt_fontinfo *info, unsigned char *data, in
info->hhea = stbtt__find_table(data, fontstart, "hhea"); // required
info->hmtx = stbtt__find_table(data, fontstart, "hmtx"); // required
info->kern = stbtt__find_table(data, fontstart, "kern"); // not required
+ info->gpos = stbtt__find_table(data, fontstart, "GPOS"); // not required
if (!cmap || !info->head || !info->hhea || !info->hmtx)
return 0;
@@ -2186,7 +2225,7 @@ static int stbtt__run_charstring(const stbtt_fontinfo *info, int glyph_index, st
// push immediate
if (b0 == 255) {
- f = (float)stbtt__buf_get32(&b) / 0x10000;
+ f = (float)(stbtt_int32)stbtt__buf_get32(&b) / 0x10000;
}
else {
stbtt__buf_skip(&b, -1);
@@ -2225,12 +2264,10 @@ static int stbtt__GetGlyphInfoT2(const stbtt_fontinfo *info, int glyph_index, in
{
stbtt__csctx c = STBTT__CSCTX_INIT(1);
int r = stbtt__run_charstring(info, glyph_index, &c);
- if (x0) {
- *x0 = r ? c.min_x : 0;
- *y0 = r ? c.min_y : 0;
- *x1 = r ? c.max_x : 0;
- *y1 = r ? c.max_y : 0;
- }
+ if (x0) *x0 = r ? c.min_x : 0;
+ if (y0) *y0 = r ? c.min_y : 0;
+ if (x1) *x1 = r ? c.max_x : 0;
+ if (y1) *y1 = r ? c.max_y : 0;
return r ? c.num_vertices : 0;
}
@@ -2255,7 +2292,7 @@ STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_inde
}
}
-STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2)
+static int stbtt__GetGlyphKernInfoAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2)
{
stbtt_uint8 *data = info->data + info->kern;
stbtt_uint32 needle, straw;
@@ -2285,9 +2322,260 @@ STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1,
return 0;
}
+static stbtt_int32 stbtt__GetCoverageIndex(stbtt_uint8 *coverageTable, int glyph)
+{
+ stbtt_uint16 coverageFormat = ttUSHORT(coverageTable);
+ switch (coverageFormat) {
+ case 1: {
+ stbtt_uint16 glyphCount = ttUSHORT(coverageTable + 2);
+
+ // Binary search.
+ stbtt_int32 l = 0, r = glyphCount - 1, m;
+ int straw, needle = glyph;
+ while (l <= r) {
+ stbtt_uint8 *glyphArray = coverageTable + 4;
+ stbtt_uint16 glyphID;
+ m = (l + r) >> 1;
+ glyphID = ttUSHORT(glyphArray + 2 * m);
+ straw = glyphID;
+ if (needle < straw)
+ r = m - 1;
+ else if (needle > straw)
+ l = m + 1;
+ else {
+ return m;
+ }
+ }
+ } break;
+
+ case 2: {
+ stbtt_uint16 rangeCount = ttUSHORT(coverageTable + 2);
+ stbtt_uint8 *rangeArray = coverageTable + 4;
+
+ // Binary search.
+ stbtt_int32 l = 0, r = rangeCount - 1, m;
+ int strawStart, strawEnd, needle = glyph;
+ while (l <= r) {
+ stbtt_uint8 *rangeRecord;
+ m = (l + r) >> 1;
+ rangeRecord = rangeArray + 6 * m;
+ strawStart = ttUSHORT(rangeRecord);
+ strawEnd = ttUSHORT(rangeRecord + 2);
+ if (needle < strawStart)
+ r = m - 1;
+ else if (needle > strawEnd)
+ l = m + 1;
+ else {
+ stbtt_uint16 startCoverageIndex = ttUSHORT(rangeRecord + 4);
+ return startCoverageIndex + glyph - strawStart;
+ }
+ }
+ } break;
+
+ default: {
+ // There are no other cases.
+ STBTT_assert(0);
+ } break;
+ }
+
+ return -1;
+}
+
+static stbtt_int32 stbtt__GetGlyphClass(stbtt_uint8 *classDefTable, int glyph)
+{
+ stbtt_uint16 classDefFormat = ttUSHORT(classDefTable);
+ switch (classDefFormat)
+ {
+ case 1: {
+ stbtt_uint16 startGlyphID = ttUSHORT(classDefTable + 2);
+ stbtt_uint16 glyphCount = ttUSHORT(classDefTable + 4);
+ stbtt_uint8 *classDef1ValueArray = classDefTable + 6;
+
+ if (glyph >= startGlyphID && glyph < startGlyphID + glyphCount)
+ return (stbtt_int32)ttUSHORT(classDef1ValueArray + 2 * (glyph - startGlyphID));
+
+ classDefTable = classDef1ValueArray + 2 * glyphCount;
+ } break;
+
+ case 2: {
+ stbtt_uint16 classRangeCount = ttUSHORT(classDefTable + 2);
+ stbtt_uint8 *classRangeRecords = classDefTable + 4;
+
+ // Binary search.
+ stbtt_int32 l = 0, r = classRangeCount - 1, m;
+ int strawStart, strawEnd, needle = glyph;
+ while (l <= r) {
+ stbtt_uint8 *classRangeRecord;
+ m = (l + r) >> 1;
+ classRangeRecord = classRangeRecords + 6 * m;
+ strawStart = ttUSHORT(classRangeRecord);
+ strawEnd = ttUSHORT(classRangeRecord + 2);
+ if (needle < strawStart)
+ r = m - 1;
+ else if (needle > strawEnd)
+ l = m + 1;
+ else
+ return (stbtt_int32)ttUSHORT(classRangeRecord + 4);
+ }
+
+ classDefTable = classRangeRecords + 6 * classRangeCount;
+ } break;
+
+ default: {
+ // There are no other cases.
+ STBTT_assert(0);
+ } break;
+ }
+
+ return -1;
+}
+
+// Define to STBTT_assert(x) if you want to break on unimplemented formats.
+#define STBTT_GPOS_TODO_assert(x)
+
+static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2)
+{
+ stbtt_uint16 lookupListOffset;
+ stbtt_uint8 *lookupList;
+ stbtt_uint16 lookupCount;
+ stbtt_uint8 *data;
+ stbtt_int32 i;
+
+ if (!info->gpos) return 0;
+
+ data = info->data + info->gpos;
+
+ if (ttUSHORT(data + 0) != 1) return 0; // Major version 1
+ if (ttUSHORT(data + 2) != 0) return 0; // Minor version 0
+
+ lookupListOffset = ttUSHORT(data + 8);
+ lookupList = data + lookupListOffset;
+ lookupCount = ttUSHORT(lookupList);
+
+ for (i = 0; i<lookupCount; ++i) {
+ stbtt_uint16 lookupOffset = ttUSHORT(lookupList + 2 + 2 * i);
+ stbtt_uint8 *lookupTable = lookupList + lookupOffset;
+
+ stbtt_uint16 lookupType = ttUSHORT(lookupTable);
+ stbtt_uint16 subTableCount = ttUSHORT(lookupTable + 4);
+ stbtt_uint8 *subTableOffsets = lookupTable + 6;
+ switch (lookupType) {
+ case 2: { // Pair Adjustment Positioning Subtable
+ stbtt_int32 sti;
+ for (sti = 0; sti<subTableCount; sti++) {
+ stbtt_uint16 subtableOffset = ttUSHORT(subTableOffsets + 2 * sti);
+ stbtt_uint8 *table = lookupTable + subtableOffset;
+ stbtt_uint16 posFormat = ttUSHORT(table);
+ stbtt_uint16 coverageOffset = ttUSHORT(table + 2);
+ stbtt_int32 coverageIndex = stbtt__GetCoverageIndex(table + coverageOffset, glyph1);
+ if (coverageIndex == -1) continue;
+
+ switch (posFormat) {
+ case 1: {
+ stbtt_int32 l, r, m;
+ int straw, needle;
+ stbtt_uint16 valueFormat1 = ttUSHORT(table + 4);
+ stbtt_uint16 valueFormat2 = ttUSHORT(table + 6);
+ stbtt_int32 valueRecordPairSizeInBytes = 2;
+ stbtt_uint16 pairSetCount = ttUSHORT(table + 8);
+ stbtt_uint16 pairPosOffset = ttUSHORT(table + 10 + 2 * coverageIndex);
+ stbtt_uint8 *pairValueTable = table + pairPosOffset;
+ stbtt_uint16 pairValueCount = ttUSHORT(pairValueTable);
+ stbtt_uint8 *pairValueArray = pairValueTable + 2;
+ // TODO: Support more formats.
+ STBTT_GPOS_TODO_assert(valueFormat1 == 4);
+ if (valueFormat1 != 4) return 0;
+ STBTT_GPOS_TODO_assert(valueFormat2 == 0);
+ if (valueFormat2 != 0) return 0;
+
+ STBTT_assert(coverageIndex < pairSetCount);
+
+ needle = glyph2;
+ r = pairValueCount - 1;
+ l = 0;
+
+ // Binary search.
+ while (l <= r) {
+ stbtt_uint16 secondGlyph;
+ stbtt_uint8 *pairValue;
+ m = (l + r) >> 1;
+ pairValue = pairValueArray + (2 + valueRecordPairSizeInBytes) * m;
+ secondGlyph = ttUSHORT(pairValue);
+ straw = secondGlyph;
+ if (needle < straw)
+ r = m - 1;
+ else if (needle > straw)
+ l = m + 1;
+ else {
+ stbtt_int16 xAdvance = ttSHORT(pairValue + 2);
+ return xAdvance;
+ }
+ }
+ } break;
+
+ case 2: {
+ stbtt_uint16 valueFormat1 = ttUSHORT(table + 4);
+ stbtt_uint16 valueFormat2 = ttUSHORT(table + 6);
+
+ stbtt_uint16 classDef1Offset = ttUSHORT(table + 8);
+ stbtt_uint16 classDef2Offset = ttUSHORT(table + 10);
+ int glyph1class = stbtt__GetGlyphClass(table + classDef1Offset, glyph1);
+ int glyph2class = stbtt__GetGlyphClass(table + classDef2Offset, glyph2);
+
+ stbtt_uint16 class1Count = ttUSHORT(table + 12);
+ stbtt_uint16 class2Count = ttUSHORT(table + 14);
+ STBTT_assert(glyph1class < class1Count);
+ STBTT_assert(glyph2class < class2Count);
+
+ // TODO: Support more formats.
+ STBTT_GPOS_TODO_assert(valueFormat1 == 4);
+ if (valueFormat1 != 4) return 0;
+ STBTT_GPOS_TODO_assert(valueFormat2 == 0);
+ if (valueFormat2 != 0) return 0;
+
+ if (glyph1class >= 0 && glyph1class < class1Count && glyph2class >= 0 && glyph2class < class2Count) {
+ stbtt_uint8 *class1Records = table + 16;
+ stbtt_uint8 *class2Records = class1Records + 2 * (glyph1class * class2Count);
+ stbtt_int16 xAdvance = ttSHORT(class2Records + 2 * glyph2class);
+ return xAdvance;
+ }
+ } break;
+
+ default: {
+ // There are no other cases.
+ STBTT_assert(0);
+ break;
+ };
+ }
+ }
+ break;
+ };
+
+ default:
+ // TODO: Implement other stuff.
+ break;
+ }
+ }
+
+ return 0;
+}
+
+STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int g1, int g2)
+{
+ int xAdvance = 0;
+
+ if (info->gpos)
+ xAdvance += stbtt__GetGlyphGPOSInfoAdvance(info, g1, g2);
+
+ if (info->kern)
+ xAdvance += stbtt__GetGlyphKernInfoAdvance(info, g1, g2);
+
+ return xAdvance;
+}
+
STBTT_DEF int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2)
{
- if (!info->kern) // if no kerning table, don't waste time looking up both codepoint->glyphs
+ if (!info->kern && !info->gpos) // if no kerning table, don't waste time looking up both codepoint->glyphs
return 0;
return stbtt_GetGlyphKernAdvance(info, stbtt_FindGlyphIndex(info, ch1), stbtt_FindGlyphIndex(info, ch2));
}
@@ -2304,6 +2592,17 @@ STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, in
if (lineGap) *lineGap = ttSHORT(info->data + info->hhea + 8);
}
+STBTT_DEF int stbtt_GetFontVMetricsOS2(const stbtt_fontinfo *info, int *typoAscent, int *typoDescent, int *typoLineGap)
+{
+ int tab = stbtt__find_table(info->data, info->fontstart, "OS/2");
+ if (!tab)
+ return 0;
+ if (typoAscent) *typoAscent = ttSHORT(info->data + tab + 68);
+ if (typoDescent) *typoDescent = ttSHORT(info->data + tab + 70);
+ if (typoLineGap) *typoLineGap = ttSHORT(info->data + tab + 72);
+ return 1;
+}
+
STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1)
{
*x0 = ttSHORT(info->data + info->head + 36);
@@ -2402,7 +2701,7 @@ static void *stbtt__hheap_alloc(stbtt__hheap *hh, size_t size, void *userdata)
hh->num_remaining_in_head_chunk = count;
}
--hh->num_remaining_in_head_chunk;
- return (char *)(hh->head) + size * hh->num_remaining_in_head_chunk;
+ return (char *)(hh->head) + sizeof(stbtt__hheap_chunk) + size * hh->num_remaining_in_head_chunk;
}
}
@@ -3122,7 +3421,7 @@ static int stbtt__tesselate_curve(stbtt__point *points, int *num_points, float x
float dy = (y0 + y2) / 2 - my;
if (n > 16) // 65536 segments on one curve better be enough!
return 1;
- if (dx*dx + dy*dy > objspace_flatness_squared) { // half-pixel error allowed... need to be smaller if AA
+ if (dx*dx + dy * dy > objspace_flatness_squared) { // half-pixel error allowed... need to be smaller if AA
stbtt__tesselate_curve(points, num_points, x0, y0, (x0 + x1) / 2.0f, (y0 + y1) / 2.0f, mx, my, objspace_flatness_squared, n + 1);
stbtt__tesselate_curve(points, num_points, mx, my, (x1 + x2) / 2.0f, (y1 + y2) / 2.0f, x2, y2, objspace_flatness_squared, n + 1);
}
@@ -3144,9 +3443,9 @@ static void stbtt__tesselate_cubic(stbtt__point *points, int *num_points, float
float dy2 = y3 - y2;
float dx = x3 - x0;
float dy = y3 - y0;
- float longlen = (float)(STBTT_sqrt(dx0*dx0 + dy0*dy0) + STBTT_sqrt(dx1*dx1 + dy1*dy1) + STBTT_sqrt(dx2*dx2 + dy2*dy2));
- float shortlen = (float)STBTT_sqrt(dx*dx + dy*dy);
- float flatness_squared = longlen*longlen - shortlen*shortlen;
+ float longlen = (float)(STBTT_sqrt(dx0*dx0 + dy0 * dy0) + STBTT_sqrt(dx1*dx1 + dy1 * dy1) + STBTT_sqrt(dx2*dx2 + dy2 * dy2));
+ float shortlen = (float)STBTT_sqrt(dx*dx + dy * dy);
+ float flatness_squared = longlen * longlen - shortlen * shortlen;
if (n > 16) // 65536 segments on one curve better be enough!
return;
@@ -3257,7 +3556,8 @@ error:
STBTT_DEF void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata)
{
float scale = scale_x > scale_y ? scale_y : scale_x;
- int winding_count, *winding_lengths;
+ int winding_count = 0;
+ int *winding_lengths = NULL;
stbtt__point *windings = stbtt_FlattenCurves(vertices, num_verts, flatness_in_pixels / scale, &winding_lengths, &winding_count, userdata);
if (windings) {
stbtt__rasterize(result, windings, winding_lengths, winding_count, scale_x, scale_y, shift_x, shift_y, x_off, y_off, invert, userdata);
@@ -3345,6 +3645,11 @@ STBTT_DEF unsigned char *stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo *
return stbtt_GetGlyphBitmapSubpixel(info, scale_x, scale_y, shift_x, shift_y, stbtt_FindGlyphIndex(info, codepoint), width, height, xoff, yoff);
}
+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)
+{
+ stbtt_MakeGlyphBitmapSubpixelPrefilter(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, oversample_x, oversample_y, sub_x, sub_y, stbtt_FindGlyphIndex(info, codepoint));
+}
+
STBTT_DEF void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint)
{
stbtt_MakeGlyphBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, stbtt_FindGlyphIndex(info, codepoint));
@@ -3397,7 +3702,7 @@ static int stbtt_BakeFontBitmap_internal(unsigned char *data, int offset, // fo
return -i;
STBTT_assert(x + gw < pw);
STBTT_assert(y + gh < ph);
- stbtt_MakeGlyphBitmap(&f, pixels + x + y*pw, gw, gh, pw, scale, scale, g);
+ stbtt_MakeGlyphBitmap(&f, pixels + x + y * pw, gw, gh, pw, scale, scale, g);
chardata[i].x0 = (stbtt_int16)x;
chardata[i].y0 = (stbtt_int16)y;
chardata[i].x1 = (stbtt_int16)(x + gw);
@@ -3836,7 +4141,7 @@ STBTT_DEF void stbtt_PackFontRangesPackRects(stbtt_pack_context *spc, stbrp_rect
stbrp_pack_rects((stbrp_context *)spc->pack_info, rects, num_rects);
}
-STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)
+STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)
{
stbtt_fontinfo info;
int i, j, n, return_value = 1;
@@ -3872,7 +4177,7 @@ STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontd
return return_value;
}
-STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,
+STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, float font_size,
int first_unicode_codepoint_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range)
{
stbtt_pack_range range;
@@ -3935,10 +4240,10 @@ static int stbtt__ray_intersect_bezier(float orig[2], float ray[2], float q0[2],
int num_s = 0;
if (a != 0.0) {
- float discr = b*b - a*c;
+ float discr = b * b - a * c;
if (discr > 0.0) {
float rcpna = -1 / a;
- float d = (float)sqrt(discr);
+ float d = (float)STBTT_sqrt(discr);
s0 = (b + d) * rcpna;
s1 = (b - d) * rcpna;
if (s0 >= 0.0 && s0 <= 1.0)
@@ -3972,12 +4277,12 @@ static int stbtt__ray_intersect_bezier(float orig[2], float ray[2], float q0[2],
float q20d = q2d - q0d;
float q0rd = q0d - rod;
- hits[0][0] = q0rd + s0*(2.0f - 2.0f*s0)*q10d + s0*s0*q20d;
- hits[0][1] = a*s0 + b;
+ hits[0][0] = q0rd + s0 * (2.0f - 2.0f*s0)*q10d + s0 * s0*q20d;
+ hits[0][1] = a * s0 + b;
if (num_s > 1) {
- hits[1][0] = q0rd + s1*(2.0f - 2.0f*s1)*q10d + s1*s1*q20d;
- hits[1][1] = a*s1 + b;
+ hits[1][0] = q0rd + s1 * (2.0f - 2.0f*s1)*q10d + s1 * s1*q20d;
+ hits[1][1] = a * s1 + b;
return 2;
}
else {
@@ -4002,7 +4307,7 @@ static int stbtt__compute_crossings_x(float x, float y, int nverts, stbtt_vertex
orig[1] = y;
// make sure y never passes through a vertex of the shape
- y_frac = (float)fmod(y, 1.0f);
+ y_frac = (float)STBTT_fmod(y, 1.0f);
if (y_frac < 0.01f)
y += 0.01f;
else if (y_frac > 0.99f)
@@ -4073,10 +4378,10 @@ static float stbtt__cuberoot(float x)
static int stbtt__solve_cubic(float a, float b, float c, float* r)
{
float s = -a / 3;
- float p = b - a*a / 3;
+ float p = b - a * a / 3;
float q = a * (2 * a*a - 9 * b) / 27 + c;
- float p3 = p*p*p;
- float d = q*q + 4 * p3 / 27;
+ float p3 = p * p*p;
+ float d = q * q + 4 * p3 / 27;
if (d >= 0) {
float z = (float)STBTT_sqrt(d);
float u = (-q + z) / 2;
@@ -4158,9 +4463,9 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
float x1 = verts[i].cx*scale_x, y1 = verts[i].cy*scale_y;
float x0 = verts[i].x *scale_x, y0 = verts[i].y *scale_y;
float bx = x0 - 2 * x1 + x2, by = y0 - 2 * y1 + y2;
- float len2 = bx*bx + by*by;
+ float len2 = bx * bx + by * by;
if (len2 != 0.0f)
- precompute[i] = 1.0f / (bx*bx + by*by);
+ precompute[i] = 1.0f / (bx*bx + by * by);
else
precompute[i] = 0.0f;
}
@@ -4203,7 +4508,7 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
float px = x0 - sx, py = y0 - sy;
// minimize (px+t*dx)^2 + (py+t*dy)^2 = px*px + 2*px*dx*t + t^2*dx*dx + py*py + 2*py*dy*t + t^2*dy*dy
// derivative: 2*px*dx + 2*py*dy + (2*dx*dx+2*dy*dy)*t, set to 0 and solve
- float t = -(px*dx + py*dy) / (dx*dx + dy*dy);
+ float t = -(px*dx + py * dy) / (dx*dx + dy * dy);
if (t >= 0.0f && t <= 1.0f)
min_dist = dist;
}
@@ -4224,16 +4529,16 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
float res[3], px, py, t, it;
float a_inv = precompute[i];
if (a_inv == 0.0) { // if a_inv is 0, it's 2nd degree so use quadratic formula
- float a = 3 * (ax*bx + ay*by);
- float b = 2 * (ax*ax + ay*ay) + (mx*bx + my*by);
- float c = mx*ax + my*ay;
+ float a = 3 * (ax*bx + ay * by);
+ float b = 2 * (ax*ax + ay * ay) + (mx*bx + my * by);
+ float c = mx * ax + my * ay;
if (a == 0.0) { // if a is 0, it's linear
if (b != 0.0) {
res[num++] = -c / b;
}
}
else {
- float discriminant = b*b - 4 * a*c;
+ float discriminant = b * b - 4 * a*c;
if (discriminant < 0)
num = 0;
else {
@@ -4245,31 +4550,31 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
}
}
else {
- float b = 3 * (ax*bx + ay*by) * a_inv; // could precompute this as it doesn't depend on sample point
- float c = (2 * (ax*ax + ay*ay) + (mx*bx + my*by)) * a_inv;
- float d = (mx*ax + my*ay) * a_inv;
+ float b = 3 * (ax*bx + ay * by) * a_inv; // could precompute this as it doesn't depend on sample point
+ float c = (2 * (ax*ax + ay * ay) + (mx*bx + my * by)) * a_inv;
+ float d = (mx*ax + my * ay) * a_inv;
num = stbtt__solve_cubic(b, c, d, res);
}
if (num >= 1 && res[0] >= 0.0f && res[0] <= 1.0f) {
t = res[0], it = 1.0f - t;
- px = it*it*x0 + 2 * t*it*x1 + t*t*x2;
- py = it*it*y0 + 2 * t*it*y1 + t*t*y2;
+ px = it * it*x0 + 2 * t*it*x1 + t * t*x2;
+ py = it * it*y0 + 2 * t*it*y1 + t * t*y2;
dist2 = (px - sx)*(px - sx) + (py - sy)*(py - sy);
if (dist2 < min_dist * min_dist)
min_dist = (float)STBTT_sqrt(dist2);
}
if (num >= 2 && res[1] >= 0.0f && res[1] <= 1.0f) {
t = res[1], it = 1.0f - t;
- px = it*it*x0 + 2 * t*it*x1 + t*t*x2;
- py = it*it*y0 + 2 * t*it*y1 + t*t*y2;
+ px = it * it*x0 + 2 * t*it*x1 + t * t*x2;
+ py = it * it*y0 + 2 * t*it*y1 + t * t*y2;
dist2 = (px - sx)*(px - sx) + (py - sy)*(py - sy);
if (dist2 < min_dist * min_dist)
min_dist = (float)STBTT_sqrt(dist2);
}
if (num >= 3 && res[2] >= 0.0f && res[2] <= 1.0f) {
t = res[2], it = 1.0f - t;
- px = it*it*x0 + 2 * t*it*x1 + t*t*x2;
- py = it*it*y0 + 2 * t*it*y1 + t*t*y2;
+ px = it * it*x0 + 2 * t*it*x1 + t * t*x2;
+ py = it * it*y0 + 2 * t*it*y1 + t * t*y2;
dist2 = (px - sx)*(px - sx) + (py - sy)*(py - sy);
if (dist2 < min_dist * min_dist)
min_dist = (float)STBTT_sqrt(dist2);
@@ -4516,6 +4821,9 @@ STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const
// FULL VERSION HISTORY
//
+// 1.19 (2018-02-11) OpenType GPOS kerning (horizontal only), STBTT_fmod
+// 1.18 (2018-01-29) add missing function
+// 1.17 (2017-07-23) make more arguments const; doc fix
// 1.16 (2017-07-12) SDF support
// 1.15 (2017-03-03) make more arguments const
// 1.14 (2017-01-16) num-fonts-in-TTC function
@@ -4608,4 +4916,4 @@ AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------
-*/
+*/ \ No newline at end of file
diff --git a/src/libjin/Graphics/Font.h b/src/libjin/Graphics/Font.h
index e4fa12b..0ab482d 100644
--- a/src/libjin/Graphics/Font.h
+++ b/src/libjin/Graphics/Font.h
@@ -15,9 +15,18 @@ namespace graphics
class Font: public Drawable
{
public:
- Font();
+ Font * createFont(const char* file);
+ Font* createFont(const char* data, size_t size);
- void loadFile(const char* file);
+ void box(const char* text, int fontHeight, int spacing, int lineHeight, int* w, int * h);
+
+ private:
+ /* ASCII 32(space)..126(~) 95 glyphs */
+ static const int ASCII_CHARACTER_NUM = 96;
+
+ Font();
+
+ void loadFile(const char* file);
void loadMemory(const unsigned char* data);
void render(
const char* text, // rendered text
@@ -26,14 +35,9 @@ namespace graphics
int spacing, // font spacing
int lineHeight // line height
);
- void box(const char* text, int fontHeight, int spacing, int lineHeight, int* w, int * h);
-
- private:
- /* ASCII 32(space)..126(~) 95 glyphs */
- static const int ASCII_CHARACTER_NUM = 96;
stbtt_bakedchar asciiData[ASCII_CHARACTER_NUM];
-
+
};
} // graphics
diff --git a/src/lua/embed/boot.lua.h b/src/lua/embed/boot.lua.h
index 35bfdfc..f41ba3b 100644
--- a/src/lua/embed/boot.lua.h
+++ b/src/lua/embed/boot.lua.h
@@ -96,7 +96,7 @@ jin.nogame = {
nogame.t = nogame.ww - 1
end,
onEvent = function(e)
- if e.type == 'quit' then
+ if e.type == 'Quit' then
jin.core.stop()
end
end,