memononen / fontstash Goto Github PK
View Code? Open in Web Editor NEWLight-weight online font texture atlas builder
License: zlib License
Light-weight online font texture atlas builder
License: zlib License
According to https://www.fontsquirrel.com/fonts/droid-serif the droid fonts are to be distributed under the Apache v2 license.
Hi People, please has someone working simple example for android? Or if is someone interested in help then I can create android container for testing with ndk and opengl es 2.0, but I don't know how to integrate fontstash...
So I started using fontstash, and I gave it a pretty small glyph cache size (128x128) because I knew I had very few different characters I needed to render, and then my thing got a little more complicated and I added a little more text, and suddenly it started just skipping characters. I thought I was going completely mad. How could it just be skipping characters? Like, it was fine except text containing the digit '5' would just leave that digit out, and sometimes it would skip '3's as well.
I spent ages tracking this down, and what was the problem? Of course it had just run out of space in the glyph cache. And with hindsight that's totally obvious -- what else could it be, right? But the trouble is that hindsight doesn't actually help to debug stuff, it only helps to make you feel dumb once you work out what the problem is.
So... I think fontstash needs to do something more useful when it can't fit a glyph into the cache texture. It doesn't have to auto-resize the texture or have some smart cache replacement policy, or even a dumb cache replacement policy. I just mean it needs to give some obvious and immediate indication that the cache texture has run out of space. Like, it could printf("FONT STASH SAYS: OH SHIT WE'RE OUT OF SPACE!\n");
or whatever.
I'd make a pull request, but I don't know how you'd prefer this error condition be handled.
Trying to include your library into my little game engine, but when i try to include glFontStash.h compiler (visual studio 2013) gives me hundreds of errors.
if i don't include it i can't call glFonsCreate!
i've included it so:
#include <stdio.h> // malloc, free, fopen, fclose, ftell, fseek, fread
#include <string.h> // memset
#define FONTSTASH_IMPLEMENTATION // Expands implementation
#include "fontstash.h"
#define GLFONTSTASH_IMPLEMENTATION // Expands implementation
#include "glfontstash.h"
Downloaded both GLFW and Fontstash. Run premake4 vs2010 to generate project files.
Set paths to GLFW in VS Directories tab on the project.
Compile and get the following errors:
Warning 17 warning C4024: 'fons__blur' : different types for formal and actual parameter 2 684
Warning 13 warning C4024: 'stbtt_MakeGlyphBitmap' : different types for formal and actual parameter 2 665
Warning 12 warning C4047: 'function' : 'unsigned char *' differs in levels of indirection from 'int' 665
Warning 16 warning C4047: 'function' : 'unsigned char *' differs in levels of indirection from 'int' 684
Warning 3 warning C4047: 'return' : 'void *' differs in levels of indirection from 'int' 212
Warning 20 warning C4133: 'function' : incompatible types - from 'int *' to 'float *' 818
Warning 23 warning C4133: 'function' : incompatible types - from 'int *' to 'float *' 821
Error 6 error C2065: 'alpha' : undeclared identifier 568
Error 7 error C2065: 'alpha' : undeclared identifier 569
Error 8 error C2065: 'alpha' : undeclared identifier 570
Error 9 error C2065: 'alpha' : undeclared identifier 571
Error 15 error C2065: 'bdst' : undeclared identifier 684
Error 53 error C2065: 'black' : undeclared identifier 258
Error 49 error C2065: 'blue' : undeclared identifier 194
Error 47 error C2065: 'brown' : undeclared identifier 170
Error 11 error C2065: 'dst' : undeclared identifier 665
Error 27 error C2065: 'font' : undeclared identifier 940
Error 29 error C2065: 'font' : undeclared identifier 943
Error 32 error C2065: 'font' : undeclared identifier 945
Error 35 error C2065: 'font' : undeclared identifier 947
Error 41 error C2065: 'h' : undeclared identifier 57
Error 31 error C2065: 'isize' : undeclared identifier 943
Error 34 error C2065: 'isize' : undeclared identifier 945
Error 37 error C2065: 'isize' : undeclared identifier 947
Error 2 error C2065: 'ptr' : undeclared identifier 212
Error 40 error C2065: 'w' : undeclared identifier 57
Error 46 error C2065: 'white' : undeclared identifier 165
Error 48 error C2065: 'white' : undeclared identifier 175
Error 50 error C2065: 'white' : undeclared identifier 203
Error 51 error C2065: 'white' : undeclared identifier 216
Error 52 error C2065: 'white' : undeclared identifier 249
Error 54 error C2065: 'white' : undeclared identifier 263
Error 19 error C2065: 'width' : undeclared identifier 818
Error 21 error C2065: 'width' : undeclared identifier 819
Error 22 error C2065: 'width' : undeclared identifier 821
Error 24 error C2065: 'width' : undeclared identifier 822
Error 1 error C2143: syntax error : missing ';' before 'type' 210
Error 4 error C2143: syntax error : missing ';' before 'type' 566
Error 5 error C2143: syntax error : missing ';' before 'type' 567
Error 10 error C2143: syntax error : missing ';' before 'type' 664
Error 14 error C2143: syntax error : missing ';' before 'type' 683
Error 18 error C2143: syntax error : missing ';' before 'type' 813
Error 25 error C2143: syntax error : missing ';' before 'type' 938
Error 26 error C2143: syntax error : missing ';' before 'type' 939
Error 38 error C2143: syntax error : missing ';' before 'type' 50
Error 39 error C2143: syntax error : missing ';' before 'type' 51
Error 42 error C2143: syntax error : missing ';' before 'type' 143
Error 43 error C2143: syntax error : missing ';' before 'type' 144
Error 44 error C2143: syntax error : missing ';' before 'type' 145
Error 45 error C2143: syntax error : missing ';' before 'type' 146
Error 30 error C2223: left of '->ascender' must point to struct/union 943
Error 28 error C2223: left of '->data' must point to struct/union 940
Error 33 error C2223: left of '->descender' must point to struct/union 945
Error 36 error C2223: left of '->lineh' must point to struct/union 947
why need to xadvance * 10.0f?
glyph->xadv = (short)(scale * advance * 10.0f)
*x += (int)(glyph->xadv / 10.0f + 0.5f);
When calculating the advance in fons__getQuad(), on line 1244:
*x += (int)(glyph->xadv / 10.0f + 0.5f);
Shouldn't the spacing be added somewhere like it is on line 1203:
*x += (int)(adv + spacing + 0.5f);
When you set -1 as letter spacing in nanovg, the result looks as if it set to 0.
I've been adding warning flags in the Makefile and of course some stuff rolls out here and there. For example the align
member of fontstash_style
doesn't seem to be used anywhere (nor initialized). Is that meant to be? Or is that some sort of reminder to you that it still needs to be implemented?
Would you like to make the project as pedantic-free as possible or would you rather keep it simple?
The reason I ask is because in my project I mostly turn the warnings up to 11, so when I include external files they usually trigger a bunch of things, I like to fix it at the root if possible.
I'd also like to add a static analyzing target in the makefile for the LLVM static analyzer, which has helped me track down a lot of stuff in the past (to show that I'm not entirely crazy, John Carmack seems to agree with me :)).
If you're not ok with any of these things, then that's cool of course! I'll be just as happy to maintain a personal fork :).
Thanks a lot for providing this library! We are currently converting our project to use it and it may be entirely my lack of GL understanding but I am not able to make the blending work out correctly. Some background polygons are blended correctly but some are not, see the picture. Sometimes the streets are blended correctly (see for instance the "am" of the upper amenity.restaurant) but sometimes not (see the last "a" in the same text). Every street has the same z value while the text is drawn slightly above. The code for text drawing is here: https://github.com/planetsumo/sumo/blob/master/sumo/src/utils/gui/div/GLHelper.cpp#L458 Any help is welcome!
Hi,
I have used a previous fork of font-stash from here:
https://github.com/akrinke/Font-Stash/
I used it at the time because it added two useful features we needed (taken from the readme):
However, now we need the graphics layer abstraction that you have added to the original fontstash because of changes in the rendering code we have planned in our game (Bitfighter.)
Does the current iteration supports the two features above? And if not, would they be worthwhile to integrate?
Thanks!
Trying to incorporate the example code into a project, but when the software makes the call to fonsSetFont, I receive an access violation on fons__getState
I've included a sample of the code below
struct FONScontext* fs = glfonsCreate(512, 512, FONS_ZERO_TOPLEFT);
int fontNormal = fonsAddFont(fs, "sans", "../DATA/Fonts/apercu-regular.ttf");
fonsSetFont(fs, fontNormal);
fonsSetSize(fs, 64.0f);
fonsDrawText(fs, dx, dy,text, NULL);
On windows a font that sits a path containing non ascii charaters fopen fails.
I m not sure what the best fix would be...
hey mikko,
Are you aware of this extension for fontstash? It uses your sdf lib and adds outlines too, via shader.
https://github.com/tangrams/ofxVectorTile/tree/master/libs/glmFontstash/fontstash
I would like to know if you plan to add these features on the main branch eventually?
If so, are you going to use this code (which license is unclear) or will you rather code your own solution?
Keep up the good work :)
Hello and thank you for this fabulous project.
My apologies if not the right place to present my work. The work is done and just want to share it with more people.
I finished the port to the programming language C# "I do not get along very well with pointers", the source code is here "https://sites.google.com/site/bitiopia/" ...
regards
On the bottom of http://bjoern.hoehrmann.de/utf-8/decoder/dfa/, there's an alternative implementation with a pre-multiplied table, which saves a bit shift. So basically an instruction less in the icache and some bytes less in the data cache. I microbenchmarked it, and it was 10% faster in a tight loop.
Since it's copy and paste work, I think it might be a good idea to use it.
Hi, on my Arch Linux system I had to add glfw to the linker options.
Thanks
diff --git a/premake4.lua b/premake4.lua
index b52cfcc..354e52f 100644
--- a/premake4.lua
+++ b/premake4.lua
@@ -14,7 +14,7 @@ solution "fontstash"
targetdir("build")
configuration { "linux" }
- links { "X11","Xrandr", "rt", "GL", "GLU", "pthread" }
+ links { "X11","Xrandr", "rt", "GL", "GLU", "pthread", "glfw" }
configuration { "windows" }
defines { "_CRT_SECURE_NO_WARNINGS" }
@@ -40,7 +40,7 @@ solution "fontstash"
targetdir("build")
configuration { "linux" }
- links { "X11","Xrandr", "rt", "GL", "GLU", "pthread" }
+ links { "X11","Xrandr", "rt", "GL", "GLU", "pthread", "glfw" }
configuration { "windows" }
defines { "_CRT_SECURE_NO_WARNINGS" }
Any plans to add text wrapping (on newline)? Specifically, in the text iteration functions used by NanoVG.
I've started to look into it, and got the simple (left-align) case working, but it gets complicated with right/center alignment. I'm not yet familiar enough with fons__decutf8() to scan for newlines without it crashing. I'd like to get your thoughts/plans before pursuing it further.
Is there any chance someone could either add an OpenGL 3 version of the example application or tweak the existing one to work with the new header? A naive substitution doesn't appear to produce a working test, unless I'm missing something...
In order to show Simplified Chinese, I tried several different ttf files. I found that set the same size, use different ttf file, the text size of the display difference. Should we need to read out some parameters from ttf file and set to fontstash?
I am using 10.9 with Xcode 5.0.2 and I get this when I try to build:
$ make
==== Building example (debug) ====
Linking example
Undefined symbols for architecture x86_64:
"_CVDisplayLinkCreateWithCGDisplay", referenced from:
__glfwPlatformGetVideoModes in libglfw3.a(cocoa_monitor.o)
__glfwPlatformGetVideoMode in libglfw3.a(cocoa_monitor.o)
"_CVDisplayLinkGetNominalOutputVideoRefreshPeriod", referenced from:
_vidmodeFromCGDisplayMode in libglfw3.a(cocoa_monitor.o)
"_CVDisplayLinkRelease", referenced from:
__glfwPlatformGetVideoModes in libglfw3.a(cocoa_monitor.o)
__glfwPlatformGetVideoMode in libglfw3.a(cocoa_monitor.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
It now works when I add -framework CoreVideo to LDFLAGS.
static int fons__tt_init()
{
FT_Error ftError;
FONS_NOTUSED(context); ---- wrong.
ftError = FT_Init_FreeType(&ftLibrary);
return ftError == 0;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.