Skip to content

Commit 5576af5

Browse files
committed
Fix ttconv so it can handle fontmeta with newlines in it
svn path=/trunk/matplotlib/; revision=3538
1 parent 3aa4c87 commit 5576af5

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

ttconv/pprdrv.h

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class TTDictionaryCallback {
5858
virtual void add_pair(const char* key, const char* value) = 0;
5959
};
6060

61+
void replace_newlines_with_spaces(char* a);
62+
6163
/*
6264
* A simple class for all ttconv exceptions.
6365
*/

ttconv/pprdrv_tt.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ void Read_name(struct TTFONT *font)
210210
font->Copyright = (char*)calloc(sizeof(char),length+1);
211211
strncpy(font->Copyright,(const char*)strings+offset,length);
212212
font->Copyright[length]=(char)NULL;
213+
replace_newlines_with_spaces(font->Copyright);
213214

214215
#ifdef DEBUG_TRUETYPE
215216
debug("font->Copyright=\"%s\"",font->Copyright);
@@ -224,6 +225,7 @@ void Read_name(struct TTFONT *font)
224225
font->FamilyName = (char*)calloc(sizeof(char),length+1);
225226
strncpy(font->FamilyName,(const char*)strings+offset,length);
226227
font->FamilyName[length]=(char)NULL;
228+
replace_newlines_with_spaces(font->FamilyName);
227229

228230
#ifdef DEBUG_TRUETYPE
229231
debug("font->FamilyName=\"%s\"",font->FamilyName);
@@ -238,6 +240,7 @@ void Read_name(struct TTFONT *font)
238240
font->Style = (char*)calloc(sizeof(char),length+1);
239241
strncpy(font->Style,(const char*)strings+offset,length);
240242
font->Style[length]=(char)NULL;
243+
replace_newlines_with_spaces(font->Style);
241244

242245
#ifdef DEBUG_TRUETYPE
243246
debug("font->Style=\"%s\"",font->Style);
@@ -252,6 +255,7 @@ void Read_name(struct TTFONT *font)
252255
font->FullName = (char*)calloc(sizeof(char),length+1);
253256
strncpy(font->FullName,(const char*)strings+offset,length);
254257
font->FullName[length]=(char)NULL;
258+
replace_newlines_with_spaces(font->FullName);
255259

256260
#ifdef DEBUG_TRUETYPE
257261
debug("font->FullName=\"%s\"",font->FullName);
@@ -266,7 +270,8 @@ void Read_name(struct TTFONT *font)
266270
font->Version = (char*)calloc(sizeof(char),length+1);
267271
strncpy(font->Version,(const char*)strings+offset,length);
268272
font->Version[length]=(char)NULL;
269-
273+
replace_newlines_with_spaces(font->Version);
274+
270275
#ifdef DEBUG_TRUETYPE
271276
debug("font->Version=\"%s\"",font->Version);
272277
#endif
@@ -280,7 +285,8 @@ void Read_name(struct TTFONT *font)
280285
font->PostName = (char*)calloc(sizeof(char),length+1);
281286
strncpy(font->PostName,(const char*)strings+offset,length);
282287
font->PostName[length]=(char)NULL;
283-
288+
replace_newlines_with_spaces(font->PostName);
289+
284290
#ifdef DEBUG_TRUETYPE
285291
debug("font->PostName=\"%s\"",font->PostName);
286292
#endif
@@ -294,6 +300,7 @@ void Read_name(struct TTFONT *font)
294300
font->Trademark = (char*)calloc(sizeof(char),length+1);
295301
strncpy(font->Trademark,(const char*)strings+offset,length);
296302
font->Trademark[length]=(char)NULL;
303+
replace_newlines_with_spaces(font->Trademark);
297304

298305
#ifdef DEBUG_TRUETYPE
299306
debug("font->Trademark=\"%s\"",font->Trademark);
@@ -343,7 +350,7 @@ void ttfont_header(TTStreamWriter& stream, struct TTFONT *font)
343350

344351
/* If there is a Copyright notice, put it here too. */
345352
if( font->Copyright != (char*)NULL )
346-
stream.printf("%%%%Copyright: %s\n",font->Copyright);
353+
stream.printf("%%%%Copyright: %s\n",font->Copyright);
347354

348355
/* We created this file. */
349356
if( font->target_type == PS_TYPE_42 )

ttconv/ttutil.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,12 @@ void TTStreamWriter::putline(const char *a)
6262
this->write(a);
6363
this->write("\n");
6464
}
65+
66+
void replace_newlines_with_spaces(char *a) {
67+
char* i = a;
68+
while (*i != 0) {
69+
if (*i == '\n')
70+
*i = ' ';
71+
i++;
72+
}
73+
}

0 commit comments

Comments
 (0)