And fixed other compile errors. Of course I forgot to add uiFontButton back in (I wanted to properly comment that first :/ ). Now for linker errors, which may result in some warning fixes along the way.
This commit is contained in:
parent
82d3de7c31
commit
c82197f408
|
@ -6,7 +6,7 @@
|
|||
// problem: for a CTFrame made from an empty string, the CTLine array will be empty, and we will crash when doing anything requiring a CTLine
|
||||
// solution: for those cases, maintain a separate framesetter just for computing those things
|
||||
// in the usual case, the separate copy will just be identical to the regular one, with extra references to everything within
|
||||
@interface uiprivTextFrame {
|
||||
@interface uiprivTextFrame : NSObject {
|
||||
CFAttributedStringRef attrstr;
|
||||
NSArray *backgroundBlocks;
|
||||
CTFramesetterRef framesetter;
|
||||
|
@ -25,7 +25,7 @@
|
|||
- (id)initWithLayoutParams:(uiDrawTextLayoutParams *)p
|
||||
{
|
||||
CFRange range;
|
||||
CGFloat width;
|
||||
CGFloat cgwidth;
|
||||
CFRange unused;
|
||||
CGRect rect;
|
||||
|
||||
|
@ -54,7 +54,7 @@
|
|||
rect.origin = CGPointZero;
|
||||
rect.size = self->size;
|
||||
self->path = CGPathCreateWithRect(rect, NULL);
|
||||
self->frame = CTFramesetterCreateFrame(tl->framesetter,
|
||||
self->frame = CTFramesetterCreateFrame(self->framesetter,
|
||||
range,
|
||||
self->path,
|
||||
// TODO kCTFramePathWidthAttributeName?
|
||||
|
@ -144,7 +144,7 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p)
|
|||
|
||||
tl = uiprivNew(uiDrawTextLayout);
|
||||
tl->frame = [[uiprivTextFrame alloc] initWithLayoutParams:p];
|
||||
if (uiAttributedStringLength(p->String) != 0)
|
||||
if (uiAttributedStringLen(p->String) != 0)
|
||||
tl->forLines = [tl->frame retain];
|
||||
else {
|
||||
uiAttributedString *space;
|
||||
|
|
|
@ -275,9 +275,9 @@ FONTNAME(familyName,
|
|||
|
||||
struct closeness {
|
||||
CFIndex index;
|
||||
uiDrawTextWeight weight;
|
||||
uiTextWeight weight;
|
||||
double italic;
|
||||
uiDrawTextStretch stretch;
|
||||
uiTextStretch stretch;
|
||||
double distance;
|
||||
};
|
||||
|
||||
|
@ -287,14 +287,14 @@ static const double italicClosenessNormal[] = { 0, 1, 1 };
|
|||
static const double italicClosenessOblique[] = { 1, 0, 0.5 };
|
||||
static const double italicClosenessItalic[] = { 1, 0.5, 0 };
|
||||
static const double *italicClosenesses[] = {
|
||||
[uiDrawTextItalicNormal] = italicClosenessNormal,
|
||||
[uiDrawTextItalicOblique] = italicClosenessOblique,
|
||||
[uiDrawTextItalicItalic] = italicClosenessItalic,
|
||||
[uiTextItalicNormal] = italicClosenessNormal,
|
||||
[uiTextItalicOblique] = italicClosenessOblique,
|
||||
[uiTextItalicItalic] = italicClosenessItalic,
|
||||
};
|
||||
|
||||
// Core Text doesn't seem to differentiate between Italic and 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
|
||||
static uiDrawTextItalic guessItalicOblique(uiprivFontStyleData *d)
|
||||
static uiTextItalic guessItalicOblique(uiprivFontStyleData *d)
|
||||
{
|
||||
CFStringRef styleName;
|
||||
BOOL isOblique;
|
||||
|
@ -309,8 +309,8 @@ static uiDrawTextItalic guessItalicOblique(uiprivFontStyleData *d)
|
|||
isOblique = YES;
|
||||
}
|
||||
if (isOblique)
|
||||
return uiDrawTextItalicOblique;
|
||||
return uiDrawTextItalicItalic;
|
||||
return uiTextItalicOblique;
|
||||
return uiTextItalicItalic;
|
||||
}
|
||||
|
||||
// Italics are hard because Core Text does NOT distinguish between italic and oblique.
|
||||
|
@ -320,7 +320,7 @@ static uiDrawTextItalic guessItalicOblique(uiprivFontStyleData *d)
|
|||
// 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 void setItalic(uiprivFontStyleData *d, uiFontDescriptor *out)
|
||||
{
|
||||
out->Italic = uiDrawTextItalicNormal;
|
||||
out->Italic = uiTextItalicNormal;
|
||||
if (([d symbolicTraits] & kCTFontItalicTrait) != 0)
|
||||
out->Italic = guessItalicOblique(d);
|
||||
}
|
||||
|
|
|
@ -31,18 +31,18 @@ static BOOL fontRegistered(uiprivFontStyleData *d)
|
|||
// Core Text does (usWidthClass / 10) - 0.5 here.
|
||||
// This roughly maps to our values with increments of 0.1, except for the fact 0 and 10 are allowed by Core Text, despite being banned by TrueType and OpenType themselves.
|
||||
// We'll just treat them as identical to 1 and 9, respectively.
|
||||
static const uiDrawTextStretch os2WidthsToStretches[] = {
|
||||
uiDrawTextStretchUltraCondensed,
|
||||
uiDrawTextStretchUltraCondensed,
|
||||
uiDrawTextStretchExtraCondensed,
|
||||
uiDrawTextStretchCondensed,
|
||||
uiDrawTextStretchSemiCondensed,
|
||||
uiDrawTextStretchNormal,
|
||||
uiDrawTextStretchSemiExpanded,
|
||||
uiDrawTextStretchExpanded,
|
||||
uiDrawTextStretchExtraExpanded,
|
||||
uiDrawTextStretchUltraExpanded,
|
||||
uiDrawTextStretchUltraExpanded,
|
||||
static const uiTextStretch os2WidthsToStretches[] = {
|
||||
uiTextStretchUltraCondensed,
|
||||
uiTextStretchUltraCondensed,
|
||||
uiTextStretchExtraCondensed,
|
||||
uiTextStretchCondensed,
|
||||
uiTextStretchSemiCondensed,
|
||||
uiTextStretchNormal,
|
||||
uiTextStretchSemiExpanded,
|
||||
uiTextStretchExpanded,
|
||||
uiTextStretchExtraExpanded,
|
||||
uiTextStretchUltraExpanded,
|
||||
uiTextStretchUltraExpanded,
|
||||
};
|
||||
|
||||
static const CFStringRef exceptions[] = {
|
||||
|
@ -174,50 +174,50 @@ void uiprivProcessFontTraits(uiprivFontStyleData *d, uiFontDescriptor *out)
|
|||
if (!hasWeight)
|
||||
// TODO this scale is a bit lopsided
|
||||
if (weight <= -0.7)
|
||||
out->Weight = uiDrawTextWeightThin;
|
||||
out->Weight = uiTextWeightThin;
|
||||
else if (weight <= -0.5)
|
||||
out->Weight = uiDrawTextWeightUltraLight;
|
||||
out->Weight = uiTextWeightUltraLight;
|
||||
else if (weight <= -0.3)
|
||||
out->Weight = uiDrawTextWeightLight;
|
||||
out->Weight = uiTextWeightLight;
|
||||
else if (weight <= -0.23) {
|
||||
out->Weight = uiDrawTextWeightBook;
|
||||
out->Weight = uiTextWeightBook;
|
||||
if (shouldReallyBeThin(d))
|
||||
out->Weight = uiDrawTextWeightThin;
|
||||
out->Weight = uiTextWeightThin;
|
||||
} else if (weight <= 0.0)
|
||||
out->Weight = uiDrawTextWeightNormal;
|
||||
out->Weight = uiTextWeightNormal;
|
||||
else if (weight <= 0.23)
|
||||
out->Weight = uiDrawTextWeightMedium;
|
||||
out->Weight = uiTextWeightMedium;
|
||||
else if (weight <= 0.3)
|
||||
out->Weight = uiDrawTextWeightSemiBold;
|
||||
out->Weight = uiTextWeightSemiBold;
|
||||
else if (weight <= 0.4)
|
||||
out->Weight = uiDrawTextWeightBold;
|
||||
out->Weight = uiTextWeightBold;
|
||||
else if (weight <= 0.5)
|
||||
out->Weight = uiDrawTextWeightUltraBold;
|
||||
out->Weight = uiTextWeightUltraBold;
|
||||
else if (weight <= 0.7)
|
||||
out->Weight = uiDrawTextWeightHeavy;
|
||||
out->Weight = uiTextWeightHeavy;
|
||||
else
|
||||
out->Weight = uiDrawTextWeightUltraHeavy;
|
||||
out->Weight = uiTextWeightUltraHeavy;
|
||||
|
||||
if (!hasWidth)
|
||||
// TODO this scale is a bit lopsided
|
||||
if (width <= -0.7) {
|
||||
out->Stretch = uiDrawTextStretchUltraCondensed;
|
||||
out->Stretch = uiTextStretchUltraCondensed;
|
||||
if (shouldReallyBeSemiCondensed(d))
|
||||
out->Stretch = uiDrawTextStretchSemiCondensed;
|
||||
out->Stretch = uiTextStretchSemiCondensed;
|
||||
} else if (width <= -0.5)
|
||||
out->Stretch = uiDrawTextStretchExtraCondensed;
|
||||
out->Stretch = uiTextStretchExtraCondensed;
|
||||
else if (width <= -0.2)
|
||||
out->Stretch = uiDrawTextStretchCondensed;
|
||||
out->Stretch = uiTextStretchCondensed;
|
||||
else if (width <= -0.1)
|
||||
out->Stretch = uiDrawTextStretchSemiCondensed;
|
||||
out->Stretch = uiTextStretchSemiCondensed;
|
||||
else if (width <= 0.0)
|
||||
out->Stretch = uiDrawTextStretchNormal;
|
||||
out->Stretch = uiTextStretchNormal;
|
||||
else if (width <= 0.1)
|
||||
out->Stretch = uiDrawTextStretchSemiExpanded;
|
||||
out->Stretch = uiTextStretchSemiExpanded;
|
||||
else if (width <= 0.2)
|
||||
out->Stretch = uiDrawTextStretchExpanded;
|
||||
out->Stretch = uiTextStretchExpanded;
|
||||
else if (width <= 0.6)
|
||||
out->Stretch = uiDrawTextStretchExtraExpanded;
|
||||
out->Stretch = uiTextStretchExtraExpanded;
|
||||
else
|
||||
out->Stretch = uiDrawTextStretchUltraExpanded;
|
||||
out->Stretch = uiTextStretchUltraExpanded;
|
||||
}
|
||||
|
|
|
@ -310,8 +310,8 @@ void uiprivProcessFontVariation(uiprivFontStyleData *d, NSDictionary *axisDict,
|
|||
CFDictionaryRef var;
|
||||
double v;
|
||||
|
||||
out->Weight = uiDrawTextWeightNormal;
|
||||
out->Stretch = uiDrawTextStretchNormal;
|
||||
out->Weight = uiTextWeightNormal;
|
||||
out->Stretch = uiTextStretchNormal;
|
||||
|
||||
var = [d variation];
|
||||
|
||||
|
@ -320,14 +320,14 @@ void uiprivProcessFontVariation(uiprivFontStyleData *d, NSDictionary *axisDict,
|
|||
// we want a linear value between 0 and 1000 with 400 being normal
|
||||
if (v < 0) {
|
||||
v += 1;
|
||||
out->Weight = (uiDrawTextWeight) (v * 400);
|
||||
out->Weight = (uiTextWeight) (v * 400);
|
||||
} else if (v > 0)
|
||||
out->Weight += (uiDrawTextWeight) (v * 600);
|
||||
out->Weight += (uiTextWeight) (v * 600);
|
||||
}
|
||||
|
||||
if (tryAxis(axisDict, var, fvarAxisKey(fvarWidth), &v)) {
|
||||
// likewise, but with stretches, we go from 0 to 8 with 4 being directly between the two, so this is sufficient
|
||||
v += 1;
|
||||
out->Stretch = (uiDrawTextStretch) (v * 4);
|
||||
out->Stretch = (uiTextStretch) (v * 4);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ static uiForEach otfArrayForEachOT(const uiOpenTypeFeatures *otf, char a, char b
|
|||
p.valueValue = (const SInt32 *) (&value);
|
||||
addCTFeatureEntry(&p);
|
||||
|
||||
CFRelease(strTag);
|
||||
CFRelease(tagstr);
|
||||
return uiForEachContinue;
|
||||
}
|
||||
|
||||
|
|
|
@ -61,11 +61,3 @@ _UI_EXTERN double uiDrawTextLayoutByteLocationInLine(uiDrawTextLayout *tl, size_
|
|||
_UI_EXTERN void uiDrawCaret(uiDrawContext *c, double x, double y, uiDrawTextLayout *layout, size_t pos, int *line);
|
||||
// TODO allow blinking
|
||||
// TODO allow secondary carets
|
||||
|
||||
typedef struct uiFontButton uiFontButton;
|
||||
#define uiFontButton(this) ((uiFontButton *) (this))
|
||||
// TODO have a function that sets an entire font descriptor to a range in a uiAttributedString at once, for SetFont?
|
||||
_UI_EXTERN void uiFontButtonFont(uiFontButton *b, uiDrawFontDescriptor *desc);
|
||||
// TOOD SetFont, mechanics
|
||||
_UI_EXTERN void uiFontButtonOnChanged(uiFontButton *b, void (*f)(uiFontButton *, void *), void *data);
|
||||
_UI_EXTERN uiFontButton *uiNewFontButton(void);
|
||||
|
|
|
@ -495,3 +495,11 @@ _UI_EXTERN void uiDrawTextLayoutLineByteRange(uiDrawTextLayout *tl, int line, si
|
|||
// TODO metrics functions
|
||||
|
||||
// TODO number of lines visible for clipping rect, range visible for clipping rect?
|
||||
|
||||
typedef struct uiFontButton uiFontButton;
|
||||
#define uiFontButton(this) ((uiFontButton *) (this))
|
||||
// TODO have a function that sets an entire font descriptor to a range in a uiAttributedString at once, for SetFont?
|
||||
_UI_EXTERN void uiFontButtonFont(uiFontButton *b, uiFontDescriptor *desc);
|
||||
// TOOD SetFont, mechanics
|
||||
_UI_EXTERN void uiFontButtonOnChanged(uiFontButton *b, void (*f)(uiFontButton *, void *), void *data);
|
||||
_UI_EXTERN uiFontButton *uiNewFontButton(void);
|
||||
|
|
Loading…
Reference in New Issue