I found a nasty little problem that happens when you
have HTML inside of a PDF, and the HTML is not closed
in the same order it was opened. I dug around in
HtmlOutputDev.cc and wrote a very quick fix for this. I'm
not a C++ programmer, so if there's a better way let me
know and i'll patch mine as well.
-- Begin Diff --
22a23
> #include <string.h>
325a327
>
488,489c490,498
< GString *str, *str1;
< for(HtmlString *tmp=yxStrings;tmp;tmp=tmp-
>yxNext){
---
> GString *str;
> GString *str1;
>
> // Needed for character compare
> char strBuff[10000];
> int i = 0;
>
> for(HtmlString *tmp=yxStrings; tmp; tmp=tmp-
>yxNext)
> {
494a504
>
498c508,523
< fputs(str1->getCString(),f);
---
>
> // Copy the string into a temp buffer
> strcpy(strBuff, str1->getCString());
>
> // Look through the string for '<' or '>' and replace
them with &..;
> for (i = 0; i < strlen(strBuff); i++)
> {
> if (strBuff[i] == '<')
> fprintf(f, "&lt;");
> else if (strBuff[i] == '>')
> fprintf(f, "&gt;");
> else
> fprintf(f, "%c", strBuff[i]);
>
> }
>
502a528
>
-- End Diff --
If anyone has any questions please feel free to drop me
a line at tim at thelogichouse.com
Logged In: YES
user_id=173287
I can't reproduce the problem w/o patch and as far as I know
the code that's in there already handles this, see
HtmlFont:HtmlFilter
Logged In: YES
user_id=828625
This is no good solution to fix this problem. Your fix
converts also XML-Tags in str1. E.g. the bold tag.
The problem is the method HtmlFilter in HtmlFonts.cc. It
replaces special characters before doing the mapping from
Unicode:
--
switch (u[i])
{
case '"': tmp->append("&quot;"); break;
case '&': tmp->append("&amp;"); break;
case '<': tmp->append("&lt;"); break;
case '>': tmp->append("&gt;"); break;
default:
{
// convert unicode to string
if ((n = uMap->mapUnicode(u[i], buf, sizeof(buf))) > 0) {
tmp->append(buf, n);
}
}
}
--
The solution is to made the mapping first:
--
// convert unicode to string
if ((n = uMap->mapUnicode(u[i], buf, sizeof(buf))) > 0) {
if (n == 1){
switch (buf[0])
{
case '"': tmp->append("&quot;"); break;
case '&': tmp->append("&amp;"); break;
case '<': tmp->append("&lt;"); break;
case '>': tmp->append("&gt;"); break;
default: tmp->append(buf, n);
}
} else {
tmp->append(buf, n);
}
}