File indexing completed on 2026-05-03 14:21:41
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2002 Dirk Schönberger <dirk.schoenberger@sz-online.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef PSCOMMENTLEXER_H 0008 #define PSCOMMENTLEXER_H 0009 0010 #include <QIODevice> 0011 #include <QString> 0012 0013 /** 0014 *@author Dirk Schönberger 0015 */ 0016 typedef enum { 0017 State_Comment = 0, 0018 State_CommentEncodedChar, 0019 State_Start 0020 } State; 0021 0022 typedef enum { 0023 Action_Copy = 1, 0024 Action_CopyOutput, 0025 Action_Output, 0026 Action_Ignore, 0027 Action_Abort, 0028 Action_OutputUnget, 0029 Action_InitTemp, 0030 Action_CopyTemp, 0031 Action_DecodeUnget, 0032 Action_ByteArraySpecial 0033 } Action; 0034 0035 // TODO: Looks like this class is duplicated in ailexer.h 0036 class StringBuffer 0037 { 0038 public: 0039 StringBuffer(); 0040 virtual ~StringBuffer(); 0041 0042 void append(char c); 0043 void clear(); 0044 QString toString() const; 0045 uint length() const; 0046 double toFloat(); 0047 int toInt(); 0048 const char *toLatin1() const; 0049 QString mid(uint index, uint len = 0xffffffff) const; 0050 private: 0051 char *m_buffer; 0052 uint m_length; 0053 int m_capacity; 0054 0055 void ensureCapacity(int p_capacity); 0056 }; 0057 0058 class PSCommentLexer 0059 { 0060 public: 0061 PSCommentLexer(); 0062 virtual ~PSCommentLexer(); 0063 0064 virtual bool parse(QIODevice& fin); 0065 private: 0066 State m_curState; 0067 StringBuffer m_buffer; 0068 StringBuffer m_temp; 0069 0070 void nextStep(char c, State* newState, Action* newAction); 0071 0072 void doOutput(); 0073 uchar decode(); 0074 0075 protected: 0076 virtual void parsingStarted(); 0077 virtual void parsingFinished(); 0078 virtual void parsingAborted(); 0079 0080 virtual void gotComment(const char *value); 0081 }; 0082 0083 class BoundingBoxExtractor : public PSCommentLexer 0084 { 0085 public: 0086 BoundingBoxExtractor(); 0087 ~BoundingBoxExtractor() override; 0088 0089 int llx() const { 0090 return m_llx; 0091 } 0092 int lly() const { 0093 return m_lly; 0094 } 0095 int urx() const { 0096 return m_urx; 0097 } 0098 int ury() const { 0099 return m_ury; 0100 } 0101 private: 0102 int m_llx, m_lly, m_urx, m_ury; 0103 bool getRectangle(const char* input, int &llx, int &lly, int &urx, int &ury); 0104 0105 protected: 0106 void gotComment(const char *value) override; 0107 }; 0108 0109 #endif 0110