Bug 690301

Summary: Request to treat text and graphics differently
Product: Ghostscript Reporter: Marcos H. Woehrmann <marcos.woehrmann>
Component: Graphics LibraryAssignee: Ray Johnston <ray.johnston>
Status: NOTIFIED FIXED    
Severity: enhancement    
Priority: P2    
Version: master   
Hardware: All   
OS: All   
Customer: 211 Word Size: ---
Attachments: combined.pdf

Description Marcos H. Woehrmann 2009-02-24 08:56:11 UTC
We have a request from a customer to improve the quality of Ghostscript output for faxing.  When the 
attached PDF file is converted to tiffg4 @ 200 dpi the small, colored text is not legible.  I suggested using 
a custom transfer function:

 << /Install { { 0.85 gt { 1 } { 0 } ifelse } settransfer } >> setpagedevice

This greatly improved the text quality but made the graphics and images in the document unusable.  The 
customer would like a way of improving the text darkness but leaving the images alone.
Comment 1 Marcos H. Woehrmann 2009-02-24 09:01:57 UTC
Created attachment 4807 [details]
combined.pdf
Comment 2 Ken Sharp 2009-02-24 09:17:56 UTC
If this is only required for PDF, perhaps another possibility would be to set
the current colour to black when a BT operation is encountered, and reset it on ET ?

Its also possible to redefine all the show operators for PostScript to do the
same, but tedious...
Comment 3 Ray Johnston 2009-02-24 09:22:12 UTC
For general PS input, there are 8 text drawing operators that could be
redefined in order to save the currrenttransfer, execute the real operator,
then restore the transfer function.

In PDF interpreter, it is easier because the BT and ET PDF operators can be
hooked to do this.

Please let us know if you need a patch for the PDF interpreter, or for PS input
documents as well.
Comment 4 Ray Johnston 2009-02-26 09:51:33 UTC
The customer reports that they only need PDF input.
Comment 5 Ray Johnston 2009-03-10 10:44:00 UTC
This is an alternate 'pdf_ops.ps' that allows applying a unique transfer function
defined as /TR_text to PDF text objects.

Note that since this only works within BT ... ET PDF text blocks, text that is
part of an image will not be affected.

Uasge: you must pre-define the transfer function to be applied to text by
       defining it in userdict. This can be done in a prefix file or by a
       -c "..." -f sequence on the command line.

Example:
gswin32c -c "/TR_text { 0.85 gt { 1 } { 0 } ifelse } bind def" -f combined.pdf

The changes to pdf_ops.ps are:
-------------------------------------------------------------------------------
*** Resource/Init/pdf_ops.ps Wed Dec 10 12:22:06 2008
--- ./pdf_ops.ps Tue Mar 10 10:35:10 2009
***************
*** 450,455 ****
--- 450,459 ----
  } bdef

  /BT {
+   % PATCH TO APPLY A TRANSFER FUNCTION TO TEXT
+   userdict /TRsave currenttransfer put
+   userdict /TR_text known { userdict /TR_text get settransfer } if
+   % END PATCH
    currentdict /TextLineMatrix .knownget
      { identmatrix pop TextMatrix identmatrix pop }
      { matrix /TextLineMatrix gput matrix /TextMatrix gput }
***************
*** 461,466 ****
--- 465,473 ----
    matrix /TextTempMatrix gput         % see settextposition
  } bdef
  /ET {
+   % PATCH TO RESTORE the NON-TEXT TRANSFER FUNCTION
+   userdict /TRsave get settransfer
+   % END PATCH
    TextRenderingMode 4 ge { clip newpath } if
    TextSaveMatrix setmatrix
    currentdict /TextSaveMatrix undef

-------------------------------------------------------------------------------
Comment 6 Ray Johnston 2009-03-12 10:35:32 UTC
Customer replies that this works for them and "The graphics and text both look
great."

Closing.