This patch fixes the embedding of the fonts in the Xft build.
It also fixes the printing bugs that Christian found. Basically before
we were printing one word at a time, and PS_Graphics::_drawCharsUTF8,
and due to the recent performance fixes, now this function has to handle
up to the whole line.
Cheers,
P.S.: Martin, now your problem about printing documents with fonts that
you don't have should be solved.
--
Joaqu�n Cuenca Abela
[EMAIL PROTECTED]
diff -ru abi/src/af/xap/unix/xap_UnixPSGraphics.cpp abi_profile/src/af/xap/unix/xap_UnixPSGraphics.cpp
--- abi/src/af/xap/unix/xap_UnixPSGraphics.cpp Sat Aug 3 15:31:47 2002
+++ abi_profile/src/af/xap/unix/xap_UnixPSGraphics.cpp Sat Aug 3 17:58:11 2002
@@ -421,9 +421,38 @@
// This piece of code scales the FONT chosen at low resolution to that at high
// resolution. This fixes bug 1632 and other non-WYSIWYG behaviour.
UT_uint32 iSize = getAppropriateFontSizeFromString(pszFontSize);
- XAP_UnixFontHandle* pFont = new XAP_UnixFontHandle(pUnixFont, iSize);
- UT_ASSERT(pFont);
+ PSFont* pFont = new PSFont(pUnixFont, iSize);
+
+ if (!pFont)
+ return NULL;
+
+ // Here we do something different from gr_UnixGraphics::setFont().
+ // The PostScript context keeps a simple vector of all its fonts,
+ // so that it can run through them and dump them into a document.
+ UT_uint32 k, count;
+ for (k = 0, count = m_vecFontList.getItemCount(); k < count; k++)
+ {
+ PSFont * psf = (PSFont *) m_vecFontList.getNthItem(k);
+ UT_ASSERT(psf);
+ // is this good enough for a match?
+ if (!strcmp(psf->getUnixFont()->getFontKey(),pFont->getUnixFont()->getFontKey()) &&
+ psf->getSize() == pFont->getSize())
+ {
+ // don't return the one in the vector, even though
+ // it matches, but return the copy, since they're
+ // disposable outside our realm.
+ pFont->setIndex(psf->getIndex());
+ return pFont;
+ }
+ }
+
+ // wasn't already there, add it
+ m_vecFontList.addItem((void *) pFont);
+ // it's always the last in the list
+ UT_uint32 n = m_vecFontList.getItemCount() - 1;
+ pFont->setIndex(n);
+
return pFont;
}
@@ -562,7 +591,7 @@
#else
for(pS=pE,xS=xoff; pE<pEnd && !XAP_EncodingManager::get_instance()->is_cjk_letter(*pE); ++pE)
#endif
- xoff += _scale(pEnglishFont->getCharWidth(remapGlyph(*pE,/**pS > 0xff*/0)));
+ xoff += _scale(pEnglishFont->getCharWidth(remapGlyph(*pE,/**pS > 0xff*/0)));
if(pE>pS)
{
_emit_SetFont(pEnglishFont);
@@ -924,8 +953,9 @@
char buf[LINE_BUFFER_SIZE];
char * pD = buf;
- const UT_UCSChar * pS = pChars+iCharOffset;
- const UT_UCSChar * pEnd = pS+iLength;
+ const UT_UCSChar* pS = pChars + iCharOffset;
+ const UT_UCSChar* pFirstChar = pS;
+ const UT_UCSChar* pEnd = pS+iLength;
UT_UCSChar currentChar;
//when printing 8-bit chars we enclose them in brackets, but 16-bit
@@ -933,6 +963,7 @@
bool open_bracket = false;
bool using_names = false;
+
while (pS<pEnd)
{
if (pD-buf > OUR_LINE_LIMIT)
@@ -951,15 +982,17 @@
{
// if currentChar is not an english character, we will have to write it
// using parentheses
- if(open_bracket)
+ if (open_bracket)
{
open_bracket = false;
sprintf((char *) pD,") %d %d MS\n",xoff,yoff);
m_ps->writeBytes(buf);
pD = buf;
}
- else if(!using_names)
+ else if (!using_names)
{
+ xoff += measureString(pFirstChar, 0, pS - pFirstChar, NULL);
+ pFirstChar = pS;
sprintf((char *) pD," %d %d MV ",xoff,yoff);
pD = buf + strlen(buf);
using_names = true;
@@ -970,7 +1003,7 @@
const char * glyph = ae->ucsToAdobe(currentChar);
// ' /glyph GS '
- if(pD - buf + strlen(glyph) + 6 > OUR_LINE_LIMIT)
+ if (pD - buf + strlen(glyph) + 6 > OUR_LINE_LIMIT)
{
//*pD++ = '\\';
*pD++ = '\n';
@@ -988,10 +1021,10 @@
}
else
{
- UT_DEBUGMSG(("char < 255\n"));
-
- if(!open_bracket)
+ if (!open_bracket)
{
+ xoff += measureString(pFirstChar, 0, pS - pFirstChar, NULL);
+ pFirstChar = pS;
*pD++ = '(';
open_bracket = true;
using_names = false;
@@ -1016,7 +1049,8 @@
}
pS++;
}
- if(open_bracket)
+
+ if (open_bracket)
{
*pD++ = ')';
sprintf((char *) pD," %d %d MS\n",xoff,yoff);
@@ -1028,7 +1062,7 @@
}
m_ps->writeBytes(buf);
- if(ae)
+ if (ae)
delete ae;
}
#endif // #ifndef WITH_PANGO
@@ -1921,12 +1955,12 @@
void PS_Graphics::_emit_SetFont(PSFont *pFont)
{
- if ( pFont )
- {
- char buf[1024];
- g_snprintf(buf, 1024, "F%d\n", pFont->getIndex());
- m_ps->writeBytes(buf);
- }
+ if (pFont)
+ {
+ char buf[1024];
+ g_snprintf(buf, 1024, "F%d\n", pFont->getIndex());
+ m_ps->writeBytes(buf);
+ }
};
@@ -1934,15 +1968,15 @@
void PS_Graphics::_explodePSFonts(PSFont *current, PSFont*& pEnglishFont,PSFont*& pChineseFont)
{
- if (current->getUnixFont()->is_CJK_font())
+ if (current->getUnixFont()->is_CJK_font())
{
- pChineseFont=current;
- pEnglishFont=_findMatchPSFontCJK(pChineseFont);
+ pChineseFont=current;
+ pEnglishFont=_findMatchPSFontCJK(pChineseFont);
}
- else
+ else
{
- pEnglishFont=current;
- pChineseFont=_findMatchPSFontCJK(pEnglishFont);
+ pEnglishFont=current;
+ pChineseFont=_findMatchPSFontCJK(pEnglishFont);
}
}