Browse Source

Handle tab and newline, fix underscore

master
Macoy Madson 5 months ago
parent
commit
6cd26f72a9
  1. 7
      src/FontAtlas.cake
  2. 26
      src/Presentation.cake

7
src/FontAtlas.cake

@ -11,8 +11,8 @@
y uint16_t
width uint16_t
height uint16_t
to-origin-left uint16_t
to-origin-top uint16_t
to-origin-left int16_t
to-origin-top int16_t
advance-x uint16_t)
(defstruct font-atlas
@ -28,6 +28,7 @@
;; Returns 0 for success or anything else for failure
(defun build-font-atlas (font-face (* (const (unsigned char)))
font-face-size (unsigned int)
character-height-points (unsigned char)
font-atlas-out (* font-atlas) &return int)
(var freetype-library FT_Library)
(var result int
@ -47,7 +48,7 @@
(set result (FT_Set_Char_Size
typeface ;; handle to face object
0 ;; char_width in 1/64th of points
(* 16 64) ;; char_height in 1/64th of points
(* character-height-points 64) ;; char_height in 1/64th of points
300 ;; horizontal device resolution
300)) ;; vertical device resolution

26
src/Presentation.cake

@ -31,7 +31,18 @@
x int y int str (* (const char)))
(var write-x int x)
(var write-y int y)
(var tab-width int 100)
(var line-height int 100)
(each-char-in-string-const str current-char
(cond
((= (deref current-char) '\n')
(set write-y (+ line-height write-y))
(set write-x x)
(continue))
((= (deref current-char) '\t')
(set write-x (+ write-x tab-width))
(continue)))
(var search-key char (deref current-char))
(var glyph (* glyph-entry) (dict-ptr-at (path font > glyph-lookup-table) search-key))
(unless glyph ;; fallback
@ -74,8 +85,10 @@
(defer (SDL_DestroyRenderer renderer))
(var ubuntu-regular-font-atlas font-atlas (array 0))
(var font-size-points (unsigned char) 12)
(unless (= 0 (build-font-atlas s-start-ubuntu-regular-font
(- s-end-ubuntu-regular-font s-start-ubuntu-regular-font)
font-size-points
(addr ubuntu-regular-font-atlas)))
(return 1))
(defer (free-font-atlas (addr ubuntu-regular-font-atlas)))
@ -127,8 +140,17 @@
(sdl-print-error)
(set exit-reason "SDL failed to render font atlas")))
(render-string renderer (addr ubuntu-regular-font-atlas) ubuntu-regular-texture
200 600 "This is a test!")
(render-string
renderer (addr ubuntu-regular-font-atlas) ubuntu-regular-texture
200 600
#"#result= FT_Set_Char_Size(typeface, 0, (16 * 64), 300, 300);
if (!((result== FT_Err_Ok)))
{
fprintf(stderr, "error: encountered error %d while %s\n", result, "setting character size");
FT_Done_Face(typeface);
FT_Done_FreeType(freetypeLibrary);
return 1;
}#"#)
(SDL_RenderPresent renderer)
(SDL_UpdateWindowSurface window)

Loading…
Cancel
Save