/contrib/sdk/samples/freetype/txview/winlib/button.c |
---|
File deleted |
/contrib/sdk/samples/freetype/txview/winlib/link.h |
---|
File deleted |
/contrib/sdk/samples/freetype/txview/winlib/winlib.c |
---|
File deleted |
/contrib/sdk/samples/freetype/txview/winlib/control.h |
---|
File deleted |
/contrib/sdk/samples/freetype/txview/winlib/winlib.h |
---|
File deleted |
/contrib/sdk/samples/freetype/txview/pxdraw/pxdraw.h |
---|
File deleted |
/contrib/sdk/samples/freetype/txview/pxdraw/internal.h |
---|
File deleted |
/contrib/sdk/samples/freetype/txview/pxdraw/region.c |
---|
File deleted |
/contrib/sdk/samples/freetype/txview/pxdraw/dutils.c |
---|
File deleted |
/contrib/sdk/samples/freetype/txview/pxdraw/context.c |
---|
File deleted |
/contrib/sdk/samples/freetype/txview/tview.c |
---|
4,6 → 4,7 |
#include FT_FREETYPE_H |
#include FT_GLYPH_H |
#include "winlib.h" |
#include "draw2.h" |
int init_fontlib(); |
font_t *create_font(FT_Face face, int size); |
86,13 → 87,8 |
rect_t rc; |
int i; |
rc.l = 0; |
rc.t = 0; |
rc.r = txv->w; |
rc.b = txv->h; |
draw_rect(txv->ctx, 0, 0, txv->w, txv->h, 0xFFFFFFFF); |
px_fill_rect(txv->ctx, &rc, 0xFFFFFFFF); |
rc.l = txv->margins.l; |
rc.t = txv->margins.t; |
rc.r = txv->w - txv->margins.r; |
166,7 → 162,7 |
dst = txv->margins.t; |
src = dst + txv->line_height; |
rows = txv->line_height * (txv->pagesize-1); |
scroll_context(txv->ctx, dst, src, rows ); |
scroll_ctx(txv->ctx, dst, src, rows ); |
rc.l = txv->margins.l; |
rc.t = txv->margins.t + rows; |
173,7 → 169,7 |
rc.r = txv->w - txv->margins.r; |
rc.b = rc.t + txv->line_height; |
px_fill_rect(txv->ctx, &rc, 0xFFFFFFFF); |
draw_rect(txv->ctx, rc.l, rc.t, rc.r - rc.l, txv->line_height, 0xFFFFFFFF); |
draw_text_ext(txv->ctx, txv->font, txv->line[txv->endline], |
txv->line[txv->endline+1]-txv->line[txv->endline], &rc, 0xFF000000); |
185,7 → 181,7 |
{ |
rc.t+= txv->line_height; |
rc.b+= txv->line_height; |
px_fill_rect(txv->ctx, &rc, 0xFFFFFFFF); |
draw_rect(txv->ctx, rc.l, rc.t, rc.r - rc.l, txv->line_height, 0xFFFFFFFF); |
draw_text_ext(txv->ctx, txv->font, txv->line[txv->endline], |
txv->line[txv->endline+1]-txv->line[txv->endline], &rc, 0xFF000000); |
} |
206,7 → 202,7 |
src = txv->margins.t; |
dst = src + txv->line_height; |
scroll_context(txv->ctx, dst, src, rows); |
scroll_ctx(txv->ctx, dst, src, rows); |
rc.l = txv->margins.l; |
rc.t = txv->margins.t; |
213,7 → 209,7 |
rc.r = txv->w - txv->margins.r; |
rc.b = rc.t + txv->line_height; |
px_fill_rect(txv->ctx, &rc, 0xFFFFFFFF); |
draw_rect(txv->ctx, rc.l, rc.t, rc.r - rc.l, txv->line_height, 0xFFFFFFFF); |
txv->startline--; |
txv->endline--; |
/contrib/sdk/samples/freetype/txview/fontlib.c |
---|
6,12 → 6,19 |
#include <ft2build.h> |
#include FT_FREETYPE_H |
#include FT_GLYPH_H |
#include <pxdraw.h> |
#include <pixlib2.h> |
typedef struct |
{ |
int l; |
int t; |
int r; |
int b; |
}rect_t; |
typedef struct |
{ |
FT_Face face; |
int fontsize; |
int height; |
int base; |
20,10 → 27,7 |
}font_t; |
static FT_Face def_face; |
static FT_Face sym_face; |
font_t *sym_font; |
typedef unsigned int color_t; |
unsigned int ansi2utf32(unsigned char ch); |
30,30 → 34,56 |
font_t *create_font(FT_Face face, int size); |
void draw_glyph(ctx_t *ctx, void *buffer, int pitch, rect_t *rc, color_t color); |
void my_draw_bitmap(bitmap_t *win, FT_Bitmap *bitmap, int dstx, int dsty, int col) |
{ |
uint8_t *dst; |
uint8_t *src, *tmpsrc; |
unsigned int ansi2utf32(unsigned char ch) |
uint32_t *tmpdst; |
int i, j; |
dst = win->data + dsty * win->pitch + dstx*4; |
src = bitmap->buffer; |
// printf("buffer %x width %d rows %d\n", |
// bitmap->buffer, bitmap->width, bitmap->rows); |
for( i = 0; i < bitmap->rows; i++ ) |
{ |
if(ch < 0x80) |
return ch; |
tmpdst = (uint32_t*)dst; |
tmpsrc = src; |
if(ch < 0xB0) |
return 0x410-0x80 + ch; |
dst+= win->pitch; |
src+= bitmap->pitch; |
if(ch < 0xE0) |
return 0; |
for( j = 0; j < bitmap->width; j++) |
{ |
int a = *tmpsrc++; |
int sr, sg, sb; |
int dr, dg, db; |
if(ch < 0xF0) |
return 0x440-0xE0 + ch; |
if( a != 0) a++; |
if(ch == 0xF0) |
return 0x401; |
else if(ch==0xF1) |
return 0x451; |
else return 0; |
db = *tmpdst & 0xFF; |
dg = (*tmpdst >> 8) & 0xFF; |
dr = (*tmpdst >> 16) & 0xFF; |
sb = col & 0xFF; |
sg = (col >> 8) & 0xFF; |
sr = (col >> 16) &0xFF; |
db = (a*sb + db*(256-a))/256; |
dg = (a*sg + dg*(256-a))/256; |
dr = (a*sr + dr*(256-a))/256; |
*tmpdst++ = 0xFF000000|(dr<<16)|(dg<<8)|db; |
}; |
} |
}; |
int draw_text_ext(ctx_t *ctx, font_t *font, char *text, int len, rect_t *rc, color_t color) |
int draw_text_ext(bitmap_t *winbitmap, font_t *font, char *text, int len, rect_t *rc, int color) |
{ |
FT_UInt glyph_index; |
FT_Bool use_kerning = 0; |
60,7 → 90,7 |
FT_BitmapGlyph glyph; |
FT_UInt previous; |
int x, y, xend; |
int x, y, w; |
int col, ncol; |
unsigned char ch; |
int err = 0; |
70,9 → 100,10 |
col = 0; |
x = rc->l << 6; |
xend = rc->r << 6; |
y = rc->t + font->base; |
y = rc->b; |
w = (rc->r - rc->l) << 6; |
while( len-- ) |
{ |
ch = *text++; |
82,7 → 113,7 |
if(ch == '\t') |
{ |
ncol = (col+3) & ~4; |
ncol = (col+4) & ~3; |
if( col < ncol) |
{ |
glyph_index = FT_Get_Char_Index( font->face, ansi2utf32(' ') ); |
96,7 → 127,7 |
x += delta.x ; |
} |
if( x + (font->glyph[ch]->advance.x >> 10) >= xend) |
if( x + (font->glyph[ch]->advance.x >> 10) > w) |
break; |
x += font->glyph[ch]->advance.x >> 10; |
116,30 → 147,15 |
x += delta.x ; |
} |
// if( x + (font->glyph[ch]->advance.x >> 10) >= xend) |
// break; |
if( x >= xend) |
if( x + (font->glyph[ch]->advance.x >> 10) > w) |
break; |
glyph = (FT_BitmapGlyph)font->glyph[ch]; |
if(glyph != NULL) |
{ |
rect_t rc_dst; |
my_draw_bitmap(winbitmap, &glyph->bitmap, (x >> 6) + glyph->left, |
y - glyph->top, color); |
rc_dst.l = (x >> 6) + glyph->left; |
rc_dst.t = y - glyph->top; |
rc_dst.r = rc_dst.l + glyph->bitmap.width; |
if(rc_dst.r > (xend >> 6)) |
rc_dst.r = xend >> 6; |
rc_dst.b = rc_dst.t + glyph->bitmap.rows; |
// printf("char: %c ", ch); |
px_draw_glyph(ctx, glyph->bitmap.buffer, glyph->bitmap.pitch, &rc_dst, color); |
x += font->glyph[ch]->advance.x >> 10; |
}; |
previous = glyph_index; |
}; |
164,6 → 180,7 |
// err = FT_New_Face( library, "/kolibrios/Fonts/lucon.ttf", 0, &face ); |
err = FT_New_Face( library, "/kolibrios/Fonts/DroidSansMono.ttf", 0, &face ); |
if ( err == FT_Err_Unknown_File_Format ) |
{ |
printf("font format is unsupported\n"); |
174,33 → 191,37 |
{ |
printf("font file could not be read or broken\n"); |
goto done; |
} |
def_face = face; |
err = FT_New_Face( library, "/kolibrios/Fonts/Symbols.ttf", 0, &face ); |
if ( err == FT_Err_Unknown_File_Format ) |
{ |
printf("font format is unsupported\n"); |
goto done; |
done: |
} |
else if ( err ) |
{ |
printf("font file could not be read or broken\n"); |
goto done; |
} |
return err; |
}; |
sym_face = face; |
sym_font = create_font(sym_face, 14); |
unsigned int ansi2utf32(unsigned char ch) |
{ |
if(ch < 0x80) |
return ch; |
done: |
if(ch < 0xB0) |
return 0x410-0x80 + ch; |
return err; |
}; |
if(ch < 0xE0) |
return 0; |
if(ch < 0xF0) |
return 0x440-0xE0 + ch; |
if(ch == 0xF0) |
return 0x401; |
else if(ch==0xF1) |
return 0x451; |
else return 0; |
} |
font_t *create_font(FT_Face xface, int size) |
215,7 → 236,7 |
memset(font, 0, sizeof(*font)); |
font->face = (xface == NULL) ? def_face : xface; |
font->height = size; |
font->height = size+1; |
err = FT_Set_Pixel_Sizes( font->face, 0, size ); |
255,9 → 276,3 |
return font; |
} |
int get_font_height(font_t *font) |
{ |
return font->height; |
} |
/contrib/sdk/samples/freetype/txview/main.c |
---|
1,4 → 1,3 |
#include <stdio.h> |
#include <string.h> |
#include <ft2build.h> |
5,32 → 4,50 |
#include FT_FREETYPE_H |
#include FT_GLYPH_H |
#include <kos32sys.h> |
#include <pixlib2.h> |
#include "winlib.h" |
typedef struct |
{ |
int l; |
int t; |
int r; |
int b; |
}rect_t; |
typedef struct |
{ |
FT_Face face; |
int height; |
int base; |
typedef struct tview *tview_t; |
FT_Glyph glyph[256]; |
tview_t *create_tview(ctx_t *ctx, int width, int height); |
void txv_get_margins(const tview_t *txv, rect_t *margins); |
void txv_set_margins(tview_t *txv, const rect_t *margins); |
}font_t; |
typedef struct |
{ |
bitmap_t bitmap; |
font_t *font; |
char *text; |
char **line; |
int lines; |
int txlines; |
int startline; |
int endline; |
int w; |
int h; |
}tview_t; |
int init_tview(tview_t *txv, int width, int height, char *text, int size); |
void txv_set_size(tview_t *txv, int txw, int txh); |
void txv_set_font_size(tview_t *txv, int size); |
int txv_get_font_size(tview_t *txv); |
void txv_set_text(tview_t *txv, char *text, int size); |
int txv_scroll_up(tview_t *txv); |
int txv_scroll_down(tview_t *txv); |
int txv_page_up(tview_t *txv); |
int txv_page_down(tview_t *txv); |
typedef struct |
{ |
volatile int lock; |
unsigned int handle; |
}mutex_t; |
void* init_fontlib(); |
int draw_text_ext(bitmap_t *winbitmap, FT_Face face, char *text, int len, rect_t *rc, int color); |
void draw_window(void) |
{ |
39,21 → 56,15 |
EndDraw(); |
} |
tview_t *txv; |
tview_t txv; |
int main(int argc, char *argv[]) |
{ |
ufile_t uf; |
oskey_t key; |
ctx_t *ctx; |
rect_t margins = {4,2,20,0}; |
int clw = 640; |
int clh = 480; |
__asm__ __volatile__( |
"int $0x40" |
::"a"(40), "b"(0xc0000027)); |
66,18 → 77,16 |
uf.size == 0) |
return 0; |
ctx = create_context(TYPE_3_BORDER_WIDTH, get_skin_height(), clw, clh); |
init_pixlib(0); |
init_fontlib(); |
txv = create_tview(ctx, clw, clh); |
txv_set_margins(txv, &margins); |
txv_set_text(txv, uf.data, uf.size); |
init_tview(&txv, clw, clh, uf.data, uf.size); |
BeginDraw(); |
DrawWindow(10, 40, clw+TYPE_3_BORDER_WIDTH*2, |
clh+TYPE_3_BORDER_WIDTH+get_skin_height(), "Text example", 0x000000, 0x73); |
show_context(ctx); |
blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); |
EndDraw(); |
for (;;) |
93,14 → 102,8 |
char proc_info[1024]; |
int winx, winy, winw, winh; |
int txw, txh; |
char state; |
draw_window(); |
get_proc_info(proc_info); |
state = *(char*)(proc_info+70); |
if(state & (WIN_STATE_MINIMIZED|WIN_STATE_ROLLED)) |
continue; |
winx = *(uint32_t*)(proc_info+34); |
winy = *(uint32_t*)(proc_info+38); |
113,56 → 116,47 |
if( (txw != clw) || |
(txh != clh) ) |
{ |
resize_context(ctx, txw, txh); |
txv_set_size(txv, txw, txh); |
txv_set_size(&txv, txw, txh); |
clw = txw; |
clh = txh; |
}; |
show_context(ctx); |
draw_window(); |
blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); |
break; |
} |
case 2: |
key = get_key(); |
// printf("key %d\n", key.code); |
printf("key %d\n", key.code); |
switch(key.code) |
{ |
case 27: |
return 0; |
return; |
case 45: |
txv_set_font_size(txv, txv_get_font_size(txv) - 2); |
show_context(ctx); |
txv_set_font_size(&txv, txv.font->height-3); |
blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); |
break; |
case 61: |
txv_set_font_size(txv, txv_get_font_size(txv) + 2); |
show_context(ctx); |
txv_set_font_size(&txv, txv.font->height+1); |
blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); |
break; |
case 177: |
if( txv_scroll_down(txv) ) |
show_context(ctx); |
if( txv_scroll_up(&txv) ) |
blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); |
break; |
case 178: |
if( txv_scroll_up(txv) ) |
show_context(ctx); |
if( txv_scroll_down(&txv) ) |
blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); |
break; |
case 183: |
if( txv_page_down(txv) ) |
show_context(ctx); |
break; |
case 184: |
if( txv_page_up(txv) ) |
show_context(ctx); |
break; |
} |
break; |
case 3: |
// button pressed; we have only one button, close |
return 0; |
return; |
case 6: |
// pos = get_mouse_pos(); |
171,15 → 165,15 |
if( wheels & 0xFFFF) |
{ |
int r = 0; |
int r; |
if((short)wheels > 0) |
r = txv_scroll_down(txv); |
else if((short)wheels < 0) |
r = txv_scroll_up(txv); |
r = txv_scroll_up(&txv); |
else |
r = txv_scroll_down(&txv); |
if( r ) |
show_context(ctx); |
blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); |
} |
} |
} |
/contrib/sdk/samples/freetype/txview/Makefile |
---|
1,33 → 1,19 |
CC = kos32-gcc |
LD = kos32-ld |
AR = kos32-ar |
SDK_DIR:= $(abspath ../../..) |
CONTRIB_DIR:= $(abspath ../../../..) |
LDFLAGS = -static --subsystem native -Tapp-dynamic.lds -Map txview.map --image-base 0 |
LDFLAGS = -static -S -nostdlib -T $(SDK_DIR)/sources/newlib/app.lds -Map txview.map --image-base 0 |
CFLAGS = -c -O2 -msse2 -fno-ident -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32 |
CFLAGS = -c -fno-ident -O2 -fomit-frame-pointer -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32 |
INCLUDES= -I./winlib -I./pxdraw -I $(SDK_DIR)/sources/newlib/libc/include -I $(SDK_DIR)/sources/freetype/include |
INCLUDES+= -I $(CONTRIB_DIR)/toolchain/binutils/bfd -I $(CONTRIB_DIR)/toolchain/binutils/include |
LIBPATH:= -L./ -L $(SDK_DIR)/lib |
INCLUDES= -I $(SDK_DIR)/sources/newlib/libc/include -I $(SDK_DIR)/sources/freetype/include |
LIBPATH:= -L $(SDK_DIR)/lib -L /home/autobuild/tools/win32/mingw32/lib |
LIB_SRCS= \ |
pxdraw/context.c \ |
pxdraw/dutils.c \ |
pxdraw/region.c \ |
winlib/button.c \ |
winlib/winlib.c \ |
$(NULL) |
SOURCES = main.c \ |
fontlib.c \ |
tview.c \ |
$(NULL) |
tview.c |
LIB_OBJS = $(patsubst %.c, %.o, $(LIB_SRCS)) |
OBJECTS = $(patsubst %.c, %.o, $(SOURCES)) |
34,16 → 20,10 |
default: txview |
libwin.a: $(LIB_OBJS) Makefile |
$(AR) crs $@ $(LIB_OBJS) |
txview: $(OBJECTS) Makefile |
$(LD) $(LDFLAGS) $(LIBPATH) -o txview $(OBJECTS) -lfreetype.dll -lpixlib.dll -lgcc -lc.dll -lapp |
objcopy txview -O binary |
txview: $(OBJECTS) libwin.a Makefile |
$(LD) $(LDFLAGS) $(LIBPATH) -o txview.dll $(OBJECTS) -lfreetype.dll -lpixlib3 -lwin -lgcc -lc.dll |
# objdump -d txview.dll > txview.lst |
objcopy txview.dll txview -O binary |
clean: |
/bin/rm -rf *.o txview |
%.o : %.c Makefile $(SOURCES) |
$(CC) $(CFLAGS) $(INCLUDES) -o $@ $< |