From 7f270942a7e2988401a831bc01a94a2bd0a27b2a Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 17 Jan 2017 13:54:23 -0500 Subject: [PATCH] And fixed errors. Woo, it works!!!!! --- common/attrstr.c | 4 +++- darwin/drawtext.m | 3 ++- examples/drawtext/main.c | 5 ++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/common/attrstr.c b/common/attrstr.c index 891453cd..bfe42842 100644 --- a/common/attrstr.c +++ b/common/attrstr.c @@ -131,7 +131,9 @@ void uiAttributedStringInsertAtUnattributed(uiAttributedString *s, const char *s // TODO } - at16 = s->u8tou16[at]; + at16 = 0; + if (s->u8tou16 != NULL) + at16 = s->u8tou16[at]; // do this first to reclaim memory invalidateGraphemes(s); diff --git a/darwin/drawtext.m b/darwin/drawtext.m index 4296d35a..a8a34542 100644 --- a/darwin/drawtext.m +++ b/darwin/drawtext.m @@ -231,7 +231,8 @@ void uiDrawText(uiDrawContext *c, uiDrawTextLayout *tl, double x, double y) CGContextSetTextMatrix(c->c, CGAffineTransformIdentity); // wait, that's not enough; we need to offset y values to account for our new flipping - y = c->height - y; + // TODO explain this calculation + y = c->height - tl->size.height - y; // CTFrameDraw() draws in the path we specified when creating the frame // this means that in our usage, CTFrameDraw() will draw at (0,0) diff --git a/examples/drawtext/main.c b/examples/drawtext/main.c index 90c401ee..f2580504 100644 --- a/examples/drawtext/main.c +++ b/examples/drawtext/main.c @@ -34,7 +34,7 @@ uiDrawFontDescriptor defaultFont = { }; uiAttributedString *attrstr; -#define margins 5 +#define margins 10 static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p) { @@ -113,8 +113,7 @@ int main(void) attrstr = uiNewAttributedString(text); - mainwin = uiNewWindow("libui Histogram Example", 640, 480, 1); - uiWindowSetMargined(mainwin, 1); + mainwin = uiNewWindow("libui Text-Drawing Example", 640, 480, 1); uiWindowOnClosing(mainwin, onClosing, NULL); area = uiNewArea(&handler);