Fixed build errors. DOES IT WORK?!?!?!?!?!?!?!?!

This commit is contained in:
Pietro Gagliardi 2017-01-17 13:05:40 -05:00
parent 794d30154c
commit 7bda3baee3
10 changed files with 45 additions and 43 deletions

View File

@ -168,7 +168,7 @@ static struct attr *attrDropRange(struct attrlist *alist, struct attr *a, size_t
// we are dropping the left half, so set a->start and unlink
a->start = end;
*tail = a;
return attrUnlink(attr, a);
return attrUnlink(alist, a);
}
if (a->end == end) { // chop off the end
// we are dropping the right half, so just set a->end
@ -321,11 +321,11 @@ void attrlistInsertAttribute(struct attrlist *alist, uiAttribute type, uintptr_t
// TODO will this cause problems with fonts?
// TODO will this reduce fragmentation if we first add from 0 to 2 and then from 2 to 4? or do we have to do that separately?
if (before->val == val) {
attrGrow(alist, a, start, end);
attrGrow(alist, before, start, end);
return;
}
// okay the values are different; we need to split apart
before = attrDropRange(alist, a, start, end, &tail);
before = attrDropRange(alist, before, start, end, &tail);
split = 1;
continue;
@ -486,9 +486,10 @@ void attrlistRemoveAttribute(struct attrlist *alist, uiAttribute type, size_t st
struct attr *tails = NULL; // see attrlistInsertCharactersUnattributed() above
struct attr *tailsAt = NULL;
a = alist->start;
a = alist->first;
while (a != NULL) {
size_t lstart, lend;
struct attr *tail;
// this defines where to re-attach the tails
// (all the tails will have their start at end, so we can just insert them all before tailsAt)
@ -532,9 +533,10 @@ void attrlistRemoveAttributes(struct attrlist *alist, size_t start, size_t end)
struct attr *tails = NULL; // see attrlistInsertCharactersUnattributed() above
struct attr *tailsAt = NULL;
a = alist->start;
a = alist->first;
while (a != NULL) {
size_t lstart, lend;
struct attr *tail;
// this defines where to re-attach the tails
// (all the tails will have their start at end, so we can just insert them all before tailsAt)
@ -578,7 +580,7 @@ void attrlistRemoveCharacters(struct attrlist *alist, size_t start, size_t end)
a = attrDeleteRange(alist, a, start, end);
}
void attrlistForEach(struct attr *alist, uiAttributedString *s, uiAttributedStringForEachAttributeFunc f, void *data)
void attrlistForEach(struct attrlist *alist, uiAttributedString *s, uiAttributedStringForEachAttributeFunc f, void *data)
{
struct attr *a;

View File

@ -120,7 +120,7 @@ void uiAttributedStringInsertAtUnattributed(uiAttributedString *s, const char *s
{
uint32_t rune;
char buf[4];
uint16_t u16buf[2];
uint16_t buf16[2];
size_t n8, n16;
size_t old, old16;
size_t oldlen, old16len;
@ -238,20 +238,20 @@ void uiAttributedStringDelete(uiAttributedString *s, size_t start, size_t end)
memmove(
s->s + start,
s->s + end,
(oldlen - end) * sizeof (char));
(s->len - end) * sizeof (char));
memmove(
s->u16 + start16,
s->u16 + end16,
(old16len - end16) * sizeof (uint16_t));
(s->u16len - end16) * sizeof (uint16_t));
// note the + 1 for these; we want to copy the terminating null too
memmove(
s->u8tou16 + start,
s->u8tou16 + end,
(oldlen - end + 1) * sizeof (size_t));
(s->len - end + 1) * sizeof (size_t));
memmove(
s->u16tou8 + start16,
s->u16tou8 + end16,
(old16len - end16 + 1) * sizeof (size_t));
(s->u16len - end16 + 1) * sizeof (size_t));
// update the conversion tables
// note the use of <= to include the null terminator
@ -308,7 +308,7 @@ const uint16_t *attrstrUTF16(uiAttributedString *s)
return s->u16;
}
size_t attrstrUTF16LEn(uiAttributedString *s)
size_t attrstrUTF16Len(uiAttributedString *s)
{
return s->u16len;
}

View File

@ -5,6 +5,7 @@ extern "C" {
#endif
#include <stdarg.h>
#include <string.h>
#include "controlsigs.h"
#include "utf.h"
@ -68,7 +69,7 @@ extern struct graphemes *graphemes(void *s, size_t len);
// attrstr.c
extern const uint16_t *attrstrUTF16(uiAttributedString *s);
extern size_t attrstrUTF16LEn(uiAttributedString *s);
extern size_t attrstrUTF16Len(uiAttributedString *s);
extern size_t attrstrUTF8ToUTF16(uiAttributedString *s, size_t n);
extern size_t *attrstrCopyUTF16ToUTF8(uiAttributedString *s, size_t *n);
@ -79,8 +80,8 @@ extern void attrlistInsertCharactersUnattributed(struct attrlist *alist, size_t
extern void attrlistInsertCharactersExtendingAttributes(struct attrlist *alist, size_t start, size_t count);
extern void attrlistRemoveAttribute(struct attrlist *alist, uiAttribute type, size_t start, size_t end);
extern void attrlistRemoveAttributes(struct attrlist *alist, size_t start, size_t end);
extern; void attrlistRemoveCharacters(struct attrlist *alist, size_t start, size_t end);
extern void attrlistForEach(struct attr *alist, uiAttributedString *s, uiAttributedStringForEachAttributeFunc f, void *data);
extern void attrlistRemoveCharacters(struct attrlist *alist, size_t start, size_t end);
extern void attrlistForEach(struct attrlist *alist, uiAttributedString *s, uiAttributedStringForEachAttributeFunc f, void *data);
// TODO move these to the top like everythng else
extern struct attrlist *attrlistNew(void);
extern void attrlistFree(struct attrlist *alist);

View File

@ -17,7 +17,7 @@ list(APPEND _LIBUI_SOURCES
darwin/drawtext.m
darwin/editablecombo.m
darwin/entry.m
darwin/fontbutton.m
#TODO darwin/fontbutton.m
darwin/fontmatch.m
darwin/form.m
darwin/graphemes.m
@ -44,7 +44,7 @@ list(APPEND _LIBUI_SOURCES
)
set(_LIBUI_SOURCES ${_LIBUI_SOURCES} PARENT_SCOPE)
// TODO is this correct?
# TODO is this correct?
list(APPEND _LIBUI_INCLUDEDIRS
darwin
)

View File

@ -443,8 +443,3 @@ void uiDrawRestore(uiDrawContext *c)
{
CGContextRestoreGState(c->c);
}
void uiDrawText(uiDrawContext *c, double x, double y, uiDrawTextLayout *layout)
{
doDrawText(c->c, c->height, x, y, layout);
}

View File

@ -82,10 +82,10 @@ static CFAttributedStringRef attrstrToCoreFoundation(uiAttributedString *s, uiDr
return mas;
}
static uiDrawTextLayoutLineMetrics *computeLineMetrics(CTFrame frame, CGSize size)
static uiDrawTextLayoutLineMetrics *computeLineMetrics(CTFrameRef frame, CGSize size)
{
uiDrawTextLayoutLineMetrics *metrics;
CFArray lines;
CFArrayRef lines;
CTLineRef line;
CFIndex i, n;
CGFloat ypos;
@ -95,10 +95,9 @@ static uiDrawTextLayoutLineMetrics *computeLineMetrics(CTFrame frame, CGSize siz
lines = CTFrameGetLines(frame);
n = CFArrayGetCount(lines);
metrics = (uiDrawTextLay
outLineMetrics *) uiAlloc(n * sizeof (uiDrawTextLayoutLineMetrics), "uiDrawTextLayoutLineMetrics[] (text layout)");
metrics = (uiDrawTextLayoutLineMetrics *) uiAlloc(n * sizeof (uiDrawTextLayoutLineMetrics), "uiDrawTextLayoutLineMetrics[] (text layout)");
origins = (CGFloat *) uiAlloc(n * sizeof (CGFloat), "CGFloat[] (text layout)");
origins = (CGPoint *) uiAlloc(n * sizeof (CGPoint), "CGPoint[] (text layout)");
CTFrameGetLineOrigins(frame, CFRangeMake(0, n), origins);
ypos = size.height;
@ -183,9 +182,9 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiAttributedString *s, uiDrawFontDescripto
// TODO kCTFramePathWidthAttributeName?
NULL,
CGSizeMake(cgwidth, CGFLOAT_MAX),
&unused); // not documented as accepting NULL
&unused); // not documented as accepting NULL (TODO really?)
rect.origin = CGZeroPoint;
rect.origin = CGPointZero;
rect.size = tl->size;
tl->path = CGPathCreateWithRect(rect, NULL);
tl->frame = CTFramesetterCreateFrame(tl->framesetter,
@ -227,7 +226,7 @@ void uiDrawText(uiDrawContext *c, uiDrawTextLayout *tl, double x, double y)
// Core Text doesn't draw onto a flipped view correctly; we have to pretend it was unflipped
// see the iOS bits of the first example at https://developer.apple.com/library/mac/documentation/StringsTextFonts/Conceptual/CoreText_Programming/LayoutOperations/LayoutOperations.html#//apple_ref/doc/uid/TP40005533-CH12-SW1 (iOS is naturally flipped)
// TODO how is this affected by a non-identity CTM?
CGContextTranslateCTM(c->c, 0, cheight);
CGContextTranslateCTM(c->c, 0, c->height);
CGContextScaleCTM(c->c, 1.0, -1.0);
CGContextSetTextMatrix(c->c, CGAffineTransformIdentity);
@ -280,9 +279,8 @@ void uiDrawTextLayoutByteIndexToGraphemeRect(uiDrawTextLayout *tl, size_t pos, i
void uiDrawTextLayoutHitTest(uiDrawTextLayout *tl, double x, double y, uiDrawTextLayoutHitTestResult *result)
{
CFIndex i;
CTLine line;
CTLineRef line;
CFIndex pos;
CGFloat charLeft, charRight;
if (y >= 0) {
for (i = 0; i < tl->nLines; i++) {
@ -302,28 +300,26 @@ void uiDrawTextLayoutHitTest(uiDrawTextLayout *tl, double x, double y, uiDrawTex
i = 0;
result->YPosition = uiDrawTextLayoutHitTestPositionBefore;
}
m->Line = i;
result->Line = i;
result->XPosition = uiDrawTextLayoutHitTestPositionInside;
if (x < tl->lineMetrics[i].X) {
result->XPosition = uiDrawTextLay
outHitTestPositionBefore;
result->XPosition = uiDrawTextLayoutHitTestPositionBefore;
// and forcibly return the first character
x = tl->lineMetrics[i].X;
} else if (x > (tl->lineMetrics[i].X + tl->lineMetrics[i].Width)) {
result->XPosition = uiDrawTextLayoutHitTestP
ositionAfter;
result->XPosition = uiDrawTextLayoutHitTestPositionAfter;
// and forcibly return the last character
x = tl->lineMetrics[i].X + tl->lineMetrics[i].Width;
}
line = (CTLineRef) CFArrayGetValueAtIndex(tl->lines, i);
pos = CTLineGetStringIndexForPosition(line, CGP
ointMake(x, 0));
// TODO copy the part from the docs about this point
pos = CTLineGetStringIndexForPosition(line, CGPointMake(x, 0));
if (pos == kCFNotFound) {
// TODO
}
m->Pos = tl->u16tou8[pos];
result->Pos = tl->u16tou8[pos];
}
void uiDrawTextLayoutByteRangeToRectangle(uiDrawTextLayout *tl, size_t start, size_t end, uiDrawTextLayoutByteRangeRectangle *r)

View File

@ -54,7 +54,7 @@ static const struct italicCloseness italicClosenesses[] = {
// TODO there is still one catch that might matter from a user's POV: the reverse is not true the italic bit can be set even if the style of the font face/subfamily/style isn't named as Italic (for example, script typefaces like Adobe's Palace Script MT Std); I don't know what to do about this... I know how to start: find a script font that has an italic form (Adobe's Palace Script MT Std does not; only Regular and Semibold)
static double italicCloseness(CTFontDescriptorRef desc, CFDictionaryRef traits, uiDrawTextItalic italic)
{
struct italicCloseness *ic = &(italicClosenesses[italic]);
const struct italicCloseness *ic = &(italicClosenesses[italic]);
CFNumberRef cfnum;
CTFontSymbolicTraits symbolic;
// there is no kCFNumberUInt32Type, but CTFontSymbolicTraits is uint32_t, so SInt32 should work
@ -77,7 +77,7 @@ static double italicCloseness(CTFontDescriptorRef desc, CFDictionaryRef traits,
// Okay, now we know it's either Italic or Oblique
// Pango's Core Text code just does a g_strrstr() (backwards case-sensitive search) for "Oblique" in the font's style name (see https://git.gnome.org/browse/pango/tree/pango/pangocoretext-fontmap.c); let's do that too I guess
isOblique = NO; // default value
styleName = (CFStringRef) CTFontDescriptorCopyAttribute(current, kCTFontStyleNameAttribute);
styleName = (CFStringRef) CTFontDescriptorCopyAttribute(desc, kCTFontStyleNameAttribute);
// TODO is styleName guaranteed?
if (styleName != NULL) {
CFRange range;

View File

@ -13,7 +13,7 @@ struct graphemes *graphemes(void *s, size_t len)
{
struct graphemes *g;
UniChar *str = (UniChar *) s;
CFString cfstr;
CFStringRef cfstr;
size_t ppos, gpos;
CFRange range;
size_t i;

View File

@ -109,9 +109,15 @@ extern uiDrawContext *newContext(CGContextRef, CGFloat);
extern void freeContext(uiDrawContext *);
// fontbutton.m
#if 0 /* TODO */
extern BOOL fontButtonInhibitSendAction(SEL sel, id from, id to);
extern BOOL fontButtonOverrideTargetForAction(SEL sel, id from, id to, id *override);
extern void setupFontPanel(void);
#else
static inline BOOL fontButtonInhibitSendAction(SEL sel, id from, id to) { return NO; }
static inline BOOL fontButtonOverrideTargetForAction(SEL sel, id from, id to, id *override) { return NO; }
static inline void setupFontPanel(void) {}
#endif
// colorbutton.m
extern BOOL colorButtonInhibitSendAction(SEL sel, id from, id to);

2
ui.h
View File

@ -577,6 +577,7 @@ struct uiAreaKeyEvent {
int Up;
};
#if 0 /* TODO */
typedef struct uiFontButton uiFontButton;
#define uiFontButton(this) ((uiFontButton *) (this))
// TODO document this returns a new font
@ -584,6 +585,7 @@ _UI_EXTERN uiDrawTextFont *uiFontButtonFont(uiFontButton *b);
// TOOD SetFont, mechanics
_UI_EXTERN void uiFontButtonOnChanged(uiFontButton *b, void (*f)(uiFontButton *, void *), void *data);
_UI_EXTERN uiFontButton *uiNewFontButton(void);
#endif
typedef struct uiColorButton uiColorButton;
#define uiColorButton(this) ((uiColorButton *) (this))