More examples and crash fixes.

This commit is contained in:
Pietro Gagliardi 2017-02-16 15:02:19 -05:00
parent e27e51c4b8
commit 025dd16d76
2 changed files with 102 additions and 47 deletions
darwin
examples/drawtext

View File

@ -298,56 +298,57 @@ CTFontDescriptorRef fontdescAppendFeatures(CTFontDescriptorRef desc, const uint1
} }
// now we have to take care of the language // now we have to take care of the language
// TODO can we assume this is present?
if (language != NULL) { if (language != NULL) {
languages = CTFontDescriptorCopyAttribute(desc, kCTFontLanguagesAttribute); languages = CTFontDescriptorCopyAttribute(desc, kCTFontLanguagesAttribute);
nl = CFArrayGetCount(languages); if (languages != NULL) {
d[0] = language[0]; nl = CFArrayGetCount(languages);
if (d[0] >= 'A' && d[0] <= 'Z') d[0] = language[0];
d[0] += 'a' - 'A'; if (d[0] >= 'A' && d[0] <= 'Z')
d[1] = language[1]; d[0] += 'a' - 'A';
if (d[1] >= 'A' && d[1] <= 'Z') d[1] = language[1];
d[1] += 'a' - 'A'; if (d[1] >= 'A' && d[1] <= 'Z')
for (il = 0; il < nl; il++) { d[1] += 'a' - 'A';
char c[2]; for (il = 0; il < nl; il++) {
char c[2];
curlang = (CFStringRef) CFArrayGetValueAtIndex(languages, il); curlang = (CFStringRef) CFArrayGetValueAtIndex(languages, il);
// TODO check for failure // TODO check for failure
CFStringGetBytes(curlang, CFRangeMake(0, 2), CFStringGetBytes(curlang, CFRangeMake(0, 2),
kCFStringEncodingUTF8, 0, false, kCFStringEncodingUTF8, 0, false,
(UInt8 *) c, 2, NULL); (UInt8 *) c, 2, NULL);
if (c[0] >= 'A' && c[0] <= 'Z') if (c[0] >= 'A' && c[0] <= 'Z')
c[0] += 'a' - 'A'; c[0] += 'a' - 'A';
if (c[1] >= 'A' && c[1] <= 'Z') if (c[1] >= 'A' && c[1] <= 'Z')
c[1] += 'a' - 'A'; c[1] += 'a' - 'A';
if (c[0] == d[0] && c[1] == d[1]) if (c[0] == d[0] && c[1] == d[1])
break; break;
}
if (il != nl) {
uint16_t typ;
typ = kLanguageTagType;
il++;
numType = CFNumberCreate(NULL, kCFNumberSInt16Type,
(const SInt16 *) (&typ));
numSelector = CFNumberCreate(NULL, kCFNumberCFIndexType,
&il);
values[0] = numType;
values[1] = numSelector;
innerDict = CFDictionaryCreate(NULL,
keys, values, 2,
// TODO are these correct?
&kCFCopyStringDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
if (innerDict == NULL) {
// TODO
} }
CFArrayAppendValue(outerArray, innerDict); if (il != nl) {
CFRelease(innerDict); uint16_t typ;
CFRelease(numSelector);
CFRelease(numType); typ = kLanguageTagType;
il++;
numType = CFNumberCreate(NULL, kCFNumberSInt16Type,
(const SInt16 *) (&typ));
numSelector = CFNumberCreate(NULL, kCFNumberCFIndexType,
&il);
values[0] = numType;
values[1] = numSelector;
innerDict = CFDictionaryCreate(NULL,
keys, values, 2,
// TODO are these correct?
&kCFCopyStringDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
if (innerDict == NULL) {
// TODO
}
CFArrayAppendValue(outerArray, innerDict);
CFRelease(innerDict);
CFRelease(numSelector);
CFRelease(numType);
}
CFRelease(languages);
} }
CFRelease(languages);
} }
keys[0] = kCTFontFeatureSettingsAttribute; keys[0] = kCTFontFeatureSettingsAttribute;

View File

@ -8,6 +8,7 @@ static void setupAttributedString(void)
uiAttributeSpec spec; uiAttributeSpec spec;
size_t start, end; size_t start, end;
const char *next; const char *next;
int i;
attrstr = uiNewAttributedString("uiAttributedString isn't just for plain text! It supports "); attrstr = uiNewAttributedString("uiAttributedString isn't just for plain text! It supports ");
@ -355,7 +356,60 @@ static void setupAttributedString(void)
uiAttributedStringAppendUnattributed(attrstr, ", "); uiAttributedStringAppendUnattributed(attrstr, ", ");
next = "TODO mathematical greek"; next = "\xCE\xA0\xCE\xA3";
uiAttributedStringAppendUnattributed(attrstr, "mathematical greek (");
start = uiAttributedStringLen(attrstr);
end = start + strlen(next);
uiAttributedStringAppendUnattributed(attrstr, next);
spec.Type = uiAttributeMathematicalGreek;
spec.Value = 0;
uiAttributedStringSetAttribute(attrstr, &spec, start, end);
uiAttributedStringAppendUnattributed(attrstr, " vs. ");
start = uiAttributedStringLen(attrstr);
end = start + strlen(next);
uiAttributedStringAppendUnattributed(attrstr, next);
spec.Type = uiAttributeMathematicalGreek;
spec.Value = 1;
uiAttributedStringSetAttribute(attrstr, &spec, start, end);
uiAttributedStringAppendUnattributed(attrstr, ")");
uiAttributedStringAppendUnattributed(attrstr, ", ");
next = "qwertyuiop\xE2\x80\xA2";
uiAttributedStringAppendUnattributed(attrstr, "ornamental forms (");
for (i = 1; i < 11; i++) {
start = uiAttributedStringLen(attrstr);
end = start + strlen(next);
uiAttributedStringAppendUnattributed(attrstr, next);
spec.Type = uiAttributeOrnamentalForms;
spec.Value = (uintptr_t) i;
uiAttributedStringSetAttribute(attrstr, &spec, start, end);
next = "\xE2\x80\xA2";
}
uiAttributedStringAppendUnattributed(attrstr, ")");
uiAttributedStringAppendUnattributed(attrstr, ", ");
next = "g";
uiAttributedStringAppendUnattributed(attrstr, "specific forms/alternates (");
start = uiAttributedStringLen(attrstr);
end = start + strlen(next);
uiAttributedStringAppendUnattributed(attrstr, next);
spec.Type = uiAttributeSpecificCharacterForm;
spec.Value = 0;
uiAttributedStringSetAttribute(attrstr, &spec, start, end);
uiAttributedStringAppendUnattributed(attrstr, " vs. ");
start = uiAttributedStringLen(attrstr);
end = start + strlen(next);
uiAttributedStringAppendUnattributed(attrstr, next);
spec.Type = uiAttributeSpecificCharacterForm;
spec.Value = 1;
uiAttributedStringSetAttribute(attrstr, &spec, start, end);
uiAttributedStringAppendUnattributed(attrstr, ")");
uiAttributedStringAppendUnattributed(attrstr, ", ");
next = "TODO titling capitals";
} }
static char fontFamily[] = "Times New Roman"; static char fontFamily[] = "Times New Roman";