home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 720 / PDF090B4-SorceCode / pdf / TextOutputDev.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  6.6 KB  |  223 lines

  1. //========================================================================
  2. //
  3. // TextOutputDev.h
  4. //
  5. // Copyright 1997 Derek B. Noonburg
  6. //
  7. //========================================================================
  8. //
  9. //
  10. // Ported to EPOC by Sander van der Wal
  11. //
  12. // $Id: TextOutputDev.h 1.2 2000-09-17 13:38:14+02 svdwal Exp svdwal $
  13.  
  14. #ifndef TEXTOUTPUTDEV_H
  15. #define TEXTOUTPUTDEV_H
  16.  
  17. #ifdef __GNUC__
  18. #pragma interface
  19. #endif
  20.  
  21. #ifndef __E32BASE_H__
  22. #include <e32base.h>
  23. #endif
  24.  
  25. #include <stdio.h>
  26. #include "gtypes.h"
  27. #include "GfxFont.h"
  28. #include "OutputDev.h"
  29.  
  30. class GfxState;
  31. class GString;
  32.  
  33. //------------------------------------------------------------------------
  34. // TextString
  35. //------------------------------------------------------------------------
  36.  
  37. class TextString: public CBase {
  38. public:
  39.  
  40.   // Constructor.
  41.   TextString(FontEncoding& aAscii7Encoding, FontEncoding& aIsoLatin1Encoding)
  42.     :ascii7Encoding(aAscii7Encoding), isoLatin1Encoding(aIsoLatin1Encoding){}
  43.   void ConstructL(GfxState *state, GBool hexCodes1);
  44.   // Destructor.
  45.   ~TextString();
  46.  
  47.   // Add a character to the string.
  48.   void addChar(GfxState *state, double x, double y,
  49.            double dx, double dy,
  50.            Guchar c, GBool useASCII7);
  51.  
  52.   // Add a 16-bit character to the string.
  53.   void addChar16(GfxState *state, double x, double y,
  54.          double dx, double dy,
  55.          int c, GfxFontCharSet16 charSet);
  56.  
  57. private:
  58.  
  59.   double xMin, xMax;        // bounding box x coordinates
  60.   double yMin, yMax;        // bounding box y coordinates
  61.   int col;            // starting column
  62.   GString *text;        // the text
  63.   double *xRight;        // right-hand x coord of each char
  64.   TextString *yxNext;        // next string in y-major order
  65.   TextString *xyNext;        // next string in x-major order
  66.   GBool hexCodes;        // subsetted font with hex char codes
  67.  
  68.   friend class TextPage;
  69. #ifdef __SYMBIAN32__
  70.   FontEncoding& ascii7Encoding;
  71.   FontEncoding& isoLatin1Encoding;
  72. #endif
  73. };
  74.  
  75. //------------------------------------------------------------------------
  76. // TextPage
  77. //------------------------------------------------------------------------
  78.  
  79. class TextPage {
  80. public:
  81.  
  82.   // Constructor.
  83.   TextPage(FontEncoding& aAscii7Encoding, FontEncoding& aIsoLatin1Encoding)
  84.     :ascii7Encoding(aAscii7Encoding), isoLatin1Encoding(aIsoLatin1Encoding) {}
  85.   void ConstructL(GBool useASCII7, GBool rawOrder);
  86.  
  87.   // Destructor.
  88.   ~TextPage();
  89.  
  90.   // Begin a new string.
  91.   void beginString(GfxState *state, GString *s, GBool hex1);
  92.  
  93.   // Add a character to the current string.
  94.   void addChar(GfxState *state, double x, double y,
  95.            double dx, double dy, Guchar c);
  96.  
  97.   // Add a 16-bit character to the current string.
  98.   void addChar16(GfxState *state, double x, double y,
  99.          double dx, double dy, int c,
  100.          GfxFontCharSet16 charSet);
  101.  
  102.   // End the current string, sorting it into the list of strings.
  103.   void endString();
  104.  
  105.   // Coalesce strings that look like parts of the same line.
  106.   void coalesce();
  107.  
  108.   // Find a string.  If <top> is true, starts looking at top of page;
  109.   // otherwise starts looking at <xMin>,<yMin>.  If <bottom> is true,
  110.   // stops looking at bottom of page; otherwise stops looking at
  111.   // <xMax>,<yMax>.  If found, sets the text bounding rectange and
  112.   // returns true; otherwise returns false.
  113.   GBool findText(char *s, GBool top, GBool bottom,
  114.          double *xMin, double *yMin,
  115.          double *xMax, double *yMax,
  116.      GBool aCaseSensitive);
  117.  
  118.   // Get the text which is inside the specified rectangle.
  119.   GString *getText(double xMin, double yMin,
  120.            double xMax, double yMax);
  121.  
  122.   // Dump contents of page to a file.
  123.   void dump(FILE *f);
  124.  
  125.   // Clear the page.
  126.   void clear();
  127.  
  128. private:
  129.  
  130.   GBool useASCII7;        // use 7-bit ASCII?
  131.   GBool rawOrder;        // keep strings in content stream order
  132.  
  133.   TextString *curStr;        // currently active string
  134.  
  135.   TextString *yxStrings;    // strings in y-major order
  136.   TextString *xyStrings;    // strings in x-major order
  137.   TextString *yxCur1, *yxCur2;    // cursors for yxStrings list
  138.  
  139. #ifdef __SYMBIAN32__
  140.   FontEncoding& ascii7Encoding;
  141.   FontEncoding& isoLatin1Encoding;
  142. #endif
  143. };
  144.  
  145. //------------------------------------------------------------------------
  146. // TextOutputDev
  147. //------------------------------------------------------------------------
  148.  
  149. class TextOutputDev: public OutputDev {
  150. public:
  151.  
  152.   // Open a text output file.  If <fileName> is NULL, no file is written
  153.   // (this is useful, e.g., for searching text).  If <useASCII7> is true,
  154.   // text is converted to 7-bit ASCII; otherwise, text is converted to
  155.   // 8-bit ISO Latin-1.  <useASCII7> should also be set for Japanese
  156.   // (EUC-JP) text.  If <rawOrder> is true, the text is kept in content
  157.   // stream order.
  158.   TextOutputDev() {}
  159.   void ConstructL(TFileName* fileName, GBool useASCII7, GBool rawOrder);
  160.  
  161.   // Destructor.
  162.   virtual ~TextOutputDev();
  163.  
  164.   // Check if file was successfully created.
  165.   virtual GBool isOk() { return ok; }
  166.  
  167.   //---- get info about output device
  168.  
  169.   // Does this device use upside-down coordinates?
  170.   // (Upside-down means (0,0) is the top left corner of the page.)
  171.   virtual GBool upsideDown() { return gTrue; }
  172.  
  173.   // Does this device use drawChar() or drawString()?
  174.   virtual GBool useDrawChar() { return gTrue; }
  175.  
  176.   //----- initialization and control
  177.  
  178.   // Start a page.
  179.   virtual void startPageL(int pageNum, GfxState *state);
  180.  
  181.   // End a page.
  182.   virtual void endPage();
  183.  
  184.   //----- update text state
  185.   virtual void updateFont(GfxState *state);
  186.  
  187.   //----- text drawing
  188.   virtual void beginString(GfxState *state, GString *s);
  189.   virtual void endString(GfxState *state);
  190.   virtual void drawChar(GfxState *state, double x, double y,
  191.             double dx, double dy, Guchar c);
  192.   virtual void drawChar16(GfxState *state, double x, double y,
  193.               double dx, double dy, int c);
  194.  
  195.   //----- special access
  196.  
  197.   // Find a string.  If <top> is true, starts looking at top of page;
  198.   // otherwise starts looking at <xMin>,<yMin>.  If <bottom> is true,
  199.   // stops looking at bottom of page; otherwise stops looking at
  200.   // <xMax>,<yMax>.  If found, sets the text bounding rectange and
  201.   // returns true; otherwise returns false.
  202.   GBool findText(char *s, GBool top, GBool bottom,
  203.          double *xMin, double *yMin,
  204.          double *xMax, double *yMax,
  205.      GBool aCaseSensitive);
  206.  
  207. private:
  208.  
  209.   FILE *f;            // text file
  210.   GBool needClose;        // need to close the file?
  211.   TextPage *text;        // text for the current page
  212.   GBool rawOrder;        // keep text in content stream order
  213.   GBool hexCodes;        // subsetted font with hex char codes
  214.   GBool ok;            // set up ok?
  215.  
  216. #ifdef __SYMBIAN32__
  217.   FontEncoding* ascii7Encoding;
  218.   FontEncoding* isoLatin1Encoding;
  219. #endif
  220. };
  221.  
  222. #endif
  223.