Started a hit-test and grapheme boundary test. Looks like we're not quite out of the woods with DirectWrite just yet.
This commit is contained in:
parent
87b7d5b4b7
commit
339bdfc89b
|
@ -33,6 +33,7 @@ endif()
|
|||
|
||||
_add_example(drawtext
|
||||
drawtext/basic.c
|
||||
drawtext/hittest.c
|
||||
drawtext/main.c
|
||||
${_EXAMPLE_RESOURCES_RC}
|
||||
)
|
||||
|
|
|
@ -15,3 +15,6 @@ extern void redraw(void);
|
|||
|
||||
// basic.c
|
||||
extern struct example *mkBasicExample(void);
|
||||
|
||||
// hittest.c
|
||||
extern struct example *mkHitTestExample(void);
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
// 20 january 2017
|
||||
#include "drawtext.h"
|
||||
|
||||
static const char *text =
|
||||
"Each of the glyphs an end user interacts with are called graphemes. "
|
||||
"If you enter a byte range in the text boxes below and click the button, you can see the blue box move to surround that byte range, as well as what the actual byte range necessary is. "
|
||||
"You'll also see the index of the first grapheme; uiAttributedString has facilities for converting between UTF-8 code points and grapheme indices. "
|
||||
"Additionally, click on the string to move the caret. Watch the status text at the bottom change too. "
|
||||
"That being said: "
|
||||
"\xC3\x93O\xCC\x81 (combining accents) "
|
||||
"A\xCC\x81\xE0\xAB\x81 (multiple combining accents) "
|
||||
"\xE2\x80\xAE#\xE2\x80\xAC (RTL glyph) "
|
||||
"\xF0\x9F\x92\xBB (non-BMP character) "
|
||||
"\xF0\x9F\x92\xBB\xCC\x80 (combined non-BMP character) "
|
||||
"";
|
||||
static char fontFamily[] = "Helvetica";
|
||||
static uiDrawFontDescriptor defaultFont = {
|
||||
.Family = fontFamily,
|
||||
.Size = 14,
|
||||
.Weight = uiDrawTextWeightNormal,
|
||||
.Italic = uiDrawTextItalicNormal,
|
||||
.Stretch = uiDrawTextStretchNormal,
|
||||
};
|
||||
static uiAttributedString *attrstr;
|
||||
|
||||
#define margins 10
|
||||
|
||||
static uiBox *panel;
|
||||
|
||||
static void draw(uiAreaDrawParams *p)
|
||||
{
|
||||
uiDrawPath *path;
|
||||
uiDrawTextLayout *layout;
|
||||
|
||||
// only clip the text, not the guides
|
||||
uiDrawSave(p->Context);
|
||||
|
||||
path = uiDrawNewPath(uiDrawFillModeWinding);
|
||||
uiDrawPathAddRectangle(path, margins, margins,
|
||||
p->AreaWidth - 2 * margins,
|
||||
p->AreaHeight - 2 * margins);
|
||||
uiDrawPathEnd(path);
|
||||
uiDrawClip(p->Context, path);
|
||||
uiDrawFreePath(path);
|
||||
|
||||
layout = uiDrawNewTextLayout(attrstr,
|
||||
&defaultFont,
|
||||
p->AreaWidth - 2 * margins);
|
||||
uiDrawText(p->Context, layout, margins, margins);
|
||||
|
||||
uiDrawRestore(p->Context);
|
||||
|
||||
uiDrawFreeTextLayout(layout);
|
||||
}
|
||||
|
||||
static struct example hitTestExample;
|
||||
|
||||
struct example *mkHitTestExample(void)
|
||||
{
|
||||
panel = uiNewVerticalBox();
|
||||
|
||||
hitTestExample.name = "Hit-Testing and Grapheme Boundaries";
|
||||
hitTestExample.panel = uiControl(panel);
|
||||
hitTestExample.draw = draw;
|
||||
|
||||
attrstr = uiNewAttributedString(text);
|
||||
|
||||
return &hitTestExample;
|
||||
}
|
|
@ -100,6 +100,12 @@ int main(void)
|
|||
n = 0;
|
||||
examples[n] = mkBasicExample();
|
||||
uiComboboxAppend(exampleList, examples[n]->name);
|
||||
uiControlHide(examples[n]->panel);
|
||||
uiBoxAppend(box, examples[n]->panel, 0);
|
||||
n++;
|
||||
examples[n] = mkHitTestExample();
|
||||
uiComboboxAppend(exampleList, examples[n]->name);
|
||||
uiControlHide(examples[n]->panel);
|
||||
uiBoxAppend(box, examples[n]->panel, 0);
|
||||
n++;
|
||||
// and set things up for the initial state
|
||||
|
|
Loading…
Reference in New Issue