Very early TrueType support.

This commit is contained in:
Michael R Sweet 2021-06-11 11:22:08 -04:00
parent 42e7183eb0
commit bca0add5d8
No known key found for this signature in database
GPG Key ID: BE67C75EC81F3244
2 changed files with 278 additions and 9 deletions

View File

@ -1159,20 +1159,77 @@ pdfioFileCreateFontObjFromFile(
const char *filename, // I - Filename
bool unicode) // I - Unicode font?
{
#if 0
pdfio_dict_t *dict; // Font dictionary
pdfio_obj_t *obj; // Font object
pdfio_st_t *st; // Content stream
pdfio_dict_t *dict; // ICC profile dictionary
pdfio_obj_t *obj; // ICC profile object
pdfio_stream_t *st; // ICC profile stream
int fd; // File
char buffer[16384]; // Copy buffer
unsigned char buffer[16384]; // Read buffer
ssize_t bytes; // Bytes read
// Range check input...
if (!pdf)
return (NULL);
if (!filename)
{
_pdfioFileError(pdf, "No TrueType/OpenType filename specified.");
return (NULL);
}
if ((fd = open(filename, O_RDONLY | O_BINARY)) < 0)
{
_pdfioFileError(pdf, "Unable to open font file '%s': %s", filename, strerror(errno));
return (NULL);
}
// Create the font object...
if ((dict = pdfioDictCreate(pdf)) == NULL)
{
close(fd);
return (NULL);
}
pdfioDictSetName(dict, "Type", "Font");
pdfioDictSetName(dict, "Subtype", "TrueType");
pdfioDictSetName(dict, "BaseFont", "Bogus"); // TODO: Fix BaseFont value
(void)unicode;
pdfioDictSetName(dict, "Encoding", "WinAnsiEncoding"); // TODO: Fix encoding
pdfioDictSetName(dict, "Filter", "FlateDecode");
#if 0
pdfioDictSetObject(dict, "FontDescriptor", descriptor);
pdfioDictSetNumber(dict, "FirstChar", firstchar);
pdfioDictSetNumber(dict, "LastChar", lastchar);
pdfioDictSetArray(dict, "Widths", widths);
#endif // 0
(void)pdf;
(void)filename;
(void)unicode;
if ((obj = pdfioFileCreateObj(pdf, dict)) == NULL)
{
close(fd);
return (NULL);
}
return (NULL);
if ((st = pdfioObjCreateStream(obj, PDFIO_FILTER_FLATE)) == NULL)
{
close(fd);
return (NULL);
}
while ((bytes = read(fd, buffer, sizeof(buffer))) > 0)
{
if (!pdfioStreamWrite(st, buffer, (size_t)bytes))
{
close(fd);
pdfioStreamClose(st);
return (NULL);
}
}
close(fd);
pdfioStreamClose(st);
return (obj);
}

View File

@ -1043,7 +1043,165 @@ write_font_test(pdfio_file_t *pdf, // I - PDF file
{
pdfio_dict_t *dict; // Page dictionary
pdfio_stream_t *st; // Page contents stream
pdfio_obj_t *opensans; // OpenSans-Regular font
int i; // Looping var
static const char * const welcomes[] =// "Welcome" in many languages
{
"Welcome\n",
"Welkom\n",
// "ḫaṣānu\n",
"Mayad-ayad nga pad-abot\n",
"Mir se vjên\n",
"Mirë se vjen\n",
"Wellkumma\n",
"Bienveniu\n",
"Ghini vinit!\n",
"Bienveníu\n",
"Miro peicak\n",
// "Xoş gəlmişsiniz!\n",
"Salamat datang\n",
// "Сәләм бирем!\n",
"Menjuah-juah!\n",
// "Še das d' kemma bisd\n",
"Mwaiseni\n",
"Maogmáng Pag-abót\n",
"Welkam\n",
// "Dobrodošli\n",
"Degemer mat\n",
"Benvingut\n",
"Maayong pag-abot\n",
"Kopisanangan do kinorikatan\n",
"Bienvenida\n",
"Bien binidu\n",
"Bienbenidu\n",
// "Hóʔą\n",
"Boolkhent!\n",
"Kopivosian do kinoikatan\n",
"Malipayeng Pag-abot!\n",
"Vítej\n",
"Velkommen\n",
"Salâm\n",
"Welkom\n",
"Emedi\n",
"Welkumin\n",
"Tere tulemast\n",
// "Woé zɔ\n",
"Bienveníu\n",
"Vælkomin\n",
"Bula\n",
"Tervetuloa\n",
"Bienvenue\n",
"Wäljkiimen\n",
"Wäilkuumen\n",
"Wäilkuumen\n",
"Wolkom\n",
"Benvignût\n",
"Benvido\n",
"Willkommen\n",
// "Ἀσπάζομαι!\n",
// "Καλώς Ήρθες\n",
"Tikilluarit\n",
"Byen venu\n",
"Sannu da zuwa\n",
"Aloha\n",
"Wayakurua\n",
"Dayón\n",
"Zoo siab txais tos!\n",
"Üdvözlet\n",
"Selamat datai\n",
"Velkomin\n",
// "Nnọọ\n",
"Selamat datang\n",
"Qaimarutin\n",
"Fáilte\n",
"Benvenuto\n",
"Voschata\n",
"Murakaza neza\n",
"Mauri\n",
"Tu be xér hatî ye!\n",
// "Taŋyáŋ yahí\n",
"Salve\n",
// "Laipni lūdzam\n",
"Wilkóm\n",
// "Sveiki atvykę\n",
"Willkamen\n",
"Mu amuhezwi\n",
"Tukusanyukidde\n",
"Wëllkomm\n",
"Swagatam\n",
"Tonga soa\n",
"Selamat datang\n",
// "Merħba\n",
// "Bantulena\n",
"Failt ort\n",
"Haere mai\n",
"mai\n",
// "Pjilasi\n",
"Benvegnüu\n",
"Ne y kena\n",
// "Ximopanōltih\n",
"Yá'át'ééh\n",
"Siyalemukela\n",
"Siyalemukela\n",
"Bures boahtin\n",
"Re a go amogela\n",
"Velkommen\n",
"Benvengut!\n",
"Bon bini\n",
// "Witam Cię\n",
"Bem-vindo\n",
"Haykuykuy!\n",
"T'aves baxtalo\n",
"Bainvegni\n",
"Afio mai\n",
"Ennidos\n",
"Walcome\n",
"Fàilte\n",
"Mauya\n",
"Bon vinutu\n",
"Vitaj\n",
// "Dobrodošli\n",
"Soo dhowow\n",
"Witaj\n",
"Bienvenido\n",
"Wilujeng sumping\n",
"Karibu\n",
"Wamukelekile\n",
"Välkommen\n",
"Wilkomme\n",
"Maligayang pagdating\n",
"Maeva\n",
"Räxim itegez\n",
"Ksolok Bodik Mai\n",
"Ulu tons mai\n",
"Welkam\n",
"Talitali fiefia\n",
"Lek oy li la tale\n",
"amogetswe\n",
"Tempokani\n",
// "Hoş geldin\n",
// "Koş geldiniz\n",
"Ulufale mai!\n",
"Xush kelibsiz\n",
"Benvignùo\n",
"Tervhen tuldes\n",
"Hoan nghênh\n",
"Tere tulõmast\n",
"Benvnuwe\n",
"Croeso\n",
"Merhbe\n",
"Wamkelekile\n",
// "Märr-ŋamathirri\n",
// "Ẹ ku abọ\n",
"Kíimak 'oolal\n",
"Ngiyakwemukela\n"
};
fputs("pdfioFileCreateFontObjFromFile(OpenSans-Regular.ttf): ", stdout);
if ((opensans = pdfioFileCreateFontObjFromFile(pdf, "testfiles/OpenSans-Regular.ttf", false)) != NULL)
puts("PASS");
else
return (1);
fputs("pdfioDictCreate: ", stdout);
if ((dict = pdfioDictCreate(pdf)) != NULL)
@ -1057,6 +1215,12 @@ write_font_test(pdfio_file_t *pdf, // I - PDF file
else
return (1);
fputs("pdfioPageDictAddFont(F2): ", stdout);
if (pdfioPageDictAddFont(dict, "F2", opensans))
puts("PASS");
else
return (1);
printf("pdfioFileCreatePage(%d): ", number);
if ((st = pdfioFileCreatePage(pdf, dict)) != NULL)
@ -1067,6 +1231,54 @@ write_font_test(pdfio_file_t *pdf, // I - PDF file
if (write_header_footer(st, "TrueType Font Test", number))
goto error;
fputs("pdfioContentTextBegin(): ", stdout);
if (pdfioContentTextBegin(st))
puts("PASS");
else
return (1);
fputs("pdfioContentSetTextFont(\"F2\", 10.0): ", stdout);
if (pdfioContentSetTextFont(st, "F2", 10.0))
puts("PASS");
else
return (1);
fputs("pdfioContentSetTextLeading(12.0): ", stdout);
if (pdfioContentSetTextLeading(st, 12.0))
puts("PASS");
else
goto error;
fputs("pdfioContentTextMoveTo(36.0, 702.0): ", stdout);
if (pdfioContentTextMoveTo(st, 36.0, 702.0))
puts("PASS");
else
return (1);
for (i = 0; i < (int)(sizeof(welcomes) / sizeof(welcomes[0])); i ++)
{
if (i > 0 && (i % 50) == 0)
{
fputs("pdfioContentTextMoveTo(200.0, 600.0): ", stdout);
if (pdfioContentTextMoveTo(st, 200.0, 600.0))
puts("PASS");
else
return (1);
}
printf("pdfioContentTextShow(\"%s\"): ", welcomes[i]);
if (pdfioContentTextShow(st, welcomes[i]))
puts("PASS");
else
return (1);
}
fputs("pdfioContentTextEnd(): ", stdout);
if (pdfioContentTextEnd(st))
puts("PASS");
else
return (1);
fputs("pdfioStreamClose: ", stdout);
if (pdfioStreamClose(st))
puts("PASS");