Solved

Postscript printing issue with Polish.

Posted on 2014-03-23
24
430 Views
Last Modified: 2014-04-10
I am facing an issue with printing in Polish language.
This is not a character related issue but related to the Windows XP locale, Polish.

The printing is done from a system running on WES2009 to a network printer.
The print content is sent to this system by another system over the network.

When the language of the WES2009 system is English the contents are printed in Times-Roman.

But when the language is changed to Polish or Hungarian, the same content is printed in the ISO font.

I am not an expert in postscript commands, and also it has been difficult to browse thru all the legacy source code, one thing I could find out was, the font being sent is "Times-Roman-ISOLatin1".

I tried to debug the issue:

I commented the code which is concatenating the string "-ISOlatin1" to the font string "Times-Roman", now the print is in Times-Roman. Why is this affecting only when in Polish and not in English?

Another part of the code: modifies the font if locale is not Polish.
I removed the check (so it is not locale dependent), but with this change, I see the printer data LED blink twice but doesn't print anything.

My suspect is the first part of the code.

Could someone help me understand the link between the OS locale and ISOLatin1.
I can do some more debugging based on your suggestions.

I have attached prints in both the locales.

Note: I cannot post the exact code here, but I have ensured no miss in logic.

   /* Create the iso font name by appending the following string onto the main font name */
   strcpy (iso_font_name, font_name);
   strcat (iso_font_name, (TEXT *)"-ISOLatin1");

   /* Select a font to use */
   Specify_A_Font ( output_fd, font_name, iso_font_name,
                    current_font_size, current_font_scale_factor);

Open in new window

*******************
VOID Specify_A_Font(FILE            *output_fd,
                     TEXT            *ptr_initial_font_name, 
                     TEXT            *ptr_new_font_name,
{
TEXT  *ptr_font_name;

       GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, tsLocaleBuf, dim(tsLocaleBuf));   // LOCALE_USER_DEFAULT - XPe
       if ((_tcscmp(tsLocaleBuf, _T("CSY")) != 0) && 
		   (_tcscmp(tsLocaleBuf, _T("HUN")) != 0) && 
		   (_tcscmp(tsLocaleBuf, _T("PLK")) != 0) ) 
       { 
           /* Write the command to perform the encoding vector conversion */
           fprintf(output_fd, (TEXT *)"\n/InitialFontName /%s def /NewFontName /%s def iso_font_convert_function \n", ptr_initial_font_name, ptr_new_font_name);
       } 

   /* Write the command to set the font_name as the font to use */
   fprintf(output_fd, (TEXT *)"/%s findfont %1.0f f ", ptr_font_name,
           (float)points/font_scale_factor);
} /* end Specify_A_Font */

Open in new window






Thanks,
Basavesh
English.jpg
Polish.jpg
0
Comment
Question by:Basavesh
  • 10
  • 10
  • +2
24 Comments
 
LVL 38

Expert Comment

by:Herman D'Hondt
Comment Utility
The reason why, when the font modification is commented out, the printer receives the file but doesn't print is because of the default way PostScript behaves. If there is *any* error in the PS code, the default is to ignore the rest of the file. That means the "showpage" command at the end of the page will not be seen; hence the page will not be printed. Commenting out part of a PS command can leave the printer's interpreter in an error state.

If you use a driver like Windows, the preamble of the print file normally includes code that tells the printer to print an error page whenever there is an error. Some printers can be set to print an error page on any error (but the Windows code overrides that).

From your attachments, when the locale is Polish, the font is changed to Courier. That is PostScript's default font when the requested font is not available. In other words, the font with the "-ISOLatin1" string appended does not exist in the printer. You need to either download that font to the printer (either as part of the print job, or by making the font permanent in the printer), or use a different one.
0
 

Author Comment

by:Basavesh
Comment Utility
Thanks hd for answering both to of my situations.
I would like to get my doubts clarified, my questions may be dumb, am trying to understand the root cause of the issue.

From your attachments, when the locale is Polish, the font is changed to Courier. That is PostScript's default font when the requested font is not available. In other words, the font with the "-ISOLatin1" string appended does not exist in the printer. You need to either download that font to the printer (either as part of the print job, or by making the font permanent in the printer), or use a different one.
Could this happen when same system & printer are used by just changing my system's locale from English to polish?

In other words, the font with the "-ISOLatin1" string appended does not exist in the printer.
Could the presence of font depend upon the system's locale? because it was present when the locale was English.

You need to either download that font to the printer (either as part of the print job, or by making the font permanent in the printer), or use a different one.
Could you explain more on this please. Can I code this or does it need change on the printer itself.
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
Comment Utility
English uses ASCII Polish uses UTF8 you need to download the postscipt font and load it in the printer or upload the font to the printer as part of your print job
0
 
LVL 38

Expert Comment

by:Herman D'Hondt
Comment Utility
Could this happen when same system & printer are used by just changing my system's locale from English to polish?
It's your software that decides what actions to take when the system is set to Polish.

Could the presence of font depend upon the system's locale? because it was present when the locale was English.
No, the font has to be either permanently resident in the printer, or your software has to download it as part of the print job. The easiest way is probably to make the font permanently resident in the printer. For that you need a PS (Type 1 or Type 3) font and you need a utility to download it. You may be able to do this from the printer's web page. Xerox have a utility here for it. It's claimed to be for the Phaser 8560 but should work with any PS printer.
0
 
LVL 38

Expert Comment

by:Herman D'Hondt
Comment Utility
Further to my last post, you will need the PostScript font. That's the only type the printer can store. The PC would have the TrueType (TTF) font, which the driver can use to print the characters. However, as you are using special software that bypasses the driver, you will need to get hold f the correct font.

Another possibility: you can change the font to something that is already resident in the font, like Times New Roman. Check the printer's font list and pick one that's on both the PC and printer. I don't know how much control you have over the software though.
0
 
LVL 32

Expert Comment

by:sarabande
Comment Utility
to add to above suggestions:

Could the presence of font depend upon the system's locale? because it was present when the locale was English.

the problem is not that the font does not exist (sometimes) at the target machine but that font family name you created by concatenating an existing name with "-ISOLatin1" is a name that doesn't exist. generally the font mapper on the target machine tries to find the best match to the requirements given. a valid familyname would be a strong criterion if a font with that name exists at the target machine. that's why it worked when you choose "Times New Roman" which is available at any windows system. when the familyname doesn't exist, the result of the fontmapping is arbitrary. if some parts of the name do match, it might lead to a different result as if not. you said, the "Times New Roman"  is correct, but actually the fontname passed has suffix "-ISOLatin1" where I didn't find any fontname with that name at my machine. so I assume that the English name also was wrong and that the "Times New Roman" only was the best match for this case.

to solve the issue you should find a good font that covers all of the target languages/code-pages and use that name. or you provide a fontname for each language. in any case you should use fonts that came with the os and not make any assumptions on font names.

Sara
0
 

Author Comment

by:Basavesh
Comment Utility
As I said earlier this is a legacy code.
Am trying to solve something which is not working for Polish.
Today I found that, there is font encoding being done in the code.
Like this:
    else if ( (_tcscmp(tsLocaleBuf, _T("CSY")) == 0) || 
	      (_tcscmp(tsLocaleBuf, _T("HUN")) == 0) || 
	      (_tcscmp(tsLocaleBuf, _T("PLK")) == 0) )
    {
        fprintf(output_fd, (TEXT *)PS_POLHUN_ENCODING_1);
        fprintf(output_fd, (TEXT *)PS_POLHUN_ENCODING_2);
        fprintf(output_fd, (TEXT *)PS_POLHUN_ENCODING_3);
        fprintf(output_fd, (TEXT *)PS_POLHUN_ENCODING_4);
        fprintf(output_fd, (TEXT *)PS_POLHUN_ENCODING_5);
        fprintf(output_fd, (TEXT *)PS_POLHUN_ENCODING_6);
        fprintf(output_fd, (TEXT *)PS_POLHUN_ENCODING_7);

Open in new window

One of these macros look like
#define PS_POLHUN_ENCODING_1 "%%%BeginResource: encoding ISOLatin2Encoding \n\
/ISOLatin2Encoding [ \n\
/.notdef /Aogonek /Cacute /Eogonek /degree /Eogonek /Lslash /Nacute \n\
/Itilde /Sacute /Zacute /Zdotaccent /aogonek /cacute /eogonek /lslash \n\
/nacute /.notdef /sacute /zacute /zdotaccent /zdotaccent /zacute /cacute \n\
/Ohungarumlaut /Uhungarumlaut /.notdef /.notdef /ohungarumlaut /uhungarumlaut /Ohungarumlaut /Uhungarumlaut \n\
/space /exclam /quotedbl /numbersign /dollar /percent /ampersand /quoteright \n\
/parenleft /parenright /asterisk /plus /comma /minus /period /slash \n\
/zero /one /two /three /four /five /six /seven \n\
/eight /nine /colon /semicolon /less /equal /greater /question \n\
%% 100 \n\
/at /A /B /C /D /E /F /G \n\
/H /I /J /K /L /M /N /O \n\
/P /Q /R /S /T /U /V /W \n\
/X /Y /Z /bracketleft /backslash /bracketright /asciicircum /underscore \n\
/quoteleft /a /b /c /d /e /f /g \n\
/h /i /j /k /l /m /n /o \n\
/p /q /r /s /t /u /v /w \n\
/x /y /z /braceleft /bar /braceright /asciitilde /.notdef \n"

Open in new window


I tested, both Hungarian and Polish are not working (prints in Courier).
Could there be error in these macros?
How to debug these?
Can I trace the flow?

Thanks,
Basavesh
0
 
LVL 38

Expert Comment

by:Herman D'Hondt
Comment Utility
Yes, there must be errors in the macro. As I said before, the printer prints in Courier, because it does not have the font requested. The PS code seems to define a number of special Polish/Hungarian characters. It does not appear to be a full font though.
0
 

Author Comment

by:Basavesh
Comment Utility
Yes, hd. I too came to the conclusion that there might be errors in this encoding as you mentioned it would go to courier in such a case.

There are 12 such macros defined, as you can see in the "else if" section, they are added to the print one after another. All of them together form the font encoding.
It would be very helpful to know if there is way to find errors in this.

Thanks,
Basavesh
0
 
LVL 38

Expert Comment

by:Herman D'Hondt
Comment Utility
This is outside my expertise, but the PS code you supplied does not define a font. A font definition, as far as I know, should start with something like "%!PS-AdobeFont-1.0:". Hence asking the printer to use it will trigger Courier.
0
 

Author Comment

by:Basavesh
Comment Utility
A point in favour of the code being correct would be that the font encoding is actually working, because the polish characters like  "small letter with o with acute" - ó   are printed (as seen in attachment polish_1.jpg). So it may not be completely wrong.
Only thing I need to find is why is it getting printed in Courier (For the record, I could have lived with it if it was not overlapping).

Someone can comment if the above conclusion is correct.

The encoding of ó is found in second macro of font encoding
#define PS_POLHUN_ENCODING_2 "%% 200 \n\
/Ccedilla /udieresis /eacute /acircumflex /adieresis /Oacute /.notdef /ccedilla \n\
/.notdef /edieresis /.notdef /.notdef /icircumflex /.notdef /Adieresis /.notdef \n\
/Eacute /.notdef /.notdef /ocircumflex /odieresis /.notdef /.notdef /.notdef \n\
/.notdef /Odieresis /Udieresis /.notdef /.notdef /.notdef /.notdef /.notdef \n\
/aacute /iacute /oacute /uacute /.notdef /.notdef /.notdef /.notdef \n\
/.notdef /Scaron /.notdef /Tcaron /.notdef /.notdef /Zcaron /.notdef \n\
/.notdef /.notdef /.notdef /.notdef /.notdef /Aacute /Acircumflex /.notdef \n\
/.notdef /scaron /.notdef /tcaron /.notdef /.notdef /zcaron /.notdef \n\
%% 300 \n\
/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef \n\
/Ccaron /.notdef /.notdef /.notdef /Ecaron /.notdef /.notdef /Dcaron \n\
/.notdef /.notdef /Edieresis /Ncaron /.notdef /Iacute /.notdef /.notdef \n\
/Rcaron /Uring /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef \n\
/.notdef /Ocircumflex /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef \n\
/Uacute /ccaron /.notdef /yacute /Yacute /ecaron /.notdef /dcaron \n\
/.notdef /.notdef /ncaron /.notdef /.notdef /.notdef /.notdef /degree \n\
/caron /uring /rcaron /.notdef /.notdef /.notdef /.notdef /.notdef \n\
] def \n"

Open in new window


This is a very old (15 years old) code and not much can be suspected of it.
All the printing functionality is working in all aspects. For 17 languages.
I am only working on resolving the overlapping issue. Only way of solving it is printing in Times-Roman.

****************************

As I mentioned earlier, the printing is scattered in various files. You can see the macro for the font definition header in one of the files.

/* Standard Postscript 1st line */
#define PS_HEADER           "%%!PS-Adobe-3.0\n"

/* Postscript command used to tell the printer to print the page */
#define PS_SHOWPAGE         "showpage\n" 
#define PS_EOJ_CHARACTER    0x04

Open in new window

polish-1.jpg
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 38

Expert Comment

by:Herman D'Hondt
Comment Utility
The overlapping is happens because the Courier characters do not have the same width as the Times characters.

Your macro is not a "font definition header". The command "%%!PS-Adobe-3.0" is the first line of any normal PS print file. It is a special comment (normal comments start with a single %) that can be used to switch the printer into PS mode. Windows drivers use PJL (HP's Printer Job Control Language) commands for that instead.

The other 2 macros just define the normal PS "print this page" command (showpage) and the end-of-file character (Ctrl-D).

Do you have any control over the font used in this job?
0
 

Author Comment

by:Basavesh
Comment Utility
Do you have any control over the font used in this job?
Yes.

I have verified by a logging the font, that it is "Time-Roman-ISOLatin1" here.
   /* Create the iso font name by appending the following string onto the main font name */
   strcpy (iso_font_name, font_name);
   strcat (iso_font_name, (TEXT *)"-ISOLatin1");

   /* Select a font to use */
   Specify_A_Font ( output_fd, font_name, iso_font_name,
                    current_font_size, current_font_scale_factor);

Open in new window



VOID Specify_A_Font(FILE            *output_fd,
                     TEXT            *ptr_initial_font_name, 
                     TEXT            *ptr_new_font_name,
{
TEXT  *ptr_font_name;

       GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, tsLocaleBuf, dim(tsLocaleBuf));   // LOCALE_USER_DEFAULT - XPe
       if ((_tcscmp(tsLocaleBuf, _T("CSY")) != 0) && 
		   (_tcscmp(tsLocaleBuf, _T("HUN")) != 0) && 
		   (_tcscmp(tsLocaleBuf, _T("PLK")) != 0) ) 
       { 
           /* Write the command to perform the encoding vector conversion */
           fprintf(output_fd, (TEXT *)"\n/InitialFontName /%s def /NewFontName /%s def iso_font_convert_function \n", ptr_initial_font_name, ptr_new_font_name);
       } 

   /* Write the command to set the font_name as the font to use */
   fprintf(output_fd, (TEXT *)"/%s findfont %1.0f f ", ptr_font_name,
           (float)points/font_scale_factor);
} /* end Specify_A_Font */

Open in new window

0
 
LVL 38

Expert Comment

by:Herman D'Hondt
Comment Utility
I can virtually guarantee that the printer does not have a font called Times-Roman-ISOLatin1 installed. Times-Roman may be present, but Times-Roman-ISOLatin1 is not, and your code does not download it. That's why it prints Courier.
0
 

Author Comment

by:Basavesh
Comment Utility
The ISOlatin1 is being managed by the encoding again, if I understand this correctly.
Times-Roman-ISOLatin1 is common font used for all the languages.
/* PS Function to convert the font codes to ISO codes to get international characters */
#define PS_ISO_ENCODING   "\n%%--- Function to convert the font codes to ISO codes to get international characters--- \n\
/iso_font_convert_function \n\
{ \n\
 InitialFontName findfont \n\
 dup length dict begin \n\
   {1 index /FID ne {def} {pop pop} ifelse} forall \n\
   /Encoding ISOLatin1Encoding def \n\
   currentdict \n\
 end \n\
 NewFontName exch definefont pop \n\
} bind def \n "

Open in new window



I donot yet understand this completely, of the 50+ files written for laser printing.
The only thing I am betting on is that the same code is used by other languages too where it works fine. For example Russian has a similar encoding
TCHAR tsLocaleBuf [4];
    GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, tsLocaleBuf, dim(tsLocaleBuf));   // LOCALE_USER_DEFAULT - XPe     
    if (_tcscmp(tsLocaleBuf, _T("RUS")) == 0)
    {
        fprintf(output_fd, (TEXT *)PS_RUSSIAN_ENCODING_0);
        fprintf(output_fd, (TEXT *)PS_RUSSIAN_ENCODING_1);
        fprintf(output_fd, (TEXT *)PS_RUSSIAN_ENCODING_2);
        fprintf(output_fd, (TEXT *)PS_RUSSIAN_ENCODING_3);
        fprintf(output_fd, (TEXT *)PS_RUSSIAN_ENCODING_4);
        // more encodings follow
        .
        .
        
        fprintf(output_fd, (TEXT *)PS_RUSSIAN_ENCODING_52);
    }
    else if ( (_tcscmp(tsLocaleBuf, _T("CSY")) == 0) || 
		      (_tcscmp(tsLocaleBuf, _T("HUN")) == 0) || 
			  (_tcscmp(tsLocaleBuf, _T("PLK")) == 0) )
    {
        fprintf(output_fd, (TEXT *)PS_POLHUN_ENCODING_1);
        fprintf(output_fd, (TEXT *)PS_POLHUN_ENCODING_2);
        fprintf(output_fd, (TEXT *)PS_POLHUN_ENCODING_3);
        // more encodings follow
        .
        .
        
        fprintf(output_fd, (TEXT *)PS_POLHUN_ENCODING_12);
    }
    else
    {
        fprintf(output_fd, (TEXT *)PS_ISO_ENCODING);
    }

Open in new window

Russian is printing fine in Times Roman, characters are Cyrillic though.
There are 13 languages in total which are printing OK.
Only issue is with Polish, Czech & Hungarian. But even these are printing their characters correctly except that they are in the fixed width font (Courier).
0
 
LVL 38

Expert Comment

by:Herman D'Hondt
Comment Utility
The funny thing is that the characters you're trying to define in you're earlier post already exist in the standard Times Roman font, as per this document. Times Roman does not have Cyrillic characters, though.

What happens if you comment out the code that adds ISOLatin1 to the font name for Polish & Hungarian?
0
 

Author Comment

by:Basavesh
Comment Utility
What happens if you comment out the code that adds ISOLatin1 to the font name for Polish & Hungarian?
Thats the first thing I tried.
I commented the code which is concatenating the string "-ISOlatin1" to the font string "Times-Roman", now the print is in Times-Roman. Why is this affecting only when in Polish and not in English?
0
 
LVL 38

Expert Comment

by:Herman D'Hondt
Comment Utility
Sorry, forgot that. But, when it is commented out, do the special characters print correctly?
0
 

Author Comment

by:Basavesh
Comment Utility
I tested that today, they don't. Blanks are printed in place of polish characters.

I also tested by commenting the font encoding for polish, but in this case the print didn't go through.
0
 
LVL 16

Expert Comment

by:DansDadUK
Comment Utility
I don't know the answer to your question (I don't know PostScript very well), just a comment:

-ISOLatin1 is almost certainly referring to the ISO 8859-1 Latin 1 coded character set (see http://en.wikipedia.org/wiki/ISO/IEC_8859 ) which is the standard 8-bit set used in Western European environments.

It doesn't include Cyrillic characters, or characters used in Central European countries; for the latter, you'd want the ISO 8859-2 Latin-2, or ISO 8859-16 Latin-10 sets.

I've no idea what default coded character set is assumed by PostScript.

Modern usage (i.e. not with your 15-year-old code) would be to use Unicode or one of the Unicode Transformation Formats (usually UTF-8); again, I've no idea how this is supported within PostScript.
0
 

Author Comment

by:Basavesh
Comment Utility
I have some more data to help Experts to help me :)

In my system, I could get access to the PS file which is stored temporarily (1-2 seconds) under the spool folder, before it is sent to the printer.

I used GSView to view the PS file I copied from the spool folder.
To my surprise GSview is showing the print in Timesroman. (Just to be sure I checked at the printer that it still is in Courier)

Please suggest me if I could try anything to make this print in Timesroman somehow.
The printer's printability of the polish characters is proven as it is able to print the character both in timesroman & Courier (overlapping under courier is the only issue).

Thanks
Basavesh
0
 
LVL 38

Accepted Solution

by:
Herman D'Hondt earned 500 total points
Comment Utility
GhostView has access to fonts on the PC, so it may be able to resolve the fontname. The printer can only use fonts that are either resident in the printer, or downloaded as part of the print job.
0
 

Author Closing Comment

by:Basavesh
Comment Utility
#define PS_POLHUN_ENCODING_10 "\n\
%% oldfontname newfontname baseEncoding targetEncoding compositeChars -- \n\
/makeComposite \n\
{ \n\
  makeCompositeDict begin doMakeComposite end \n\
} bind def \n\
 \n\
%% oldfontname newfontname \n\
/eurifyFont \n\
{ \n\
  makeCompositeDict begin doEurifyFont end \n\
} bind def \n\
%%EndResource \n\
 \n\
/Times-Bold-ISOLatin1  findfont dup length dict begin  \n\
  {1 index /FID ne {def} {pop pop} ifelse} forall  \n\
  /Encoding ISOLatin2Encoding def  \n\
currentdict end \n\
/Times-Bold-ISOLatin1  exch definefont /TF exch def \n"

The composite fonts were defined as "Times-Bold-ISOLatin1", which has errors as you can see from the above code. I found the correct way to do it and it is working now.
I still am facing with some issues as side-effects of this change though, which I need to resolve. I will post more questions regarding them.

Thanks for all who helped me in getting to this.
Basavesh
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now