#include <math.h>
#include <helianthus.h>
#include "font.h"
static Font font;
void fontInit() {
font = createFont("data/fonts/blackcry.ttf");
}
void fontDraw() {
saveState();
double x = 512;
double y = 256;
fill(colorByName("1 0 0 0.5"));
textSize(64*(1+sin(windowGetSeconds()/4)));
text(x, y, "Here is the\nleft aligned\ntext. VAW.");
noFill();
textFont(font);
textAlign(HALIGN_RIGHT, VALIGN_TOP);
text(x, y, "Here is the\nright aligned\ntext. VAW.");
resetState();
x = 196;
y = 384;
double w = 128;
double h = 96;
int haligns[] = { HALIGN_LEFT, HALIGN_CENTER, HALIGN_RIGHT };
int valigns[] = { VALIGN_TOP, VALIGN_CENTER, VALIGN_BOTTOM };
const char *ht[] = { "left", "center I", "right" };
const char *vt[] = { "top", "center", "bottom q" };
for(int j = 0; j < 3; ++j) {
for(int i = 0; i < 3; ++i) {
double xx = x + (1-i)*w/2;
double yy = y + (1-j)*h/2;
textAlign(haligns[i], valigns[j]);
if (i == 1 && j == 1) {
TextLayout layout = createTextLayoutf("%s\n%s", ht[i], vt[j]);
textLayoutDraw(layout, xx, yy);
saveState();
strokeWidth(0.5);
double ex = 10;
double l = textLayoutGetLeft(layout);
double t = textLayoutGetTop(layout);
double w = textLayoutGetWidth(layout);
double h = textLayoutGetHeight(layout);
double a = textLayoutGetTopAscenderLine(layout);
double x = textLayoutGetTopXLine(layout);
double b = textLayoutGetBottomBaseline(layout);
line( xx+l-ex , yy+t , xx+l+w+ex , yy+t );
line( xx+l-ex , yy+t+h , xx+l+w+ex , yy+t+h );
line( xx+l , yy+t-ex , xx+l , yy+t+h+ex );
line( xx+l+w , yy+t-ex , xx+l+w , yy+t+h+ex );
line( xx+l-ex , yy+a , xx+l+w+ex , yy+a );
line( xx+l-ex , yy+x , xx+l+w+ex , yy+x );
line( xx+l-ex , yy+b , xx+l+w+ex , yy+b );
restoreState();
textLayoutDestroy(layout);
} else {
textf(xx, yy, "%s\n%s", ht[i], vt[j]);
}
}
}
line(x - 1.5*w, y - h/2, x + 1.5*w, y - h/2);
line(x - 1.5*w, y + h/2, x + 1.5*w, y + h/2);
line(x - w/2, y - 1.5*h, x - w/2, y + 1.5*h);
line(x + w/2, y - 1.5*h, x + w/2, y + 1.5*h);
noFill();
textAlign(HALIGN_CENTER, VALIGN_CENTER);
const char *chars = "zlpvoxS";
for(int i = 0; i < 7; ++i)
textf(x - w/2 + (i + 1)/8.0*w, y + h/2, "%c", chars[i]);
restoreState();
}