fix to bug #31351 (printing need support Unicode string) and bug #30176 (Fail to

print Chinese webpages). Design documentation is at http://linux.webchina.org/
printing/cprint.html. Tested existing ASCII pages and it remains working as before. For Chinese pages or other i18n pages, need Unicode encoded PostScript font support on the platform for rendering. Here we just output Unicode and user defined rendering
procedure 'unicodeshow'. For platforms without a Unicode encoded PostScript font, need a seperate post-processing utility to insert the font info at run time before the PostScript file is fed into a printer. I have such an utility documented in above web address and it depends on a TrueType font file which the user should buy by themselves. r=dcone.


git-svn-id: svn://10.0.0.236/trunk@65134 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
yueheng.xu%intel.com
2000-04-04 03:23:45 +00:00
parent 536db3ad95
commit 87ea73de0b
5 changed files with 143 additions and 38 deletions

View File

@@ -766,6 +766,12 @@ float totallen=0.0f;
asciichar = (*cptr)&0x00ff;
idx = asciichar-32;
fwidth = (PRInt32)(mPSFontInfo->mAFMCharMetrics[idx].mW0x);
// if ( (*cptr == 0x0020) || (*cptr == 0x002c) )
// printf("fwidth = %d\n", fwidth);
if (*cptr & 0xff00)
fwidth = 1056;
if ( (*cptr == 0x0020) || (*cptr == 0x002c) )
fwidth = 1056; // space and comma are half size of a CJK width
totallen += fwidth;
}

View File

@@ -453,6 +453,44 @@ char* charset_name = NULL;
XP_FilePrintf(f, " b4_Inc_state restore\n");
XP_FilePrintf(f, "} bind def\n");
XP_FilePrintf(f, "%%%%EndProlog\n");
//definition of 'show' command to handle unicode
// XP_FilePrintf(f, "/cwidth 12 def\n");
// XP_FilePrintf(f, "/cheight 12 def\n");
XP_FilePrintf(f, "/unicodeshow \n");
XP_FilePrintf(f, "{\n");
XP_FilePrintf(f, "/cwidth {currentfont /ScaleMatrix get 0 get} def \n");
XP_FilePrintf(f, "/cheight cwidth def \n");
XP_FilePrintf(f, " /str exch def\n");
XP_FilePrintf(f, " /i 0 def\n");
XP_FilePrintf(f, " str length /ls exch def\n");
XP_FilePrintf(f, " { i 1 add ls ge {exit} if\n");
XP_FilePrintf(f, " str i get /c1 exch def\n");
XP_FilePrintf(f, " str i 1 add get /c2 exch def\n");
XP_FilePrintf(f, " c2 1 ge \n");
XP_FilePrintf(f, " { \n");
XP_FilePrintf(f, " gsave\n");
XP_FilePrintf(f, " currentpoint translate\n");
XP_FilePrintf(f, " cwidth 1056 div cheight 1056 div scale\n");
XP_FilePrintf(f, " 2 -2 translate \n");
XP_FilePrintf(f, " /c c2 256 mul c1 add def c Unicodedict\n");
XP_FilePrintf(f, " exch get cvx exec \n");
XP_FilePrintf(f, " grestore\n");
XP_FilePrintf(f, " currentpoint exch cwidth add exch moveto\n");
XP_FilePrintf(f, " /i i 2 add def \n");
XP_FilePrintf(f, "\n");
XP_FilePrintf(f, " }\n");
XP_FilePrintf(f, " {\n");
XP_FilePrintf(f, " str i 1 getinterval show /i i 2 add def\n");
XP_FilePrintf(f, " }\n");
XP_FilePrintf(f, " ifelse\n");
XP_FilePrintf(f, "\n");
XP_FilePrintf(f, " }\n");
XP_FilePrintf(f, " loop\n");
XP_FilePrintf(f, "} bind def\n");
}
/** ---------------------------------------------------
@@ -529,10 +567,10 @@ nsPostScriptObj::annotate_page(char *aTemplate, int y, int delta_dir, int pn)
/** ---------------------------------------------------
* See documentation in nsPostScriptObj.h
* @update 2/1/99 dwc
* @update 2/1/99 dwc. Updated 3/22/2000 to deal with only non-Unicode chars. yueheng.xu@intel.com
*/
void
nsPostScriptObj::show(char* txt, int len, char *align)
nsPostScriptObj::show(const char* txt, int len, char *align)
{
XP_File f;
@@ -547,18 +585,71 @@ XP_File f;
XP_FilePrintf(f, "\\%c", *txt);
break;
default:
if (*txt < ' ' || (*txt & 0x80)){
XP_FilePrintf(f, "\\%o", *txt & 0xff);
}else{
XP_FilePrintf(f, "%c", *txt);
}
break;
XP_FilePrintf(f, "%c", *txt);
break;
}
txt++;
}
XP_FilePrintf(f, ") %sshow\n", align);
}
/** ---------------------------------------------------
* See documentation in nsPostScriptObj.h
* @update 3/22/2000 to deal with only unicode chars. yueheng.xu@intel.com
*/
void
nsPostScriptObj::show(const PRUnichar* txt, int len, char *align)
{
XP_File f;
unsigned char highbyte, lowbyte;
PRUnichar uch;
f = mPrintContext->prSetup->out;
XP_FilePrintf(f, "(");
while (len-- > 0) {
switch (*txt) {
case 0x0028: // '('
XP_FilePrintf(f, "\\050\\000");
break;
case 0x0029: // ')'
XP_FilePrintf(f, "\\051\\000");
break;
case 0x005c: // '\\'
XP_FilePrintf(f, "\\134\\000");
break;
default:
uch = *txt;
highbyte = (uch >> 8 ) & 0xff;
lowbyte = ( uch & 0xff );
// we output all unicode chars in the 2x3 digits oct format for easier post-processing
// Our 'show' command will always treat the second 3 digit oct as high 8-bits of unicode, independent of Endians
if ( lowbyte < 8 )
XP_FilePrintf(f, "\\00%o", lowbyte & 0xff);
else if ( lowbyte < 64 && lowbyte >= 8)
XP_FilePrintf(f, "\\0%o", lowbyte & 0xff);
else
XP_FilePrintf(f, "\\%o", lowbyte & 0xff);
if ( highbyte < 8 )
XP_FilePrintf(f, "\\00%o", highbyte & 0xff);
else if ( highbyte < 64 && highbyte >= 8)
XP_FilePrintf(f, "\\0%o", highbyte & 0xff);
else
XP_FilePrintf(f, "\\%o", highbyte & 0xff);
break;
}
txt++;
}
XP_FilePrintf(f, ") %sunicodeshow\n", align);
}
/** ---------------------------------------------------
* See documentation in nsPostScriptObj.h
* @update 2/1/99 dwc

View File

@@ -328,7 +328,12 @@ public:
* Issue a PS show command, which causes image to be rastered
* @update 2/1/99 dwc
*/
void show(char* aText, int aLen, char *aAlign);
void show(const char* aText, int aLen, char *aAlign);
/** ---------------------------------------------------
* This version takes an Unicode string.
* @update 3/22/2000 yueheng.xu@intel.com
*/
void show(const PRUnichar* aText, int aLen, char *aAlign);
/** ---------------------------------------------------
* set the clipping path to the current path using the winding rule
* @update 2/1/99 dwc

View File

@@ -1121,7 +1121,7 @@ nsIFontMetrics *fMetrics;
mFontMetrics->GetMaxAscent(ascent);
y += ascent;
mTMatrix->TransformCoord(&x, &y);
PostscriptTextOut((const char *)aString, 1, NS_PIXELS_TO_POINTS(x), NS_PIXELS_TO_POINTS(y), aFontID, aSpacing, PR_TRUE);
PostscriptTextOut((PRUnichar *)aString, 1, NS_PIXELS_TO_POINTS(x), NS_PIXELS_TO_POINTS(y), aFontID, aSpacing, PR_TRUE);
aX += *aSpacing++;
aString++;
}
@@ -1131,7 +1131,7 @@ nsIFontMetrics *fMetrics;
mFontMetrics->GetMaxAscent(ascent);
y += ascent;
mTMatrix->TransformCoord(&x, &y);
PostscriptTextOut((const char *)aString, aLength, NS_PIXELS_TO_POINTS(x), NS_PIXELS_TO_POINTS(y), aFontID, aSpacing, PR_TRUE);
PostscriptTextOut(aString, aLength, NS_PIXELS_TO_POINTS(x), NS_PIXELS_TO_POINTS(y), aFontID, aSpacing, PR_TRUE);
}
fMetrics = mFontMetrics;
@@ -1328,50 +1328,49 @@ nsAutoString fontFamily;
/** ---------------------------------------------------
* See documentation in nsRenderingContextPS.h
* @update 12/21/98 dwc
* @update 3/24/2000 yueheng.xu@intel.com
*/
void
nsRenderingContextPS :: PostscriptTextOut(const char *aString, PRUint32 aLength,
nscoord aX, nscoord aY, PRInt32 aFontID,
const nscoord* aSpacing, PRBool aIsUnicode)
{
int ptr = 0;
unsigned int i;
char *buf = 0;
nscoord fontHeight = 0;
//nscoord yCoord;
const nsFont *font;
mFontMetrics->GetHeight(fontHeight);
mFontMetrics->GetFont(font);
//yCoord = aY + (fontHeight / 2);
//nscoord ascent = 0;
//mFontMetrics->GetMaxAscent(ascent);
// convert the ascent to points
//ascent = ascent/20;
//yCoord = aY + ascent;
mPSObj->moveto(aX, aY);
if (PR_TRUE == aIsUnicode) {
//XXX: Investigate how to really do unicode with Postscript
// Just remove the extra byte per character and draw that instead
buf = new char[aLength];
for (i = 0; i < aLength; i++) {
buf[i] = aString[ptr];
ptr+=2;
}
mPSObj->show(buf, aLength, "");
delete buf;
} else {
mPSObj->show((char *)aString, aLength, "");
if (PR_TRUE != aIsUnicode) {
mPSObj->show(aString, aLength, "");
}
}
/** ---------------------------------------------------
* See documentation in nsRenderingContextPS.h
* @update 3/24/2000 yueheng.xu@intel.com
*/
void
nsRenderingContextPS :: PostscriptTextOut(const PRUnichar *aString, PRUint32 aLength,
nscoord aX, nscoord aY, PRInt32 aFontID,
const nscoord* aSpacing, PRBool aIsUnicode)
{
nscoord fontHeight = 0;
const nsFont *font;
mFontMetrics->GetHeight(fontHeight);
mFontMetrics->GetFont(font);
mPSObj->moveto(aX, aY);
if (PR_TRUE == aIsUnicode) {
mPSObj->show(aString, aLength, "");
}
}
#ifdef NOTNOW
HPEN nsRenderingContextPS :: SetupSolidPen(void)
{

View File

@@ -182,6 +182,10 @@ public:
nscoord aX, nscoord aY, PRInt32 aFontID,
const nscoord* aSpacing, PRBool aIsUnicode);
void PostscriptTextOut(const PRUnichar *aString, PRUint32 aLength,
nscoord aX, nscoord aY, PRInt32 aFontID,
const nscoord* aSpacing, PRBool aIsUnicode);
#ifdef MOZ_MATHML
/**
* Returns metrics (in app units) of an 8-bit character string