Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
itdan3344
stb
提交
eb62c741
S
stb
项目概览
itdan3344
/
stb
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
stb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
eb62c741
编写于
5月 25, 2014
作者:
S
Sean Barrett
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixed warnings for stb_truetype (fixes all outstanding bug reports)
上级
31897dfd
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
65 addition
and
18 deletion
+65
-18
stb_truetype.h
stb_truetype.h
+29
-14
tests/compile_test.c
tests/compile_test.c
+0
-2
tests/stb.c
tests/stb.c
+3
-0
tests/stb.dsp
tests/stb.dsp
+6
-2
tests/test_truetype.c
tests/test_truetype.c
+27
-0
未找到文件。
stb_truetype.h
浏览文件 @
eb62c741
...
...
@@ -27,9 +27,14 @@
// stoiko (Haemimont Games)
// Brian Hook
// Walter van Niftrik
// David Gow
// David Given
// Ivan-Assen Ivanov
// Anthony Pesch
//
// VERSION HISTORY
//
// 0.8 (2014-05-25) fix a few more warnings
// 0.7 (2013-09-25) bugfix: subpixel glyph bug fixed in 0.5 had come back
// 0.6c (2012-07-24) improve documentation
// 0.6b (2012-07-20) fix a few more warnings
...
...
@@ -223,7 +228,7 @@ void my_stbtt_print(float x, float y, char *text)
while (*text) {
if (*text >= 32 && *text < 128) {
stbtt_aligned_quad q;
stbtt_GetBakedQuad(cdata, 512,512, *text-32, &x,&y,&q,1);//1=opengl
,0=old d3d
stbtt_GetBakedQuad(cdata, 512,512, *text-32, &x,&y,&q,1);//1=opengl
& d3d10+,0=d3d9
glTexCoord2f(q.s0,q.t1); glVertex2f(q.x0,q.y0);
glTexCoord2f(q.s1,q.t1); glVertex2f(q.x1,q.y0);
glTexCoord2f(q.s1,q.t0); glVertex2f(q.x1,q.y1);
...
...
@@ -292,7 +297,7 @@ int main(int arg, char **argv)
{
stbtt_fontinfo font;
int i,j,ascent,baseline,ch=0;
float scale, xpos=
0;
float scale, xpos=
2; // leave a little padding in case the character extends left
char *text = "Heljo World!";
fread(buffer, 1, 1000000, fopen("c:/windows/fonts/arialbd.ttf", "rb"));
...
...
@@ -364,10 +369,15 @@ int main(int arg, char **argv)
#define STBTT_iceil(x) ((int) ceil(x))
#endif
#ifndef STBTT_sqrt
#include <math.h>
#define STBTT_sqrt(x) sqrt(x)
#endif
// #define your own functions "STBTT_malloc" / "STBTT_free" to avoid malloc.h
#ifndef STBTT_malloc
#include <
malloc
.h>
#define STBTT_malloc(x,u)
malloc(x
)
#include <
stdlib
.h>
#define STBTT_malloc(x,u)
((void)(u),malloc(x)
)
#define STBTT_free(x,u) free(x)
#endif
...
...
@@ -532,7 +542,6 @@ extern void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint
extern
int
stbtt_GetCodepointKernAdvance
(
const
stbtt_fontinfo
*
info
,
int
ch1
,
int
ch2
);
// an additional amount to add to the 'advance' value between ch1 and ch2
// @TODO; for now always returns 0!
extern
int
stbtt_GetCodepointBox
(
const
stbtt_fontinfo
*
info
,
int
codepoint
,
int
*
x0
,
int
*
y0
,
int
*
x1
,
int
*
y1
);
// Gets the bounding box of the visible part of the glyph, in unscaled coordinates
...
...
@@ -574,6 +583,13 @@ extern int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codep
extern
int
stbtt_GetGlyphShape
(
const
stbtt_fontinfo
*
info
,
int
glyph_index
,
stbtt_vertex
**
vertices
);
// returns # of vertices and fills *vertices with the pointer to them
// these are expressed in "unscaled" coordinates
//
// The shape is a series of countours. Each one starts with
// a STBTT_moveto, then consists of a series of mixed
// STBTT_lineto and STBTT_curveto segments. A lineto
// draws a line from previous endpoint to its x,y; a curveto
// draws a quadratic bezier from previous endpoint to
// its x,y, using cx,cy as the bezier control point.
extern
void
stbtt_FreeShape
(
const
stbtt_fontinfo
*
info
,
stbtt_vertex
*
vertices
);
// frees the data allocated above
...
...
@@ -916,10 +932,7 @@ int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint)
// now decrement to bias correctly to find smallest
search
-=
2
;
while
(
entrySelector
)
{
stbtt_uint16
start
,
end
;
searchRange
>>=
1
;
start
=
ttUSHORT
(
data
+
search
+
2
+
segcount
*
2
+
2
);
end
=
ttUSHORT
(
data
+
search
+
2
);
start
=
ttUSHORT
(
data
+
search
+
searchRange
*
2
+
segcount
*
2
+
2
);
end
=
ttUSHORT
(
data
+
search
+
searchRange
*
2
);
if
(
unicode_codepoint
>
end
)
...
...
@@ -1224,8 +1237,8 @@ int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_verte
}
// Find transformation scales.
m
=
(
float
)
sqrt
(
mtx
[
0
]
*
mtx
[
0
]
+
mtx
[
1
]
*
mtx
[
1
]);
n
=
(
float
)
sqrt
(
mtx
[
2
]
*
mtx
[
2
]
+
mtx
[
3
]
*
mtx
[
3
]);
m
=
(
float
)
STBTT_
sqrt
(
mtx
[
0
]
*
mtx
[
0
]
+
mtx
[
1
]
*
mtx
[
1
]);
n
=
(
float
)
STBTT_
sqrt
(
mtx
[
2
]
*
mtx
[
2
]
+
mtx
[
3
]
*
mtx
[
3
]);
// Get indexed glyph.
comp_num_verts
=
stbtt_GetGlyphShape
(
info
,
gidx
,
&
comp_verts
);
...
...
@@ -1248,8 +1261,8 @@ int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_verte
if
(
comp_verts
)
STBTT_free
(
comp_verts
,
info
->
userdata
);
return
0
;
}
if
(
num_vertices
>
0
)
memcpy
(
tmp
,
vertices
,
num_vertices
*
sizeof
(
stbtt_vertex
));
memcpy
(
tmp
+
num_vertices
,
comp_verts
,
comp_num_verts
*
sizeof
(
stbtt_vertex
));
if
(
num_vertices
>
0
)
STBTT_
memcpy
(
tmp
,
vertices
,
num_vertices
*
sizeof
(
stbtt_vertex
));
STBTT_
memcpy
(
tmp
+
num_vertices
,
comp_verts
,
comp_num_verts
*
sizeof
(
stbtt_vertex
));
if
(
vertices
)
STBTT_free
(
vertices
,
info
->
userdata
);
vertices
=
tmp
;
STBTT_free
(
comp_verts
,
info
->
userdata
);
...
...
@@ -1993,14 +2006,16 @@ static int stbtt__matchpair(stbtt_uint8 *fc, stbtt_uint32 nm, stbtt_uint8 *name,
// is this a Unicode encoding?
if
(
platform
==
0
||
(
platform
==
3
&&
encoding
==
1
)
||
(
platform
==
3
&&
encoding
==
10
))
{
stbtt_int32
slen
=
ttUSHORT
(
fc
+
loc
+
8
),
off
=
ttUSHORT
(
fc
+
loc
+
10
);
stbtt_int32
slen
=
ttUSHORT
(
fc
+
loc
+
8
);
stbtt_int32
off
=
ttUSHORT
(
fc
+
loc
+
10
);
// check if there's a prefix match
stbtt_int32
matchlen
=
stbtt__CompareUTF8toUTF16_bigendian_prefix
(
name
,
nlen
,
fc
+
stringOffset
+
off
,
slen
);
if
(
matchlen
>=
0
)
{
// check for target_id+1 immediately following, with same encoding & language
if
(
i
+
1
<
count
&&
ttUSHORT
(
fc
+
loc
+
12
+
6
)
==
next_id
&&
ttUSHORT
(
fc
+
loc
+
12
)
==
platform
&&
ttUSHORT
(
fc
+
loc
+
12
+
2
)
==
encoding
&&
ttUSHORT
(
fc
+
loc
+
12
+
4
)
==
language
)
{
stbtt_int32
slen
=
ttUSHORT
(
fc
+
loc
+
12
+
8
),
off
=
ttUSHORT
(
fc
+
loc
+
12
+
10
);
slen
=
ttUSHORT
(
fc
+
loc
+
12
+
8
);
off
=
ttUSHORT
(
fc
+
loc
+
12
+
10
);
if
(
slen
==
0
)
{
if
(
matchlen
==
nlen
)
return
1
;
...
...
tests/compile_test.c
浏览文件 @
eb62c741
#define STB_TRUETYPE_IMPLEMENTATIOn
#define STB_PERLIN_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#define STB_DXT_IMPLEMENATION
#define STB_C_LEXER_IMPLEMENTATIOn
#include "stb_truetype.h"
#include "stb_image_write.h"
#include "stb_perlin.h"
#include "stb_dxt.h"
...
...
tests/stb.c
浏览文件 @
eb62c741
...
...
@@ -570,6 +570,7 @@ void rec_print(stb_dirtree2 *d, int depth)
d
->
weight
=
(
float
)
stb_arr_len
(
d
->
files
);
}
#ifdef MAIN_TEST
int
main
(
int
argc
,
char
**
argv
)
{
char
*
z
;
...
...
@@ -1556,6 +1557,8 @@ int main(int argc, char **argv)
return
0
;
}
#endif
...
...
tests/stb.dsp
浏览文件 @
eb62c741
...
...
@@ -42,7 +42,7 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /G6 /MT /W3 /GX /Z7 /O2 /Ob2 /I ".." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
# ADD CPP /nologo /G6 /MT /W3 /GX /Z7 /O2 /Ob2 /I ".." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /
D "MAIN_TEST" /
FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
...
...
@@ -66,7 +66,7 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /GX /Zd /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /GX /Zd /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /
D "MAIN_TEST" /
FR /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
...
...
@@ -100,5 +100,9 @@ SOURCE=..\stb_image.c
SOURCE=..\stb_vorbis.c
# End Source File
# Begin Source File
SOURCE=.\test_truetype.c
# End Source File
# End Target
# End Project
tests/test_truetype.c
0 → 100644
浏览文件 @
eb62c741
#define STB_TRUETYPE_IMPLEMENTATION
#include "stb_truetype.h"
#include <stdio.h>
char
ttf_buffer
[
1
<<
25
];
#ifdef TT_TEST
int
main
(
int
argc
,
char
**
argv
)
{
stbtt_fontinfo
font
;
unsigned
char
*
bitmap
;
int
w
,
h
,
i
,
j
,
c
=
(
argc
>
1
?
atoi
(
argv
[
1
])
:
34807
),
s
=
(
argc
>
2
?
atoi
(
argv
[
2
])
:
32
);
fread
(
ttf_buffer
,
1
,
1
<<
25
,
fopen
(
argc
>
3
?
argv
[
3
]
:
"c:/windows/fonts/mingliu.ttc"
,
"rb"
));
stbtt_InitFont
(
&
font
,
ttf_buffer
,
stbtt_GetFontOffsetForIndex
(
ttf_buffer
,
0
));
bitmap
=
stbtt_GetCodepointBitmap
(
&
font
,
0
,
stbtt_ScaleForPixelHeight
(
&
font
,
(
float
)
s
),
c
,
&
w
,
&
h
,
0
,
0
);
for
(
j
=
0
;
j
<
h
;
++
j
)
{
for
(
i
=
0
;
i
<
w
;
++
i
)
putchar
(
" .:ioVM@"
[
bitmap
[
j
*
w
+
i
]
>>
5
]);
putchar
(
'\n'
);
}
return
0
;
}
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录