Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Nanovg.a #485

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: tmilon <tmilon@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2017/11/07 18:38:31 by tmilon #+# #+# #
# Updated: 2018/05/30 10:27:32 by cpieri ### ########.fr #
# #
# **************************************************************************** #

NAME = lnvg.a

CC = gcc

CFLAGS = -Wall -Wextra -Werror

INCS = fontstash.h \
nanovg.h \
nanovg_gl.h \
nanovg_gl_utils.h \
stb_image.h \
stb_truetype.h

HEADERS = ./libft.h

SRC_PATH= src

OBJ_PATH= obj

CPPFLAG = -Iinclude

SRCS = nanovg.c

OBJS = $(SRCS:.c=.o)

SRC = $(addprefix $(SRC_PATH)/,$(SRCS) )

OBJ = $(addprefix $(OBJ_PATH)/,$(OBJS) )

.PHONY: all clean fclean re

all: $(NAME)

$(NAME): $(OBJ)
@echo "compiling libnvg.a"
@ar rc $(NAME) $(OBJ)
@ranlib $(NAME)

$(OBJ_PATH)/%.o: $(SRC_PATH)/%.c
@mkdir $(OBJ_PATH) 2> /dev/null || true
@$(CC) $(CFLAGS) $(CPPFLAG) -o $@ -c $<

clean:
@echo "cleaning nvg"
@/bin/rm -f $(OBJ)
@rmdir $(OBJ_PATH) 2> /dev/null || true

fclean: clean
@/bin/rm -f $(NAME)

re: fclean all
56 changes: 28 additions & 28 deletions src/fontstash.h → include/fontstash.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static FT_Library ftLibrary;
int fons__tt_init(FONScontext *context)
{
FT_Error ftError;
FONS_NOTUSED(context);
FONS_NOTUSED(context);
ftError = FT_Init_FreeType(&ftLibrary);
return ftError == 0;
}
Expand Down Expand Up @@ -195,7 +195,7 @@ int fons__tt_getGlyphIndex(FONSttFontImpl *font, int codepoint)
}

int fons__tt_buildGlyphBitmap(FONSttFontImpl *font, int glyph, float size, float scale,
int *advance, int *lsb, int *x0, int *y0, int *x1, int *y1)
int *advance, int *lsb, int *x0, int *y0, int *x1, int *y1)
{
FT_Error ftError;
FT_GlyphSlot ftGlyph;
Expand All @@ -219,7 +219,7 @@ int fons__tt_buildGlyphBitmap(FONSttFontImpl *font, int glyph, float size, float
}

void fons__tt_renderGlyphBitmap(FONSttFontImpl *font, unsigned char *output, int outWidth, int outHeight, int outStride,
float scaleX, float scaleY, int glyph)
float scaleX, float scaleY, int glyph)
{
FT_GlyphSlot ftGlyph = font->font->glyph;
int ftGlyphOffset = 0;
Expand Down Expand Up @@ -290,7 +290,7 @@ int fons__tt_getGlyphIndex(FONSttFontImpl *font, int codepoint)
}

int fons__tt_buildGlyphBitmap(FONSttFontImpl *font, int glyph, float size, float scale,
int *advance, int *lsb, int *x0, int *y0, int *x1, int *y1)
int *advance, int *lsb, int *x0, int *y0, int *x1, int *y1)
{
FONS_NOTUSED(size);
stbtt_GetGlyphHMetrics(&font->font, glyph, advance, lsb);
Expand All @@ -299,7 +299,7 @@ int fons__tt_buildGlyphBitmap(FONSttFontImpl *font, int glyph, float size, float
}

void fons__tt_renderGlyphBitmap(FONSttFontImpl *font, unsigned char *output, int outWidth, int outHeight, int outStride,
float scaleX, float scaleY, int glyph)
float scaleX, float scaleY, int glyph)
{
stbtt_MakeGlyphBitmap(&font->font, output, outWidth, outHeight, outStride, scaleX, scaleY, glyph);
}
Expand Down Expand Up @@ -399,7 +399,7 @@ struct FONSstate
typedef struct FONSstate FONSstate;

struct FONSatlasNode {
short x, y, width;
short x, y, width;
};
typedef struct FONSatlasNode FONSatlasNode;

Expand Down Expand Up @@ -490,11 +490,11 @@ static unsigned int fons__decutf8(unsigned int* state, unsigned int* codep, unsi
12,12,12,12,12,12,12,24,12,12,12,12, 12,24,12,12,12,12,12,12,12,24,12,12,
12,12,12,12,12,12,12,36,12,36,12,12, 12,36,12,12,12,12,12,36,12,36,12,12,
12,36,12,12,12,12,12,12,12,12,12,12,
};
};

unsigned int type = utf8d[byte];

*codep = (*state != FONS_UTF8_ACCEPT) ?
*codep = (*state != FONS_UTF8_ACCEPT) ?
(byte & 0x3fu) | (*codep << 6) :
(0xff >> type) & (byte);

Expand Down Expand Up @@ -894,7 +894,7 @@ int fonsAddFont(FONScontext* stash, const char* name, const char* path)
readed = fread(data, 1, dataSize, fp);
fclose(fp);
fp = 0;
if (readed != dataSize) goto error;
if (readed != (size_t)dataSize) goto error;

return fonsAddFontMem(stash, name, data, dataSize, 1);

Expand Down Expand Up @@ -1031,12 +1031,12 @@ static void fons__blur(FONScontext* stash, unsigned char* dst, int w, int h, int
fons__blurCols(dst, w, h, dstStride, alpha);
fons__blurRows(dst, w, h, dstStride, alpha);
fons__blurCols(dst, w, h, dstStride, alpha);
// fons__blurrows(dst, w, h, dstStride, alpha);
// fons__blurcols(dst, w, h, dstStride, alpha);
// fons__blurrows(dst, w, h, dstStride, alpha);
// fons__blurcols(dst, w, h, dstStride, alpha);
}

static FONSglyph* fons__getGlyph(FONScontext* stash, FONSfont* font, unsigned int codepoint,
short isize, short iblur, int bitmapOption)
short isize, short iblur, int bitmapOption)
{
int i, g, advance, lsb, x0, y0, x1, y1, gw, gh, gx, gy, x, y;
float scale;
Expand All @@ -1062,7 +1062,7 @@ static FONSglyph* fons__getGlyph(FONScontext* stash, FONSfont* font, unsigned in
if (font->glyphs[i].codepoint == codepoint && font->glyphs[i].size == isize && font->glyphs[i].blur == iblur) {
glyph = &font->glyphs[i];
if (bitmapOption == FONS_GLYPH_BITMAP_OPTIONAL || (glyph->x0 >= 0 && glyph->y0 >= 0)) {
return glyph;
return glyph;
}
// At this point, glyph exists but the bitmap data is not yet created.
break;
Expand Down Expand Up @@ -1148,14 +1148,14 @@ static FONSglyph* fons__getGlyph(FONScontext* stash, FONSfont* font, unsigned in
}

// Debug code to color the glyph background
/* unsigned char* fdst = &stash->texData[glyph->x0 + glyph->y0 * stash->params.width];
for (y = 0; y < gh; y++) {
/* unsigned char* fdst = &stash->texData[glyph->x0 + glyph->y0 * stash->params.width];
for (y = 0; y < gh; y++) {
for (x = 0; x < gw; x++) {
int a = (int)fdst[x+y*stash->params.width] + 20;
if (a > 255) a = 255;
fdst[x+y*stash->params.width] = a;
int a = (int)fdst[x+y*stash->params.width] + 20;
if (a > 255) a = 255;
fdst[x+y*stash->params.width] = a;
}
}*/
}*/

// Blur
if (iblur > 0) {
Expand All @@ -1173,8 +1173,8 @@ static FONSglyph* fons__getGlyph(FONScontext* stash, FONSfont* font, unsigned in
}

static void fons__getQuad(FONScontext* stash, FONSfont* font,
int prevGlyphIndex, FONSglyph* glyph,
float scale, float spacing, float* x, float* y, FONSquad* q)
int prevGlyphIndex, FONSglyph* glyph,
float scale, float spacing, float* x, float* y, FONSquad* q)
{
float rx,ry,xoff,yoff,x0,y0,x1,y1;

Expand Down Expand Up @@ -1282,8 +1282,8 @@ static float fons__getVertAlign(FONScontext* stash, FONSfont* font, int align, s
}

float fonsDrawText(FONScontext* stash,
float x, float y,
const char* str, const char* end)
float x, float y,
const char* str, const char* end)
{
FONSstate* state = fons__getState(stash);
unsigned int codepoint;
Expand Down Expand Up @@ -1346,7 +1346,7 @@ float fonsDrawText(FONScontext* stash,
}

int fonsTextIterInit(FONScontext* stash, FONStextIter* iter,
float x, float y, const char* str, const char* end, int bitmapOption)
float x, float y, const char* str, const char* end, int bitmapOption)
{
FONSstate* state = fons__getState(stash);
float width;
Expand Down Expand Up @@ -1468,9 +1468,9 @@ void fonsDrawDebug(FONScontext* stash, float x, float y)
}

float fonsTextBounds(FONScontext* stash,
float x, float y,
const char* str, const char* end,
float* bounds)
float x, float y,
const char* str, const char* end,
float* bounds)
{
FONSstate* state = fons__getState(stash);
unsigned int codepoint;
Expand Down Expand Up @@ -1545,7 +1545,7 @@ float fonsTextBounds(FONScontext* stash,
}

void fonsVertMetrics(FONScontext* stash,
float* ascender, float* descender, float* lineh)
float* ascender, float* descender, float* lineh)
{
FONSfont* font;
FONSstate* state = fons__getState(stash);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading