⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textoutputdev.h

📁 这是一个做pdf阅读器的源代码文件,是大家学习阅读器资料的很好参考
💻 H
📖 第 1 页 / 共 2 页
字号:
//========================================================================//// TextOutputDev.h//// Copyright 1997-2003 Glyph & Cog, LLC////========================================================================#ifndef TEXTOUTPUTDEV_H#define TEXTOUTPUTDEV_H#include <aconf.h>#ifdef USE_GCC_PRAGMAS#pragma interface#endif#include <stdio.h>#include "gtypes.h"#include "GfxFont.h"#include "OutputDev.h"class GString;class GList;class GfxFont;class GfxState;class UnicodeMap;class Link;class TextWord;class TextPool;class TextLine;class TextLineFrag;class TextBlock;class TextFlow;class TextWordList;class TextPage;//------------------------------------------------------------------------typedef void (*TextOutputFunc)(void *stream, char *text, int len);//------------------------------------------------------------------------// TextFontInfo//------------------------------------------------------------------------class TextFontInfo {public:  TextFontInfo(GfxState *state);  ~TextFontInfo();  GBool matches(GfxState *state);#if TEXTOUT_WORD_LIST  // Get the font name (which may be NULL).  GString *getFontName() { return fontName; }  // Get font descriptor flags.  GBool isFixedWidth() { return flags & fontFixedWidth; }  GBool isSerif() { return flags & fontSerif; }  GBool isSymbolic() { return flags & fontSymbolic; }  GBool isItalic() { return flags & fontItalic; }  GBool isBold() { return flags & fontBold; }#endifprivate:  GfxFont *gfxFont;#if TEXTOUT_WORD_LIST  GString *fontName;  int flags;#endif  friend class TextWord;  friend class TextPage;};//------------------------------------------------------------------------// TextWord//------------------------------------------------------------------------class TextWord {public:  // Constructor.  TextWord(GfxState *state, int rotA, double x0, double y0,	   int charPosA, TextFontInfo *fontA, double fontSize);  // Destructor.  ~TextWord();  // Add a character to the word.  void addChar(GfxState *state, double x, double y,	       double dx, double dy, Unicode u);  // Merge <word> onto the end of <this>.  void merge(TextWord *word);  // Compares <this> to <word>, returning -1 (<), 0 (=), or +1 (>),  // based on a primary-axis comparison, e.g., x ordering if rot=0.  int primaryCmp(TextWord *word);  // Return the distance along the primary axis between <this> and  // <word>.  double primaryDelta(TextWord *word);  static int cmpYX(const void *p1, const void *p2);  // Get the TextFontInfo object associated with this word.  TextFontInfo *getFontInfo() { return font; }  // Get the next TextWord on the linked list.  TextWord *getNext() { return next; }#if TEXTOUT_WORD_LIST  int getLength() { return len; }  Unicode getChar(int idx) { return text[idx]; }  GString *getText();  GString *getFontName() { return font->fontName; }  void getColor(double *r, double *g, double *b)    { *r = colorR; *g = colorG; *b = colorB; }  void getBBox(double *xMinA, double *yMinA, double *xMaxA, double *yMaxA)    { *xMinA = xMin; *yMinA = yMin; *xMaxA = xMax; *yMaxA = yMax; }  void getCharBBox(int charIdx, double *xMinA, double *yMinA,		   double *xMaxA, double *yMaxA);  double getFontSize() { return fontSize; }  int getRotation() { return rot; }  int getCharPos() { return charPos; }  int getCharLen() { return charLen; }  GBool getSpaceAfter() { return spaceAfter; }#endif  GBool isUnderlined() { return underlined; }  Link *getLink() { return link; }private:  int rot;			// rotation, multiple of 90 degrees				//   (0, 1, 2, or 3)  double xMin, xMax;		// bounding box x coordinates  double yMin, yMax;		// bounding box y coordinates  double base;			// baseline x or y coordinate  Unicode *text;		// the text  double *edge;			// "near" edge x or y coord of each char				//   (plus one extra entry for the last char)  int len;			// length of text and edge arrays  int size;			// size of text and edge arrays  int charPos;                  // character position (within content stream)  int charLen;                  // number of content stream characters in                                //   this word  TextFontInfo *font;		// font information  double fontSize;		// font size  GBool spaceAfter;		// set if there is a space between this				//   word and the next word on the line  TextWord *next;		// next word in line#if TEXTOUT_WORD_LIST  double colorR,		// word color         colorG,         colorB;#endif  GBool underlined;  Link *link;  friend class TextPool;  friend class TextLine;  friend class TextBlock;  friend class TextFlow;  friend class TextWordList;  friend class TextPage;};//------------------------------------------------------------------------// TextPool//------------------------------------------------------------------------class TextPool {public:  TextPool();  ~TextPool();  TextWord *getPool(int baseIdx) { return pool[baseIdx - minBaseIdx]; }  void setPool(int baseIdx, TextWord *p) { pool[baseIdx - minBaseIdx] = p; }  int getBaseIdx(double base);  void addWord(TextWord *word);private:  int minBaseIdx;		// min baseline bucket index  int maxBaseIdx;		// max baseline bucket index  TextWord **pool;		// array of linked lists, one for each				//   baseline value (multiple of 4 pts)  TextWord *cursor;		// pointer to last-accessed word  int cursorBaseIdx;		// baseline bucket index of last-accessed word  friend class TextBlock;  friend class TextPage;};//------------------------------------------------------------------------// TextLine//------------------------------------------------------------------------class TextLine {public:  TextLine(TextBlock *blkA, int rotA, double baseA);  ~TextLine();  void addWord(TextWord *word);  // Return the distance along the primary axis between <this> and  // <line>.  double primaryDelta(TextLine *line);  // Compares <this> to <line>, returning -1 (<), 0 (=), or +1 (>),  // based on a primary-axis comparison, e.g., x ordering if rot=0.  int primaryCmp(TextLine *line);  // Compares <this> to <line>, returning -1 (<), 0 (=), or +1 (>),  // based on a secondary-axis comparison of the baselines, e.g., y  // ordering if rot=0.  int secondaryCmp(TextLine *line);  int cmpYX(TextLine *line);  static int cmpXY(const void *p1, const void *p2);  void coalesce(UnicodeMap *uMap);  // Get the head of the linked list of TextWords.  TextWord *getWords() { return words; }  // Get the next TextLine on the linked list.  TextLine *getNext() { return next; }  // Returns true if the last char of the line is a hyphen.  GBool isHyphenated() { return hyphenated; }private:  TextBlock *blk;		// parent block  int rot;			// text rotation  double xMin, xMax;		// bounding box x coordinates  double yMin, yMax;		// bounding box y coordinates  double base;			// baseline x or y coordinate  TextWord *words;		// words in this line  TextWord *lastWord;		// last word in this line  Unicode *text;		// Unicode text of the line, including				//   spaces between words  double *edge;			// "near" edge x or y coord of each char				//   (plus one extra entry for the last char)  int *col;			// starting column number of each Unicode char  int len;			// number of Unicode chars  int convertedLen;		// total number of converted characters  GBool hyphenated;		// set if last char is a hyphen  TextLine *next;		// next line in block  friend class TextLineFrag;  friend class TextBlock;  friend class TextFlow;  friend class TextWordList;  friend class TextPage;};//------------------------------------------------------------------------// TextBlock//------------------------------------------------------------------------class TextBlock {public:  TextBlock(TextPage *pageA, int rotA);  ~TextBlock();  void addWord(TextWord *word);  void coalesce(UnicodeMap *uMap);  // Update this block's priMin and priMax values, looking at <blk>.  void updatePriMinMax(TextBlock *blk);  static int cmpXYPrimaryRot(const void *p1, const void *p2);  static int cmpYXPrimaryRot(const void *p1, const void *p2);  int primaryCmp(TextBlock *blk);  double secondaryDelta(TextBlock *blk);  // Returns true if <this> is below <blk>, relative to the page's  // primary rotation.  GBool isBelow(TextBlock *blk);  // Get the head of the linked list of TextLines.  TextLine *getLines() { return lines; }  // Get the next TextBlock on the linked list.  TextBlock *getNext() { return next; }private:  TextPage *page;		// the parent page  int rot;			// text rotation  double xMin, xMax;		// bounding box x coordinates  double yMin, yMax;		// bounding box y coordinates  double priMin, priMax;	// whitespace bounding box along primary axis  TextPool *pool;		// pool of words (used only until lines				//   are built)  TextLine *lines;		// linked list of lines  TextLine *curLine;		// most recently added line  int nLines;			// number of lines  int charCount;		// number of characters in the block  int col;			// starting column  int nColumns;			// number of columns in the block  TextBlock *next;  TextBlock *stackNext;  friend class TextLine;  friend class TextLineFrag;  friend class TextFlow;  friend class TextWordList;  friend class TextPage;};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -