Back to index

lightning-sunbird  0.9+nobinonly
nsPostScriptObj.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
00024  *   Ken Herron <kherron@fastmail.us>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040  
00041 #ifndef _PSOBJ_H_
00042 #define _PSOBJ_H_
00043 
00044 #include "prtypes.h"  /* for int32 & friends */
00045 #ifdef __cplusplus
00046 #include "nsColor.h"
00047 #include "nsCoord.h"
00048 #include "nsRect.h"
00049 #include "nsString.h"
00050 
00051 #include "nsCOMPtr.h"
00052 #include "nsIPref.h"
00053 #include "nsHashtable.h"
00054 #include "nsIUnicodeEncoder.h"
00055 
00056 #include "nsIDeviceContextSpecPS.h"
00057 #include "nsIPersistentProperties2.h"
00058 #include "nsTempfilePS.h"
00059 #include "nsEPSObjectPS.h"
00060 
00061 class nsIImage;
00062 class nsIAtom;
00063 #endif
00064 
00065 #include <stdio.h>
00066 
00067 #define N_FONTS 8
00068 #define INCH_TO_PAGE(f) ((int) (.5 + (f)*720))
00069 
00070 typedef int XP_Bool;
00071 
00072 typedef void (*XL_CompletionRoutine)(void*);
00073 
00074 typedef struct page_breaks {
00075     int32 y_top;
00076     int32 y_break;
00077 } PageBreaks;
00078 
00079 #ifdef __cplusplus
00080 typedef struct PS_LangGroupInfo_ {
00081   nsIUnicodeEncoder *mEncoder;
00082   nsHashtable       *mU2Ntable;
00083 } PS_LangGroupInfo;
00084 #endif
00085 
00086 typedef struct LineRecord_struct LineRecord;
00087 
00088 /*
00089 ** Used to store state needed while translation is in progress
00090 */
00091 struct PrintInfo_ {
00092   const char *doc_title; /* best guess at title */
00093 
00094 #ifdef LATER
00095   THIS IS GOING TO BE DELETED XXXXX
00096   float       scale;        
00097   int32       pre_start;    
00098   int32       pre_end;      
00099   XP_List     *interesting; 
00100   XP_Bool     in_pre;              
00101 #endif
00102 
00103   /* These fields are used only by the text translator */
00104   char *line;                  /* Pointer to data for the current line */
00105   XP_Bool in_table;        /* True when caching lines in a table */
00106   XP_Bool first_line_p;            /* delete all this */
00107 
00108   int table_top,table_bottom;
00109   LineRecord *saved_lines;  /* cached lines for tables  */
00110   int last_y;        /* Used to track blank lines */
00111 };
00112 
00113 typedef struct PrintInfo_ PrintInfo;
00114 
00115 /*
00116 ** Used to pass info into text and/or postscript translation
00117 */
00118 struct PrintSetup_ {
00119   nscoord width;                /* Page size, in twips, as oriented for */
00120   nscoord height;               /* this print job. */
00121   
00122   const char* header;
00123   const char* footer;
00124   const char* paper_name;
00125 
00126   int *sizes;
00127   XP_Bool reverse;              /* Output order */
00128   XP_Bool color;                /* Image output */
00129   XP_Bool deep_color;                      /* 24 bit color output */
00130   XP_Bool landscape;            /* Rotated output */
00131   XP_Bool underline;            /* underline links */
00132   XP_Bool scale_images;         /* Scale unsized images which are too big */
00133   XP_Bool scale_pre;                /* do the pre-scaling thing */
00134   float rules;                                 /* Scale factor for rulers */
00135   int n_up;                     /* cool page combining */
00136   int bigger;                   /* Used to init sizes if sizesin NULL */
00137   const char* prefix;           /* For text xlate, prepended to each line */
00138   const char* eol;              /* For text translation, line terminator  */
00139   const char* bullet;           /* What char to use for bullets */
00140 
00141   struct URL_Struct_ *url;      /* url of doc being translated */
00142   XL_CompletionRoutine completion; /* Called when translation finished */
00143   void* carg;                   /* Data saved for completion routine */
00144   int status;                   /* Status of URL on completion */
00145   int num_copies;               /* Number of copies of job to print */
00146 };
00147 
00148 typedef struct PrintSetup_ PrintSetup;
00149 
00150 struct PSContext_{
00151 
00152     char        *url;         /* URL of current document */
00153     char        * name;           /* name of this context */
00154     char        * title;             /* title (if supplied) of current document */
00155     PrintSetup       *prSetup;         /* Info about print job */
00156     PrintInfo   *prInfo;        /* State information for printing process */
00157 };
00158 typedef struct PSContext_ PSContext;
00159 
00160 struct PSBoundingBox {          /* For BeginEPSF() */
00161   float llx, lly, urx, ury;
00162 };
00163 
00164 #ifdef __cplusplus
00165 class nsPostScriptObj
00166 {
00167 
00168 
00169 public:
00170   nsPostScriptObj();
00171   ~nsPostScriptObj();
00172   
00173   
00178   nsresult Init( nsIDeviceContextSpecPS *aSpec );
00183   void begin_page();
00188   void end_page();
00189 
00194   nsresult end_document();
00195 
00202   void write_prolog(FILE *aHandle, PRBool aFTPenable = PR_FALSE);
00203 
00209   nsresult write_script(FILE *aHandle);
00210 
00218   void moveto(nscoord aX, nscoord aY);
00227   void lineto(nscoord aX, nscoord aY);
00232   void closepath();
00239   void arc(nscoord aWidth, nscoord aHeight,float aStartAngle,float aEndAngle);
00249   void box(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00257   void box_subtract(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00267   void line(nscoord aX1, nscoord aY1, nscoord aX2, nscoord aY2, nscoord aThick);
00272   void stroke();
00277   void fill();
00282   void graphics_save();
00287   void graphics_restore();
00288 
00307   void draw_image(nsIImage *anImage,
00308       const nsRect& sRect, const nsRect& iRect, const nsRect& dRect);
00309 
00314   void begin_squished_text( float aSqeeze);
00319   void end_squished_text();
00324   void finalize_translation();
00330   void scale(float aX, float aY);
00337   void translate(nscoord aX, nscoord aY);
00342   void show(const char* aText, int aLen, const char *aAlign);
00347   void show(const PRUnichar* aText, int aLen, const char *aAlign, int aType);
00353   void show(const PRUnichar* aText, int aLen, const nsAFlatString& aCharList,
00354             PRUint16 aSubFontIdx);
00359   void clip();
00364   void eoclip(); 
00369   void newpath();
00374   void initclip();
00379   void clippath();
00384   void setcolor(nscolor aTheColor);
00389   void setscriptfont(PRInt16 aFontIndex,const nsString &aFamily,nscoord aHeight, PRUint8 aStyle, PRUint8 aVariant, PRUint16 aWeight, PRUint8 decorations);
00394   void setfont(const nsCString &aFontName, PRUint32 aHeight,
00395                PRInt32 aSubFont = -1);
00400   void comment(const char *aTheComment);
00405   void setlanggroup(nsIAtom* aLangGroup);
00410   void preshow(const PRUnichar* aText, int aLen);
00411 
00419   nsresult render_eps(const nsRect& aRect, nsEPSObjectPS &anEPS);
00420   
00421   void settitle(PRUnichar * aTitle);
00422 
00428   FILE * GetScriptHandle() { return mScriptFP; }
00429 
00440   void SetNumCopies(int aNumCopies);
00441 
00442   PRBool  GetUnixPrinterSetting(const nsCAutoString&, char**);
00443   PrintSetup            *mPrintSetup;
00444 private:
00445   PSContext             *mPrintContext;
00446   PRUint16              mPageNumber;
00447   nsCOMPtr<nsIPersistentProperties> mPrinterProps;
00448   char                  *mTitle;
00449   nsTempfilePS          mTempfileFactory;
00450   nsCOMPtr<nsILocalFile> mDocScript;
00451   FILE                  *mScriptFP;
00452 
00453 
00458   void initialize_translation(PrintSetup* aPi);
00464   void initlanggroup(FILE *aHandle);
00465 
00466 };
00467 
00468 #endif /* __cplusplus */
00469 
00470 #endif