qscilexerpostscript.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. // This module implements the QsciLexerPostScript class.
  2. //
  3. // Copyright (c) 2017 Riverbank Computing Limited <info@riverbankcomputing.com>
  4. //
  5. // This file is part of QScintilla.
  6. //
  7. // This file may be used under the terms of the GNU General Public License
  8. // version 3.0 as published by the Free Software Foundation and appearing in
  9. // the file LICENSE included in the packaging of this file. Please review the
  10. // following information to ensure the GNU General Public License version 3.0
  11. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  12. //
  13. // If you do not wish to use this file under the terms of the GPL version 3.0
  14. // then you may purchase a commercial license. For more information contact
  15. // info@riverbankcomputing.com.
  16. //
  17. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  18. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19. #include "Qsci/qscilexerpostscript.h"
  20. #include <qcolor.h>
  21. #include <qfont.h>
  22. #include <qsettings.h>
  23. // The ctor.
  24. QsciLexerPostScript::QsciLexerPostScript(QObject *parent)
  25. : QsciLexer(parent),
  26. ps_tokenize(false), ps_level(3), fold_compact(true), fold_atelse(false)
  27. {
  28. }
  29. // The dtor.
  30. QsciLexerPostScript::~QsciLexerPostScript()
  31. {
  32. }
  33. // Returns the language name.
  34. const char *QsciLexerPostScript::language() const
  35. {
  36. return "PostScript";
  37. }
  38. // Returns the lexer name.
  39. const char *QsciLexerPostScript::lexer() const
  40. {
  41. return "ps";
  42. }
  43. // Return the style used for braces.
  44. int QsciLexerPostScript::braceStyle() const
  45. {
  46. return ProcedureParenthesis;
  47. }
  48. // Returns the foreground colour of the text for a style.
  49. QColor QsciLexerPostScript::defaultColor(int style) const
  50. {
  51. switch (style)
  52. {
  53. case Comment:
  54. return QColor(0x00,0x7f,0x00);
  55. case DSCComment:
  56. return QColor(0x3f,0x70,0x3f);
  57. case DSCCommentValue:
  58. case DictionaryParenthesis:
  59. return QColor(0x30,0x60,0xa0);
  60. case Number:
  61. return QColor(0x00,0x7f,0x7f);
  62. case Name:
  63. case ProcedureParenthesis:
  64. return QColor(0x00,0x00,0x00);
  65. case Keyword:
  66. case ArrayParenthesis:
  67. return QColor(0x00,0x00,0x7f);
  68. case Literal:
  69. case ImmediateEvalLiteral:
  70. return QColor(0x7f,0x7f,0x00);
  71. case Text:
  72. case Base85String:
  73. return QColor(0x7f,0x00,0x7f);
  74. case HexString:
  75. return QColor(0x3f,0x7f,0x3f);
  76. case BadStringCharacter:
  77. return QColor(0xff,0xff,0x00);
  78. }
  79. return QsciLexer::defaultColor(style);
  80. }
  81. // Returns the font of the text for a style.
  82. QFont QsciLexerPostScript::defaultFont(int style) const
  83. {
  84. QFont f;
  85. switch (style)
  86. {
  87. case Comment:
  88. case DSCComment:
  89. case DSCCommentValue:
  90. #if defined(Q_OS_WIN)
  91. f = QFont("Comic Sans MS",9);
  92. #elif defined(Q_OS_MAC)
  93. f = QFont("Comic Sans MS", 12);
  94. #else
  95. f = QFont("Bitstream Vera Serif",9);
  96. #endif
  97. break;
  98. case Keyword:
  99. case ProcedureParenthesis:
  100. f = QsciLexer::defaultFont(style);
  101. f.setBold(true);
  102. case Text:
  103. #if defined(Q_OS_WIN)
  104. f = QFont("Times New Roman", 11);
  105. #elif defined(Q_OS_MAC)
  106. f = QFont("Times New Roman", 12);
  107. #else
  108. f = QFont("Bitstream Charter", 10);
  109. #endif
  110. break;
  111. default:
  112. f = QsciLexer::defaultFont(style);
  113. }
  114. return f;
  115. }
  116. // Returns the set of keywords.
  117. const char *QsciLexerPostScript::keywords(int set) const
  118. {
  119. if (set == 1)
  120. return
  121. "$error = == FontDirectory StandardEncoding UserObjects abs add "
  122. "aload anchorsearch and arc arcn arcto array ashow astore atan "
  123. "awidthshow begin bind bitshift bytesavailable cachestatus "
  124. "ceiling charpath clear cleardictstack cleartomark clip clippath "
  125. "closefile closepath concat concatmatrix copy copypage cos count "
  126. "countdictstack countexecstack counttomark currentcmykcolor "
  127. "currentcolorspace currentdash currentdict currentfile "
  128. "currentflat currentfont currentgray currenthsbcolor "
  129. "currentlinecap currentlinejoin currentlinewidth currentmatrix "
  130. "currentmiterlimit currentpagedevice currentpoint currentrgbcolor "
  131. "currentscreen currenttransfer cvi cvlit cvn cvr cvrs cvs cvx def "
  132. "defaultmatrix definefont dict dictstack div dtransform dup echo "
  133. "end eoclip eofill eq erasepage errordict exch exec execstack "
  134. "executeonly executive exit exp false file fill findfont "
  135. "flattenpath floor flush flushfile for forall ge get getinterval "
  136. "grestore grestoreall gsave gt idetmatrix idiv idtransform if "
  137. "ifelse image imagemask index initclip initgraphics initmatrix "
  138. "inustroke invertmatrix itransform known kshow le length lineto "
  139. "ln load log loop lt makefont mark matrix maxlength mod moveto "
  140. "mul ne neg newpath noaccess nor not null nulldevice or pathbbox "
  141. "pathforall pop print prompt pstack put putinterval quit rand "
  142. "rcheck rcurveto read readhexstring readline readonly readstring "
  143. "rectstroke repeat resetfile restore reversepath rlineto rmoveto "
  144. "roll rotate round rrand run save scale scalefont search "
  145. "setblackgeneration setcachedevice setcachelimit setcharwidth "
  146. "setcolorscreen setcolortransfer setdash setflat setfont setgray "
  147. "sethsbcolor setlinecap setlinejoin setlinewidth setmatrix "
  148. "setmiterlimit setpagedevice setrgbcolor setscreen settransfer "
  149. "setvmthreshold show showpage sin sqrt srand stack start status "
  150. "statusdict stop stopped store string stringwidth stroke "
  151. "strokepath sub systemdict token token transform translate true "
  152. "truncate type ueofill undefineresource userdict usertime version "
  153. "vmstatus wcheck where widthshow write writehexstring writestring "
  154. "xcheck xor";
  155. if (set == 2)
  156. return
  157. "GlobalFontDirectory ISOLatin1Encoding SharedFontDirectory "
  158. "UserObject arct colorimage cshow currentblackgeneration "
  159. "currentcacheparams currentcmykcolor currentcolor "
  160. "currentcolorrendering currentcolorscreen currentcolorspace "
  161. "currentcolortransfer currentdevparams currentglobal "
  162. "currentgstate currenthalftone currentobjectformat "
  163. "currentoverprint currentpacking currentpagedevice currentshared "
  164. "currentstrokeadjust currentsystemparams currentundercolorremoval "
  165. "currentuserparams defineresource defineuserobject deletefile "
  166. "execform execuserobject filenameforall fileposition filter "
  167. "findencoding findresource gcheck globaldict glyphshow gstate "
  168. "ineofill infill instroke inueofill inufill inustroke "
  169. "languagelevel makepattern packedarray printobject product "
  170. "realtime rectclip rectfill rectstroke renamefile resourceforall "
  171. "resourcestatus revision rootfont scheck selectfont serialnumber "
  172. "setbbox setblackgeneration setcachedevice2 setcacheparams "
  173. "setcmykcolor setcolor setcolorrendering setcolorscreen "
  174. "setcolorspace setcolortranfer setdevparams setfileposition "
  175. "setglobal setgstate sethalftone setobjectformat setoverprint "
  176. "setpacking setpagedevice setpattern setshared setstrokeadjust "
  177. "setsystemparams setucacheparams setundercolorremoval "
  178. "setuserparams setvmthreshold shareddict startjob uappend ucache "
  179. "ucachestatus ueofill ufill undef undefinefont undefineresource "
  180. "undefineuserobject upath ustroke ustrokepath vmreclaim "
  181. "writeobject xshow xyshow yshow";
  182. if (set == 3)
  183. return
  184. "cliprestore clipsave composefont currentsmoothness "
  185. "findcolorrendering setsmoothness shfill";
  186. if (set == 4)
  187. return
  188. ".begintransparencygroup .begintransparencymask .bytestring "
  189. ".charboxpath .currentaccuratecurves .currentblendmode "
  190. ".currentcurvejoin .currentdashadapt .currentdotlength "
  191. ".currentfilladjust2 .currentlimitclamp .currentopacityalpha "
  192. ".currentoverprintmode .currentrasterop .currentshapealpha "
  193. ".currentsourcetransparent .currenttextknockout "
  194. ".currenttexturetransparent .dashpath .dicttomark "
  195. ".discardtransparencygroup .discardtransparencymask "
  196. ".endtransparencygroup .endtransparencymask .execn .filename "
  197. ".filename .fileposition .forceput .forceundef .forgetsave "
  198. ".getbitsrect .getdevice .inittransparencymask .knownget "
  199. ".locksafe .makeoperator .namestring .oserrno .oserrorstring "
  200. ".peekstring .rectappend .runandhide .setaccuratecurves "
  201. ".setblendmode .setcurvejoin .setdashadapt .setdebug "
  202. ".setdefaultmatrix .setdotlength .setfilladjust2 .setlimitclamp "
  203. ".setmaxlength .setopacityalpha .setoverprintmode .setrasterop "
  204. ".setsafe .setshapealpha .setsourcetransparent .settextknockout "
  205. ".settexturetransparent .stringbreak .stringmatch .tempfile "
  206. ".type1decrypt .type1encrypt .type1execchar .unread arccos "
  207. "arcsin copydevice copyscanlines currentdevice finddevice "
  208. "findlibfile findprotodevice flushpage getdeviceprops getenv "
  209. "makeimagedevice makewordimagedevice max min putdeviceprops "
  210. "setdevice";
  211. return 0;
  212. }
  213. // Returns the user name of a style.
  214. QString QsciLexerPostScript::description(int style) const
  215. {
  216. switch (style)
  217. {
  218. case Default:
  219. return tr("Default");
  220. case Comment:
  221. return tr("Comment");
  222. case DSCComment:
  223. return tr("DSC comment");
  224. case DSCCommentValue:
  225. return tr("DSC comment value");
  226. case Number:
  227. return tr("Number");
  228. case Name:
  229. return tr("Name");
  230. case Keyword:
  231. return tr("Keyword");
  232. case Literal:
  233. return tr("Literal");
  234. case ImmediateEvalLiteral:
  235. return tr("Immediately evaluated literal");
  236. case ArrayParenthesis:
  237. return tr("Array parenthesis");
  238. case DictionaryParenthesis:
  239. return tr("Dictionary parenthesis");
  240. case ProcedureParenthesis:
  241. return tr("Procedure parenthesis");
  242. case Text:
  243. return tr("Text");
  244. case HexString:
  245. return tr("Hexadecimal string");
  246. case Base85String:
  247. return tr("Base85 string");
  248. case BadStringCharacter:
  249. return tr("Bad string character");
  250. }
  251. return QString();
  252. }
  253. // Returns the background colour of the text for a style.
  254. QColor QsciLexerPostScript::defaultPaper(int style) const
  255. {
  256. if (style == BadStringCharacter)
  257. return QColor(0xff,0x00,0x00);
  258. return QsciLexer::defaultPaper(style);
  259. }
  260. // Refresh all properties.
  261. void QsciLexerPostScript::refreshProperties()
  262. {
  263. setTokenizeProp();
  264. setLevelProp();
  265. setCompactProp();
  266. setAtElseProp();
  267. }
  268. // Read properties from the settings.
  269. bool QsciLexerPostScript::readProperties(QSettings &qs,const QString &prefix)
  270. {
  271. int rc = true;
  272. ps_tokenize = qs.value(prefix + "pstokenize", false).toBool();
  273. ps_level = qs.value(prefix + "pslevel", 3).toInt();
  274. fold_compact = qs.value(prefix + "foldcompact", true).toBool();
  275. fold_atelse = qs.value(prefix + "foldatelse", false).toBool();
  276. return rc;
  277. }
  278. // Write properties to the settings.
  279. bool QsciLexerPostScript::writeProperties(QSettings &qs,const QString &prefix) const
  280. {
  281. int rc = true;
  282. qs.setValue(prefix + "pstokenize", ps_tokenize);
  283. qs.setValue(prefix + "pslevel", ps_level);
  284. qs.setValue(prefix + "foldcompact", fold_compact);
  285. qs.setValue(prefix + "foldatelse", fold_atelse);
  286. return rc;
  287. }
  288. // Return true if tokens are marked.
  289. bool QsciLexerPostScript::tokenize() const
  290. {
  291. return ps_tokenize;
  292. }
  293. // Set if tokens are marked.
  294. void QsciLexerPostScript::setTokenize(bool tokenize)
  295. {
  296. ps_tokenize = tokenize;
  297. setTokenizeProp();
  298. }
  299. // Set the "ps.tokenize" property.
  300. void QsciLexerPostScript::setTokenizeProp()
  301. {
  302. emit propertyChanged("ps.tokenize",(ps_tokenize ? "1" : "0"));
  303. }
  304. // Return the PostScript level.
  305. int QsciLexerPostScript::level() const
  306. {
  307. return ps_level;
  308. }
  309. // Set the PostScript level.
  310. void QsciLexerPostScript::setLevel(int level)
  311. {
  312. ps_level = level;
  313. setLevelProp();
  314. }
  315. // Set the "ps.level" property.
  316. void QsciLexerPostScript::setLevelProp()
  317. {
  318. emit propertyChanged("ps.level", QByteArray::number(ps_level));
  319. }
  320. // Return true if folds are compact.
  321. bool QsciLexerPostScript::foldCompact() const
  322. {
  323. return fold_compact;
  324. }
  325. // Set if folds are compact
  326. void QsciLexerPostScript::setFoldCompact(bool fold)
  327. {
  328. fold_compact = fold;
  329. setCompactProp();
  330. }
  331. // Set the "fold.compact" property.
  332. void QsciLexerPostScript::setCompactProp()
  333. {
  334. emit propertyChanged("fold.compact",(fold_compact ? "1" : "0"));
  335. }
  336. // Return true if else blocks can be folded.
  337. bool QsciLexerPostScript::foldAtElse() const
  338. {
  339. return fold_atelse;
  340. }
  341. // Set if else blocks can be folded.
  342. void QsciLexerPostScript::setFoldAtElse(bool fold)
  343. {
  344. fold_atelse = fold;
  345. setAtElseProp();
  346. }
  347. // Set the "fold.at.else" property.
  348. void QsciLexerPostScript::setAtElseProp()
  349. {
  350. emit propertyChanged("fold.at.else",(fold_atelse ? "1" : "0"));
  351. }