fppdfcommands.pp 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056
  1. {$IFNDEF FPC_DOTTEDUNITS}
  2. unit fppdfcommands;
  3. {$ENDIF}
  4. {$mode ObjFPC}{$H+}
  5. interface
  6. uses
  7. {$IFDEF FPC_DOTTEDUNITS}
  8. System.Classes, System.SysUtils, FpPdf.Consts, System.Types, FpPdf.Objects;
  9. {$ELSE}
  10. Classes, SysUtils, fppdfconsts, types, fppdfobjects;
  11. {$ENDIF}
  12. Type
  13. { ----------------------------------------------------------------------
  14. General types, to be used as parents for specific commands
  15. ----------------------------------------------------------------------}
  16. // Do not register these classes !!
  17. { TPDFBTCommand }
  18. TPDFTextStateCommand = class(TPDFCommand)
  19. class function CommandType : TPDFCommandType; override;
  20. end;
  21. { TPDFGraphicStateCommand }
  22. TPDFGraphicStateCommand = class(TPDFCommand)
  23. class function CommandType : TPDFCommandType; override;
  24. end;
  25. { TPDFNameCommand }
  26. TPDFNameCommand = class(TPDFCommand)
  27. protected
  28. function GetValue: String;
  29. Public
  30. Property Name : String Read GetValue;
  31. end;
  32. { TPDFMarkedContentCommand }
  33. TPDFMarkedContentCommand = class(TPDFNameCommand)
  34. Public
  35. Class function CommandType: TPDFCommandType; override;
  36. Property Tag : String Read GetValue;
  37. end;
  38. { TPDFTextCommand }
  39. TPDFTextCommand = Class(TPDFCommand)
  40. Public
  41. class function CommandType : TPDFCommandType; override;
  42. Function GetFullText(aUnicodeMap : TPDFCMap) : RawByteString; virtual; overload;
  43. Function GetFullText : RawByteString; virtual; abstract; overload;
  44. end;
  45. // Some parents that allow easy access to the arguments
  46. { TPDFNumberCommand }
  47. TPDFNumberCommand = class(TPDFCommand)
  48. private
  49. function GetAsArray: TSingleDynArray;
  50. function GetValues(Index: Integer): Single;
  51. protected
  52. function GetValue: Single;
  53. Public
  54. Property Value : Single Read GetValue;
  55. Property Values[Index: Integer] : Single Read GetValues;
  56. Property AsArray : TSingleDynArray Read GetAsArray;
  57. end;
  58. { TPDFIntegerNumberCommand }
  59. TPDFIntegerNumberCommand = class(TPDFCommand)
  60. protected
  61. function GetValue: Integer;
  62. Public
  63. Property Value : Integer Read GetValue;
  64. end;
  65. { TPDFStringCommand }
  66. TPDFStringCommand = class(TPDFCommand)
  67. protected
  68. function GetValue: String;
  69. Public
  70. Property Value : String Read GetValue;
  71. end;
  72. { Transformation matrix :
  73. [ a b 0 ] [ hscale skew1 0]
  74. [ c d 0 ] [ skew2 vscale 0]
  75. [ e f 1 ] [ hoff voff 1]
  76. }
  77. { TPDFTransformCommand }
  78. TPDFTransformCommand = class(TPDFCommand)
  79. private
  80. function GetMatrixPos(aIndex: Integer): double;
  81. function GetTransFormation: TPDFTransFormation;
  82. public
  83. property a : double Index 0 Read GetMatrixPos; // Horz scale
  84. property b : double Index 1 Read GetMatrixPos; // Skew 1
  85. property c : double Index 2 Read GetMatrixPos; // Skew 2
  86. property d : double Index 3 Read GetMatrixPos; // Vert scale
  87. property e : double Index 4 Read GetMatrixPos; // Horz offset
  88. property f : double Index 5 Read GetMatrixPos; // Vert offset
  89. Property TransFormation : TPDFTransFormation read GetTransFormation;
  90. end;
  91. { TPDFTranslateCommand }
  92. TPDFTranslateCommand = class(TPDFCommand)
  93. private
  94. function GetPos(AIndex: Integer): double;
  95. public
  96. property x : double Index 0 Read GetPos;
  97. property y : double Index 1 Read GetPos;
  98. end;
  99. { TPDFDrawcommand }
  100. TPDFDrawcommand = class(TPDFCommand)
  101. class function CommandType : TPDFCommandType; override;
  102. end;
  103. { TPDFPointcommand }
  104. TPDFPointcommand = class(TPDFDrawcommand)
  105. protected
  106. function GetCoord(AIndex: Integer): Single;
  107. function GetPoint(AIndex: Integer): TPDFPoint;
  108. end;
  109. TPDFOnePointcommand = class(TPDFPointCommand)
  110. protected
  111. Public
  112. property X : Single Index 0 Read GetCoord;
  113. property Y : Single Index 1 Read GetCoord;
  114. Property AsPoint : TPDFPoint Index 0 Read GetPoint;
  115. end;
  116. TPDFTwoPointscommand = class(TPDFPointCommand)
  117. Public
  118. property X1 : Single Index 0 Read GetCoord;
  119. property Y1 : Single Index 1 Read GetCoord;
  120. property X2 : Single Index 2 Read GetCoord;
  121. property Y2 : Single Index 3 Read GetCoord;
  122. Property Point1 : TPDFPoint Index 0 Read GetPoint;
  123. Property Point2 : TPDFPoint Index 1 Read GetPoint;
  124. end;
  125. { TPDFThreePointscommand }
  126. TPDFThreePointscommand = class(TPDFTwoPointsCommand)
  127. Public
  128. property X3 : Single Index 4 Read GetCoord;
  129. property Y3 : Single Index 5 Read GetCoord;
  130. Property Point3 : TPDFPoint Index 2 Read GetPoint;
  131. end;
  132. { TPDFStrokeCommand }
  133. TPDFStrokeCommand = class(TPDFCommand)
  134. class function CommandType : TPDFCommandType; override;
  135. class Function StrokeOptions : TPDFStrokeOptions; virtual; abstract;
  136. end;
  137. { ----------------------------------------------------------------------
  138. Other commands
  139. ----------------------------------------------------------------------}
  140. { TPDFBXCommand }
  141. // begin compatibility section
  142. TPDFBXCommand = class(TPDFCommand)
  143. Class Function RegisterCommandName : String;override;
  144. end;
  145. { TPDFEXCommand }
  146. // end compatibility section
  147. TPDFEXCommand = class(TPDFCommand)
  148. Class Function RegisterCommandName : String; override;
  149. end;
  150. { TPDFTextStateCommand }
  151. // begin text
  152. TPDFBTCommand = class(TPDFTextStateCommand)
  153. Class Function RegisterCommandName : String;override;
  154. end;
  155. { TPDFETCommand }
  156. // end text
  157. TPDFETCommand = class(TPDFTextStateCommand)
  158. Class Function RegisterCommandName : String; override;
  159. end;
  160. { TPDFBDCCommand }
  161. // Begin Marked Content with properties
  162. TPDFBDCCommand = class(TPDFMarkedContentCommand)
  163. Class Function RegisterCommandName : String;override;
  164. end;
  165. { TPDFBMCCommand }
  166. // Begin Marked Content
  167. TPDFBMCCommand = class(TPDFMarkedContentCommand)
  168. Class Function RegisterCommandName : String;override;
  169. end;
  170. { TPDFEMCCommand }
  171. // End Marked Content
  172. TPDFEMCCommand = class(TPDFMarkedContentCommand)
  173. Class Function RegisterCommandName : String; override;
  174. end;
  175. { TPDFMPCommand }
  176. // Marked content Point
  177. TPDFMPCommand = class(TPDFMarkedContentCommand)
  178. Class Function RegisterCommandName : String; override;
  179. end;
  180. { TPDFDPCommand }
  181. // Marked content Point with properties
  182. TPDFDPCommand = class(TPDFMarkedContentCommand)
  183. Class Function RegisterCommandName : String; override;
  184. end;
  185. { TPDFDoCommand }
  186. // Invoke named object
  187. TPDFDoCommand = class(TPDFCommand)
  188. Class Function RegisterCommandName : String;override;
  189. end;
  190. { ----------------------------------------------------------------------
  191. Graphics state
  192. ----------------------------------------------------------------------}
  193. { TPDFcmCommand }
  194. // concat CMT matrix
  195. TPDFcmCommand = class(TPDFGraphicStateCommand)
  196. Class Function RegisterCommandName : String;override;
  197. end;
  198. { TPDFcm_Command }
  199. // set current transformation matrix
  200. TPDFcm_Command = class(TPDFTransformCommand)
  201. Class Function RegisterCommandName : String; override;
  202. class function CommandType : TPDFCommandType; override;
  203. end;
  204. { TPDFq_Command }
  205. // Push graphics drawing state
  206. TPDFq_Command = class(TPDFGraphicStateCommand)
  207. Class Function RegisterCommandName : String; override;
  208. end;
  209. { TPDFQCommand }
  210. // Pop graphics drawing state
  211. TPDFQCommand = class(TPDFGraphicStateCommand)
  212. Class Function RegisterCommandName : String; override;
  213. end;
  214. { TPDFw_Command }
  215. // Set line width
  216. TPDFw_Command = class(TPDFNumberCommand)
  217. public
  218. class function CommandType : TPDFCommandType; override;
  219. Class Function RegisterCommandName : String; override;
  220. Property LineWidth : Single Read GetValue;
  221. end;
  222. { TPDFJCommand }
  223. // Set line cap
  224. TPDFJCommand = class(TPDFintegerNumberCommand)
  225. private
  226. function GetLineCap: TPDFLineCapStyle;
  227. public
  228. class function CommandType : TPDFCommandType; override;
  229. Class Function RegisterCommandName : String; override;
  230. Property LineCap : TPDFLineCapStyle Read GetLineCap;
  231. end;
  232. { TPDFj_Command }
  233. // Set line join
  234. TPDFj_Command = class(TPDFintegerNumberCommand)
  235. private
  236. function GetLineJoin: TPDFLineJoinStyle;
  237. public
  238. class function CommandType : TPDFCommandType; override;
  239. Class Function RegisterCommandName : String; override;
  240. Property LineJoin : TPDFLineJoinStyle Read GetLineJoin;
  241. end;
  242. { TPDFMCommand }
  243. // Set Miter limit
  244. TPDFMCommand = class(TPDFNumberCommand)
  245. public
  246. class function CommandType : TPDFCommandType; override;
  247. Class Function RegisterCommandName : String; override;
  248. Property MiterLimit : Single Read GetValue;
  249. end;
  250. { TPDFd_Command }
  251. // Set dash style
  252. TPDFd_Command = class(TPDFCommand)
  253. private
  254. function GetDash: TPDFDashPattern;
  255. function GetPattern: TIntegerDynArray;
  256. function GetPhase: Integer;
  257. public
  258. class function CommandType : TPDFCommandType; override;
  259. Class Function RegisterCommandName : String; override;
  260. Property Pattern : TIntegerDynArray Read GetPattern;
  261. Property Phase : Integer Read GetPhase;
  262. Property AsDash : TPDFDashPattern Read GetDash;
  263. end;
  264. { TPDFi_Command }
  265. // set flatness limit
  266. TPDFi_Command = class(TPDFintegerNumberCommand)
  267. public
  268. class function CommandType : TPDFCommandType; override;
  269. Class Function RegisterCommandName : String; override;
  270. Property Flatness : Integer Read GetValue;
  271. end;
  272. { TPDFri_Command }
  273. // Set color rendering intent
  274. TPDFri_Command = class(TPDFStringCommand)
  275. public
  276. class function CommandType : TPDFCommandType; override;
  277. Class Function RegisterCommandName : String; override;
  278. Property Intent : string Read GetValue;
  279. end;
  280. { TPDFgs_Command }
  281. // Set graphics state from dictionary
  282. TPDFgs_Command = class(TPDFNameCommand)
  283. public
  284. class function CommandType: TPDFCommandType; override;
  285. Class Function RegisterCommandName : String; override;
  286. Property DictName : string Read GetValue;
  287. end;
  288. { ----------------------------------------------------------------------
  289. Color commands
  290. ----------------------------------------------------------------------}
  291. { TPDFCSCommand }
  292. // Set stroke color space
  293. TPDFCSCommand = class(TPDFNameCommand)
  294. class function CommandType: TPDFCommandType; override;
  295. Class Function RegisterCommandName : String; override;
  296. function ColorSpace : TPDFColorSpace;
  297. end;
  298. // Set fill color space
  299. { TPDFcs_Command }
  300. TPDFcs_Command = class(TPDFNameCommand)
  301. class function CommandType: TPDFCommandType; override;
  302. Class Function RegisterCommandName : String; override;
  303. function ColorSpace : TPDFColorSpace;
  304. end;
  305. { TPDFSCCommand }
  306. // Set stroke color
  307. TPDFSCCommand = class(TPDFNumberCommand)
  308. class function CommandType: TPDFCommandType; override;
  309. Class Function RegisterCommandName : String; override;
  310. end;
  311. { TPDFsc_Command }
  312. // Set non-stroke color
  313. TPDFsc_Command = class(TPDFNumberCommand)
  314. class function CommandType: TPDFCommandType; override;
  315. Class Function RegisterCommandName : String; override;
  316. end;
  317. { TPDFSCNCommand }
  318. { TPDFColorNamespaceCommand }
  319. TPDFColorNamespaceCommand = class(TPDFCommand)
  320. private
  321. function GetAsArray: TSingleDynArray;
  322. function HasName : Boolean;
  323. Public
  324. class function CommandType: TPDFCommandType; override;
  325. Function ColorSpaceName : String;
  326. Property AsArray : TSingleDynArray Read GetAsArray;
  327. end;
  328. TPDFSCNCommand = class(TPDFColorNamespaceCommand)
  329. Class Function RegisterCommandName : String; override;
  330. end;
  331. { TPDFscn_Command }
  332. TPDFscn_Command = class(TPDFColorNamespaceCommand)
  333. Class Function RegisterCommandName : String; override;
  334. end;
  335. { TPDFscn_Command }
  336. // Set devicegray and gray level for stroke operations
  337. { TPDFGCommand }
  338. TPDFGCommand = class(TPDFNumberCommand)
  339. private
  340. function GetColor: TPDFColor;
  341. public
  342. class function CommandType: TPDFCommandType; override;
  343. Class Function RegisterCommandName : String; override;
  344. property gray : single Read GetValue;
  345. function ColorSpace : TPDFColorSpace;
  346. property AsColor : TPDFColor Read GetColor;
  347. end;
  348. // Set devicegray and gray level for non-stroke operations
  349. { TPDFg_Command }
  350. TPDFg_Command = class(TPDFNumberCommand)
  351. private
  352. function GetColor: TPDFColor;
  353. public
  354. class function CommandType: TPDFCommandType; override;
  355. Class Function RegisterCommandName : String; override;
  356. property gray : single Read GetValue;
  357. function ColorSpace : TPDFColorSpace;
  358. property AsColor : TPDFColor Read GetColor;
  359. end;
  360. { TPDFRGBCommand }
  361. // Set deviceRGB color space and color - parent
  362. TPDFRGBCommand = class(TPDFNumberCommand)
  363. private
  364. function GetColor: TPDFColor;
  365. Public
  366. class function CommandType: TPDFCommandType; override;
  367. function ColorSpace : TPDFColorSpace;
  368. property R : single read GetValue;
  369. property G : single index 1 read GetValues;
  370. property B : single index 2 read GetValues;
  371. Property AsColor : TPDFColor Read GetColor;
  372. end;
  373. { TPDFRGCommand }
  374. // Set deviceRGB color space and color for stroke operations
  375. TPDFRGCommand = class(TPDFRGBCommand)
  376. Class Function RegisterCommandName : String; override;
  377. end;
  378. { TPDFrg_Command }
  379. // Set deviceRGB color space and color for non-stroke operations
  380. TPDFrg_Command = class(TPDFRGBCommand)
  381. Class Function RegisterCommandName : String; override;
  382. end;
  383. { TPDFCMYKCommand }
  384. // Select CMYK color space and color - parent
  385. TPDFCMYKCommand = class(TPDFNumberCommand)
  386. private
  387. function GetAsColor: TPDFColor;
  388. Public
  389. class function CommandType: TPDFCommandType; override;
  390. function ColorSpace : TPDFColorSpace;
  391. property C : single read GetValue;
  392. property M : single index 1 read GetValues;
  393. property Y : single index 2 read GetValues;
  394. property K : single index 3 read GetValues;
  395. property AsColor : TPDFColor Read GetAsColor;
  396. end;
  397. { TPDFKCommand }
  398. // Set stroke color in CMYK color space
  399. TPDFKCommand = class(TPDFCMYKCommand)
  400. Class Function RegisterCommandName : String; override;
  401. end;
  402. { TPDFk_Command }
  403. // Set non-stroke color in CMYK color space
  404. TPDFk_Command = class(TPDFCMYKCommand)
  405. Class Function RegisterCommandName : String; override;
  406. end;
  407. { ----------------------------------------------------------------------
  408. Text drawing
  409. ----------------------------------------------------------------------}
  410. { TPDFTJCommand }
  411. // Draw text segments
  412. TPDFTJCommand = class(TPDFTextCommand)
  413. Class Function RegisterCommandName : String; override;
  414. Function GetFullText(aUnicodeMap : TPDFCMap) : RawByteString; override; overload;
  415. Function GetFullText : RawByteString; override;
  416. end;
  417. { TPDFTj_Command }
  418. // Draw text
  419. TPDFTj_Command = class(TPDFTextCommand)
  420. Class Function RegisterCommandName : String; override;
  421. Function GetFullText : RawByteString; override;
  422. end;
  423. { ----------------------------------------------------------------------
  424. Text state commands
  425. ----------------------------------------------------------------------}
  426. { TPDFTf_Command }
  427. // Set font
  428. TPDFTf_Command = class(TPDFTextStateCommand)
  429. private
  430. function GetFontName: String;
  431. function GetFontSize: Integer;
  432. public
  433. Class Function RegisterCommandName : String; override;
  434. property FontName : String Read GetFontName;
  435. Property FontSize : Integer Read GetFontSize;
  436. end;
  437. { TPDFTm_Command }
  438. // Set text matrix
  439. TPDFTm_Command = class(TPDFTransformCommand)
  440. class function CommandType : TPDFCommandType; override;
  441. Class Function RegisterCommandName : String; override;
  442. end;
  443. { TPDFTAsterixCommand }
  444. // Move to start of next line
  445. TPDFTAsterixCommand = class(TPDFTransformCommand)
  446. class function CommandType : TPDFCommandType; override;
  447. Class Function RegisterCommandName : String; override;
  448. end;
  449. { TPDFTc_Command }
  450. // set text character spacing
  451. TPDFTc_Command = class(TPDFNumberCommand)
  452. class function CommandType : TPDFCommandType; override;
  453. Class Function RegisterCommandName : String; override;
  454. end;
  455. { TPDFTw_Command }
  456. // Set text word spacing
  457. TPDFTw_Command = class(TPDFNumberCommand)
  458. class function CommandType : TPDFCommandType; override;
  459. Class Function RegisterCommandName : String; override;
  460. end;
  461. { TPDFTz_Command }
  462. // set text horizontal scaling
  463. TPDFTz_Command = class(TPDFNumberCommand)
  464. class function CommandType : TPDFCommandType; override;
  465. Class Function RegisterCommandName : String; override;
  466. end;
  467. { TPDFTLCommand }
  468. // Set text leading
  469. TPDFTLCommand = class(TPDFNumberCommand)
  470. class function CommandType : TPDFCommandType; override;
  471. Class Function RegisterCommandName : String; override;
  472. end;
  473. { TPDFTr_Command }
  474. // set text rendering mode
  475. TPDFTr_Command = class(TPDFIntegerNumberCommand)
  476. class Function CommandType: TPDFCommandType; override;
  477. Class Function RegisterCommandName : String; override;
  478. Function RenderMode : TPDFTextRenderMode;
  479. end;
  480. { TPDFTs_Command }
  481. // set text rise
  482. TPDFTs_Command = class(TPDFNumberCommand)
  483. class Function CommandType: TPDFCommandType; override;
  484. Class Function RegisterCommandName : String; override;
  485. end;
  486. // Move text position
  487. TPDFTd_Command = class(TPDFTranslateCommand)
  488. class function CommandType : TPDFCommandType; override;
  489. Class Function RegisterCommandName : String; override;
  490. end;
  491. { TPDFTDCommand }
  492. // Move text position and leading
  493. TPDFTDCommand = class(TPDFTranslateCommand)
  494. class function CommandType : TPDFCommandType; override;
  495. Class Function RegisterCommandName : String; override;
  496. end;
  497. { ----------------------------------------------------------------------
  498. Drawing (path creation)
  499. ----------------------------------------------------------------------}
  500. { TPDFm_command }
  501. TPDFm_command = Class(TPDFOnePointcommand)
  502. public
  503. Class Function RegisterCommandName : String; override;
  504. Function PathSegment : TPDFPathSegment;
  505. end;
  506. { TPDFl_command }
  507. TPDFl_command = Class(TPDFOnePointcommand)
  508. public
  509. Class Function RegisterCommandName : String; override;
  510. end;
  511. { TPDFy_command }
  512. TPDFy_command = Class(TPDFTwoPointsCommand)
  513. public
  514. Class Function RegisterCommandName : String; override;
  515. end;
  516. { TPDFv_command }
  517. TPDFv_command = Class(TPDFTwoPointsCommand)
  518. public
  519. Class Function RegisterCommandName : String; override;
  520. end;
  521. { TPDFc_command }
  522. TPDFc_command = Class(TPDFThreePointsCommand)
  523. public
  524. Class Function RegisterCommandName : String; override;
  525. end;
  526. { TPDFh_command }
  527. TPDFh_command = Class(TPDFDrawcommand)
  528. public
  529. Class Function RegisterCommandName : String; override;
  530. end;
  531. { TPDFre_command }
  532. TPDFre_command = class(TPDFPointCommand)
  533. Public
  534. Class Function RegisterCommandName : String; override;
  535. property X : Single Index 0 Read GetCoord;
  536. property Y : Single Index 1 Read GetCoord;
  537. property Width : Single Index 2 Read GetCoord;
  538. property Height : Single Index 3 Read GetCoord;
  539. end;
  540. { ----------------------------------------------------------------------
  541. Stroke (path closing) commands
  542. ----------------------------------------------------------------------}
  543. { TPDFScommand }
  544. TPDFScommand = class(TPDFStrokeCommand)
  545. public
  546. Class Function RegisterCommandName : String; override;
  547. class Function StrokeOptions : TPDFStrokeOptions; override;
  548. end;
  549. { TPDFs_command }
  550. TPDFs_command = class(TPDFStrokeCommand)
  551. public
  552. Class Function RegisterCommandName : String; override;
  553. class Function StrokeOptions : TPDFStrokeOptions; override;
  554. end;
  555. { TPDFf_command }
  556. TPDFf_command = class(TPDFStrokeCommand)
  557. public
  558. Class Function RegisterCommandName : String; override;
  559. class Function StrokeOptions : TPDFStrokeOptions; override;
  560. end;
  561. { TPDFFcommand }
  562. TPDFFcommand = class(TPDFStrokeCommand)
  563. public
  564. Class Function RegisterCommandName : String; override;
  565. class Function StrokeOptions : TPDFStrokeOptions; override;
  566. end;
  567. { TPDfAsterisk_command }
  568. { TPDFfAsterisk_command }
  569. TPDFfAsterisk_command = class(TPDFStrokeCommand)
  570. public
  571. Class Function RegisterCommandName : String; override;
  572. class Function StrokeOptions : TPDFStrokeOptions; override;
  573. end;
  574. { TPDFBcommand }
  575. TPDFBcommand = class(TPDFStrokeCommand)
  576. public
  577. Class Function RegisterCommandName : String; override;
  578. class Function StrokeOptions : TPDFStrokeOptions; override;
  579. end;
  580. { TPDFBAsteriskcommand }
  581. TPDFBAsteriskcommand = class(TPDFStrokeCommand)
  582. public
  583. Class Function RegisterCommandName : String; override;
  584. class Function StrokeOptions : TPDFStrokeOptions; override;
  585. end;
  586. { TPDFb_command }
  587. TPDFb_command = class(TPDFStrokeCommand)
  588. public
  589. Class Function RegisterCommandName : String; override;
  590. class Function StrokeOptions : TPDFStrokeOptions; override;
  591. end;
  592. { TPDFbAsterisk_command }
  593. TPDFbAsterisk_command = class(TPDFStrokeCommand)
  594. public
  595. Class Function RegisterCommandName : String; override;
  596. class Function StrokeOptions : TPDFStrokeOptions; override;
  597. end;
  598. { TPDFn_command }
  599. TPDFn_command = class(TPDFStrokeCommand)
  600. public
  601. Class Function RegisterCommandName : String; override;
  602. class Function StrokeOptions : TPDFStrokeOptions; override;
  603. end;
  604. { ----------------------------------------------------------------------
  605. Image commands
  606. ----------------------------------------------------------------------}
  607. TPDFImageData = record
  608. Width,
  609. height,
  610. BitsPerComponent : Integer;
  611. ColorSpace : String;
  612. ColorSpaceComponents : Integer;
  613. Filters : Array of String;
  614. end;
  615. { TPDFImageDataCommand }
  616. TPDFImageDataCommand = Class(TPDFCommand)
  617. Class Procedure ParseImageOperands(aOperands : TPDFTokenArray; Out aImageData : TPDFImageData);
  618. Class Function RegisterCommandName : String; override;
  619. end;
  620. Function StringToColorSpace(aName : string) : TPDFColorSpace;
  621. implementation
  622. Procedure RegisterStandardCommands;
  623. begin
  624. // general
  625. TPDFBXCommand.Register;
  626. TPDFEXCommand.Register;
  627. TPDFcm_Command.Register;
  628. TPDFDoCommand.Register;
  629. TPDFBTCommand.Register;
  630. TPDFETCommand.Register;
  631. // Graphics state
  632. TPDFgs_Command.Register;
  633. TPDFQCommand.Register;
  634. TPDFq_Command.Register;
  635. // text state
  636. TPDFTDCommand.Register;
  637. TPDFTd_Command.Register;
  638. TPDFTf_Command.Register;
  639. TPDFTm_Command.Register;
  640. TPDFTc_Command.Register;
  641. TPDFTw_Command.Register;
  642. TPDFTz_Command.Register;
  643. TPDFTLCommand.Register;
  644. TPDFTr_Command.Register;
  645. TPDFTs_Command.Register;
  646. TPDFTAsterixCommand.Register;
  647. // Text
  648. TPDFTJCommand.Register;
  649. TPDFTj_Command.Register;
  650. // Graphics state
  651. TPDFw_Command.Register;
  652. TPDFJCommand.Register;
  653. TPDFj_Command.Register;
  654. TPDFMCommand.Register;
  655. TPDFd_Command.Register;
  656. TPDFi_Command.Register;
  657. TPDFri_Command.Register;
  658. // Color space
  659. // Draw
  660. TPDFm_command.Register;
  661. TPDFl_command.Register;
  662. TPDFy_command.Register;
  663. TPDFv_command.Register;
  664. TPDFc_command.Register;
  665. TPDFh_command.Register;
  666. // Stroke
  667. TPDFScommand.Register;
  668. TPDFs_command.Register;
  669. TPDFf_command.Register;
  670. TPDFFcommand.Register;
  671. TPDFfAsterisk_command.Register;
  672. TPDFBcommand.Register;
  673. TPDFBAsteriskcommand.Register;
  674. TPDFb_command.Register;
  675. TPDFbAsterisk_command.Register;
  676. TPDFn_command.Register;
  677. TPDFre_command.Register;
  678. // Marked content
  679. TPDFBDCCommand.Register;
  680. TPDFBMCCommand.Register;
  681. TPDFEMCCommand.Register;
  682. TPDFMPCommand.Register;
  683. TPDFDPCommand.Register;
  684. // Color
  685. TPDFCSCommand.Register;
  686. TPDFcs_Command.Register;
  687. TPDFSCCommand.Register;
  688. TPDFsc_Command.Register;
  689. TPDFSCNCommand.Register;
  690. TPDFGCommand.Register;
  691. TPDFg_Command.Register;
  692. TPDFRGCommand.Register;
  693. TPDFrg_Command.Register;
  694. TPDFKCommand.Register;
  695. TPDFk_Command.Register;
  696. end;
  697. { TPDFDrawcommand }
  698. class function TPDFDrawcommand.CommandType: TPDFCommandType;
  699. begin
  700. Result:=cmtPath;
  701. end;
  702. { TPDFPointcommand }
  703. function TPDFPointcommand.GetCoord(AIndex: Integer): Single;
  704. begin
  705. if (aIndex>=0) and (aIndex<Length(Tokens)) then
  706. Result:=Tokens[aIndex].AsSingle
  707. else
  708. Result:=0;
  709. end;
  710. function TPDFPointcommand.GetPoint(AIndex: Integer): TPDFPoint;
  711. begin
  712. Result.X:=GetCoord(aIndex * 2);
  713. Result.Y:=GetCoord((aIndex * 2)+1);
  714. end;
  715. function TPDFTransformCommand.GetMatrixPos(aIndex: Integer): double;
  716. begin
  717. if (aIndex<Length(Tokens)) then
  718. Result:=Tokens[aIndex].AsDouble
  719. else
  720. Result:=0.0;
  721. end;
  722. function TPDFTransformCommand.GetTransFormation: TPDFTransFormation;
  723. begin
  724. Result:=TPDFTransFormation.Create(a,b,c,d,e,f);
  725. end;
  726. { TPDFNumberCommand }
  727. function TPDFNumberCommand.GetAsArray: TSingleDynArray;
  728. var
  729. I : Integer;
  730. begin
  731. SetLength(Result,Length(Tokens));
  732. For I:=0 to Length(Result)-1 do
  733. Result[i]:=Values[I];
  734. end;
  735. function TPDFNumberCommand.GetValues(Index: Integer): Single;
  736. begin
  737. if (Index>=0) and (Index<Length(Tokens)) then
  738. Result:=Tokens[Index].AsSingle
  739. else
  740. Result:=0;
  741. end;
  742. function TPDFNumberCommand.GetValue: Single;
  743. begin
  744. if Length(Tokens)>0 then
  745. Result:=Tokens[0].AsSingle
  746. else
  747. Result:=0;
  748. end;
  749. { TPDFIntegerNumberCommand }
  750. function TPDFIntegerNumberCommand.GetValue: Integer;
  751. begin
  752. if Length(Tokens)>0 then
  753. Result:=Tokens[0].AsInteger
  754. else
  755. Result:=0;
  756. end;
  757. { TPDFStringCommand }
  758. function TPDFStringCommand.GetValue: String;
  759. begin
  760. if (Length(Tokens)>0) and Tokens[0].IsString then
  761. Result:=Tokens[0].AsString
  762. else
  763. Result:='';
  764. end;
  765. { TPDFNameCommand }
  766. function TPDFNameCommand.GetValue: String;
  767. begin
  768. if (Length(Tokens)>0) and Tokens[0].IsName then
  769. Result:=Tokens[0].AsName
  770. else
  771. Result:='';
  772. end;
  773. { TPDFMarkedContentCommand }
  774. class function TPDFMarkedContentCommand.CommandType: TPDFCommandType;
  775. begin
  776. Result:=cmtMarkedContent;
  777. end;
  778. { TPDFGraphicStateCommand }
  779. class function TPDFGraphicStateCommand.CommandType: TPDFCommandType;
  780. begin
  781. Result:=cmtGraphicState;
  782. end;
  783. { TPDFTextStateCommand }
  784. class function TPDFTextStateCommand.CommandType: TPDFCommandType;
  785. begin
  786. Result:=cmtTextState;
  787. end;
  788. { TPDFTextCommand }
  789. class function TPDFTextCommand.CommandType: TPDFCommandType;
  790. begin
  791. Result:=cmtText;
  792. end;
  793. function TPDFTextCommand.GetFullText(aUnicodeMap: TPDFCMap): RawByteString;
  794. Var
  795. aRaw : RawByteString;
  796. begin
  797. aRaw:=GetFullText();
  798. if not Assigned(aUnicodeMap) then
  799. Result:=aRaw
  800. else
  801. Result:=aUnicodeMap.InterPret(aRaw);
  802. end;
  803. { TPDFImageDataCommand }
  804. class procedure TPDFImageDataCommand.ParseImageOperands(
  805. aOperands: TPDFTokenArray; out aImageData: TPDFImageData);
  806. Var
  807. I,J : Integer;
  808. begin
  809. aImageData:=Default(TPDFImageData);
  810. I:=0;
  811. While (I<Length(aOperands)-1) do
  812. begin
  813. if aOperands[i].IsName then
  814. begin
  815. Case Copy(aOperands[i].TokenData,2,Length(aOperands[i].TokenData)-1) of
  816. SPDFImageKeyW :
  817. begin
  818. Inc(I);
  819. aImageData.Width:=aOperands[i].AsInteger;
  820. end;
  821. SPDFImageKeyH :
  822. begin
  823. Inc(I);
  824. aImageData.Height:=aOperands[i].AsInteger;
  825. end;
  826. SPDFImageKeyBPC:
  827. begin
  828. Inc(I);
  829. aImageData.BitsPerComponent:=aOperands[i].AsInteger;
  830. end;
  831. SPDFImageKeyCS:
  832. begin
  833. Inc(I);
  834. aImageData.ColorSpace:=aOperands[i].TokenData;
  835. end;
  836. SPDFImageKeyF:
  837. begin
  838. Inc(i);
  839. If aOperands[i].TokenType<>ptSquareOpen then
  840. begin
  841. Inc(i);
  842. aImageData.Filters:=[aOperands[i].TokenData];
  843. end
  844. else
  845. begin
  846. Inc(I);
  847. J:=I;
  848. While (J<Length(aOperands)) and (aOperands[J].TokenType<>ptSquareClose) do
  849. Inc(J);
  850. SetLength(aImageData.Filters,J);
  851. J:=I;
  852. While (J<Length(aOperands)) and (aOperands[J].TokenType<>ptSquareClose) do
  853. begin
  854. aImageData.Filters[J-I]:=aOperands[J].TokenData;
  855. Inc(J);
  856. end
  857. end;
  858. end;
  859. end;
  860. end;
  861. inc(I);
  862. end;
  863. Case Copy(aImageData.ColorSpace,2,Length(aImageData.ColorSpace)-1) of
  864. SPDFImageKeyCMYK : aImageData.ColorSpaceComponents:=4;
  865. SPDFImageKeyRGB : aImageData.ColorSpaceComponents:=3;
  866. SPDFImageKeyG : aImageData.ColorSpaceComponents:=1;
  867. end;
  868. end;
  869. class function TPDFImageDataCommand.RegisterCommandName: String;
  870. begin
  871. Result:='ID';
  872. end;
  873. { TPDFTTranslateCommand }
  874. function TPDFTranslateCommand.GetPos(AIndex: Integer): double;
  875. begin
  876. if aIndex<Length(Tokens) then
  877. Result:=Tokens[aIndex].AsDouble
  878. else
  879. Result:=0;
  880. end;
  881. { TPDFTd_Command }
  882. class function TPDFTd_Command.CommandType: TPDFCommandType;
  883. begin
  884. Result:=cmtTextState;
  885. end;
  886. class function TPDFTd_Command.RegisterCommandName: String;
  887. begin
  888. Result:='Td';
  889. end;
  890. { TPDFq_Command }
  891. class function TPDFq_Command.RegisterCommandName: String;
  892. begin
  893. Result:='q';
  894. end;
  895. { TPDFQCommand }
  896. class function TPDFQCommand.RegisterCommandName: String;
  897. begin
  898. Result:='Q';
  899. end;
  900. { TPDFw_Command }
  901. class function TPDFw_Command.CommandType: TPDFCommandType;
  902. begin
  903. Result:=cmtGraphicState;
  904. end;
  905. class function TPDFw_Command.RegisterCommandName: String;
  906. begin
  907. Result:='w';
  908. end;
  909. { TPDFJCommand }
  910. function TPDFJCommand.GetLineCap: TPDFLineCapStyle;
  911. Var
  912. i : integer;
  913. begin
  914. Result:=lcsbutt;
  915. I:=Value;
  916. if (I>=0) and (I<Ord(High(TPDFLineCapStyle))) then
  917. Result:=TPDFLineCapStyle(I);
  918. end;
  919. class function TPDFJCommand.CommandType: TPDFCommandType;
  920. begin
  921. Result:=cmtGraphicState;
  922. end;
  923. class function TPDFJCommand.RegisterCommandName: String;
  924. begin
  925. Result:='J'
  926. end;
  927. { TPDFj_Command }
  928. function TPDFj_Command.GetLineJoin: TPDFLineJoinStyle;
  929. Var
  930. i : integer;
  931. begin
  932. Result:=ljsMiter;
  933. I:=Value;
  934. if (I>=0) and (I<Ord(High(TPDFLineJoinStyle))) then
  935. Result:=TPDFLineJoinStyle(I);
  936. end;
  937. class function TPDFj_Command.CommandType: TPDFCommandType;
  938. begin
  939. Result:=cmtGraphicState;
  940. end;
  941. class function TPDFj_Command.RegisterCommandName: String;
  942. begin
  943. Result:='j';
  944. end;
  945. { TPDFMCommand }
  946. class function TPDFMCommand.CommandType: TPDFCommandType;
  947. begin
  948. Result:=cmtGraphicState;
  949. end;
  950. class function TPDFMCommand.RegisterCommandName: String;
  951. begin
  952. Result:='M';
  953. end;
  954. { TPDFd_Command }
  955. function TPDFd_Command.GetDash: TPDFDashPattern;
  956. begin
  957. Result.Pattern:=Pattern;
  958. Result.Phase:=Phase;
  959. end;
  960. function TPDFd_Command.GetPattern: TIntegerDynArray;
  961. var
  962. i,len : Integer;
  963. begin
  964. Result:=[];
  965. Len:=Length(Tokens)-2; // Index of ]
  966. if (Len<2) then
  967. exit;
  968. if (Tokens[0].AsString='[') and (Tokens[Len].AsString=']') then
  969. begin
  970. SetLength(Result,Len-1);
  971. for I:=1 to Len-1 do
  972. if Tokens[I].IsInteger then
  973. Result[i-1]:=Tokens[I].AsInteger
  974. else
  975. Result[i-1]:=0;
  976. end;
  977. end;
  978. function TPDFd_Command.GetPhase: Integer;
  979. var
  980. len : Integer;
  981. begin
  982. Len:=Length(Tokens)-1; // Index of phase
  983. if (Len>2) and (Tokens[len].IsInteger) then
  984. Result:=Tokens[Len].asInteger
  985. end;
  986. class function TPDFd_Command.CommandType: TPDFCommandType;
  987. begin
  988. Result:=cmtGraphicState;
  989. end;
  990. class function TPDFd_Command.RegisterCommandName: String;
  991. begin
  992. Result:='d';
  993. end;
  994. { TPDFi_Command }
  995. class function TPDFi_Command.CommandType: TPDFCommandType;
  996. begin
  997. Result:=cmtGraphicState;
  998. end;
  999. class function TPDFi_Command.RegisterCommandName: String;
  1000. begin
  1001. Result:='i';
  1002. end;
  1003. { TPDFri_Command }
  1004. class function TPDFri_Command.CommandType: TPDFCommandType;
  1005. begin
  1006. Result:=cmtGraphicState;
  1007. end;
  1008. class function TPDFri_Command.RegisterCommandName: String;
  1009. begin
  1010. Result:='ri';
  1011. end;
  1012. { TPDFgs_Command }
  1013. class function TPDFgs_Command.CommandType: TPDFCommandType;
  1014. begin
  1015. Result:=cmtGraphicState;
  1016. end;
  1017. class function TPDFgs_Command.RegisterCommandName: String;
  1018. begin
  1019. Result:='gs';
  1020. end;
  1021. { ----------------------------------------------------------------------
  1022. Color commands
  1023. ----------------------------------------------------------------------}
  1024. { TPDFCSCommand }
  1025. class function TPDFCSCommand.CommandType: TPDFCommandType;
  1026. begin
  1027. Result:=cmtColor;
  1028. end;
  1029. class function TPDFCSCommand.RegisterCommandName: String;
  1030. begin
  1031. Result:='CS';
  1032. end;
  1033. Function StringToColorSpace(aName : string) : TPDFColorSpace;
  1034. begin
  1035. if (aName<>'') and (aName[1]='/') then
  1036. Delete(aName,1,1);
  1037. case aName of
  1038. SPDFColorSpaceDeviceRGB : result:=csDeviceRGB;
  1039. SPDFColorSpaceDeviceGray : result:=csDeviceGray;
  1040. SPDFColorSpaceDeviceCMYK : result:=csDeviceCMYK;
  1041. else
  1042. Result:=csDict;
  1043. end;
  1044. end;
  1045. function TPDFCSCommand.ColorSpace: TPDFColorSpace;
  1046. begin
  1047. StringToColorSpace(Name);
  1048. end;
  1049. { TPDFcs_Command }
  1050. class function TPDFcs_Command.CommandType: TPDFCommandType;
  1051. begin
  1052. Result:=cmtColor;
  1053. end;
  1054. class function TPDFcs_Command.RegisterCommandName: String;
  1055. begin
  1056. Result:='cs';
  1057. end;
  1058. function TPDFcs_Command.ColorSpace: TPDFColorSpace;
  1059. begin
  1060. Result:=StringToColorSpace(Name);
  1061. end;
  1062. { TPDFSCCommand }
  1063. class function TPDFSCCommand.CommandType: TPDFCommandType;
  1064. begin
  1065. Result:=cmtColor;
  1066. end;
  1067. class function TPDFSCCommand.RegisterCommandName: String;
  1068. begin
  1069. Result:='SC';
  1070. end;
  1071. { TPDFsc_Command }
  1072. class function TPDFsc_Command.CommandType: TPDFCommandType;
  1073. begin
  1074. Result:=cmtColor;
  1075. end;
  1076. class function TPDFsc_Command.RegisterCommandName: String;
  1077. begin
  1078. Result:='sc';
  1079. end;
  1080. { TPDFColorNamespaceCommand }
  1081. function TPDFColorNamespaceCommand.GetAsArray: TSingleDynArray;
  1082. var
  1083. I,aCount : Integer;
  1084. begin
  1085. aCount:=Length(Tokens)-Ord(HasName);
  1086. SetLength(Result,aCount);
  1087. For I:=0 to aCount-1 do
  1088. Result[i]:=Tokens[i].AsSingle;
  1089. end;
  1090. function TPDFColorNamespaceCommand.HasName: Boolean;
  1091. begin
  1092. Result:=(Length(Tokens)>0) and (Tokens[Length(Tokens)].TokenType=ptName);
  1093. end;
  1094. class function TPDFColorNamespaceCommand.CommandType: TPDFCommandType;
  1095. begin
  1096. Result:=cmtColor;
  1097. end;
  1098. function TPDFColorNamespaceCommand.ColorSpaceName: String;
  1099. begin
  1100. if HasName then
  1101. Result:=Tokens[Length(Tokens)-1].AsName;
  1102. end;
  1103. { TPDFSCNCommand }
  1104. class function TPDFSCNCommand.RegisterCommandName: String;
  1105. begin
  1106. Result:='SCN';
  1107. end;
  1108. { TPDFscn_Command }
  1109. class function TPDFscn_Command.RegisterCommandName: String;
  1110. begin
  1111. Result:='scn';
  1112. end;
  1113. { TPDFg_Command }
  1114. function TPDFg_Command.GetColor: TPDFColor;
  1115. begin
  1116. Result:=Default(TPDFColor);
  1117. Result[0]:=Gray;
  1118. end;
  1119. class function TPDFg_Command.CommandType: TPDFCommandType;
  1120. begin
  1121. Result:=cmtColor
  1122. end;
  1123. class function TPDFg_Command.RegisterCommandName: String;
  1124. begin
  1125. Result:='g';
  1126. end;
  1127. function TPDFg_Command.ColorSpace: TPDFColorSpace;
  1128. begin
  1129. Result:=csDeviceGray;
  1130. end;
  1131. { TPDFRGBCommand }
  1132. function TPDFRGBCommand.GetColor: TPDFColor;
  1133. begin
  1134. Result:=Default(TPDFColor);
  1135. Result[0]:=R;
  1136. Result[1]:=G;
  1137. Result[2]:=B;
  1138. end;
  1139. class function TPDFRGBCommand.CommandType: TPDFCommandType;
  1140. begin
  1141. Result:=cmtColor;
  1142. end;
  1143. function TPDFRGBCommand.ColorSpace: TPDFColorSpace;
  1144. begin
  1145. Result:=csDeviceRGB;
  1146. end;
  1147. { TPDFRGCommand }
  1148. class function TPDFRGCommand.RegisterCommandName: String;
  1149. begin
  1150. Result:='RG';
  1151. end;
  1152. { TPDFrg_Command }
  1153. class function TPDFrg_Command.RegisterCommandName: String;
  1154. begin
  1155. Result:='rg';
  1156. end;
  1157. { TPDFCMYKCommand }
  1158. function TPDFCMYKCommand.GetAsColor: TPDFColor;
  1159. begin
  1160. Result:=Default(TPDFColor);
  1161. Result[0]:=C;
  1162. Result[1]:=M;
  1163. Result[2]:=Y;
  1164. Result[3]:=K;
  1165. end;
  1166. class function TPDFCMYKCommand.CommandType: TPDFCommandType;
  1167. begin
  1168. Result:=cmtColor;
  1169. end;
  1170. function TPDFCMYKCommand.ColorSpace: TPDFColorSpace;
  1171. begin
  1172. result:=csDeviceCMYK;
  1173. end;
  1174. { TPDFKCommand }
  1175. class function TPDFKCommand.RegisterCommandName: String;
  1176. begin
  1177. Result:='K';
  1178. end;
  1179. { TPDFk_Command }
  1180. class function TPDFk_Command.RegisterCommandName: String;
  1181. begin
  1182. Result:='k';
  1183. end;
  1184. { TPDFGCommand }
  1185. function TPDFGCommand.GetColor: TPDFColor;
  1186. begin
  1187. Result:=Default(TPDFColor);
  1188. Result[0]:=Gray;
  1189. end;
  1190. class function TPDFGCommand.CommandType: TPDFCommandType;
  1191. begin
  1192. Result:=cmtColor;
  1193. end;
  1194. class function TPDFGCommand.RegisterCommandName: String;
  1195. begin
  1196. Result:='G';
  1197. end;
  1198. function TPDFGCommand.ColorSpace: TPDFColorSpace;
  1199. begin
  1200. Result:=csDeviceGray;
  1201. end;
  1202. { ----------------------------------------------------------------------
  1203. Drawing commands
  1204. ----------------------------------------------------------------------}
  1205. { TPDFm_command }
  1206. class function TPDFm_command.RegisterCommandName: String;
  1207. begin
  1208. Result:='m'
  1209. end;
  1210. function TPDFm_command.PathSegment: TPDFPathSegment;
  1211. begin
  1212. Result:=Default(TPDFPathSegment);
  1213. Result.SegmentType:=stStart;
  1214. Result.P1:=asPoint;
  1215. end;
  1216. { TPDFl_command }
  1217. class function TPDFl_command.RegisterCommandName: String;
  1218. begin
  1219. Result:='l';
  1220. end;
  1221. { TPDFy_command }
  1222. class function TPDFy_command.RegisterCommandName: String;
  1223. begin
  1224. Result:='y';
  1225. end;
  1226. { TPDFv_command }
  1227. class function TPDFv_command.RegisterCommandName: String;
  1228. begin
  1229. Result:='v';
  1230. end;
  1231. { TPDFc_command }
  1232. class function TPDFc_command.RegisterCommandName: String;
  1233. begin
  1234. Result:='c';
  1235. end;
  1236. { TPDFh_command }
  1237. class function TPDFh_command.RegisterCommandName: String;
  1238. begin
  1239. Result:='h';
  1240. end;
  1241. { TPDFTre_command }
  1242. class function TPDFre_command.RegisterCommandName: String;
  1243. begin
  1244. Result:='re';
  1245. end;
  1246. { TPDFStrokeCommand }
  1247. class function TPDFStrokeCommand.CommandType: TPDFCommandType;
  1248. begin
  1249. Result:=cmtStroke;
  1250. end;
  1251. { TPDFScommand }
  1252. class function TPDFScommand.RegisterCommandName: String;
  1253. begin
  1254. Result:='S';
  1255. end;
  1256. class function TPDFScommand.StrokeOptions: TPDFStrokeOptions;
  1257. begin
  1258. Result:=[soStroke]
  1259. end;
  1260. { TPDFs_command }
  1261. class function TPDFs_command.RegisterCommandName: String;
  1262. begin
  1263. Result:='s';
  1264. end;
  1265. class function TPDFs_command.StrokeOptions: TPDFStrokeOptions;
  1266. begin
  1267. Result:=[soClose,soStroke]
  1268. end;
  1269. { TPDFf_command }
  1270. class function TPDFf_command.RegisterCommandName: String;
  1271. begin
  1272. Result:='f';
  1273. end;
  1274. class function TPDFf_command.StrokeOptions: TPDFStrokeOptions;
  1275. begin
  1276. Result:=[soFill,soNonZeroWinding];
  1277. end;
  1278. { TPDFFcommand }
  1279. class function TPDFFcommand.RegisterCommandName: String;
  1280. begin
  1281. Result:='F';
  1282. end;
  1283. class function TPDFFcommand.StrokeOptions: TPDFStrokeOptions;
  1284. begin
  1285. Result:=[soFill,soNonZeroWinding];
  1286. end;
  1287. { TPDFfAsterisk_command }
  1288. class function TPDFfAsterisk_command.RegisterCommandName: String;
  1289. begin
  1290. Result:='f*';
  1291. end;
  1292. class function TPDFfAsterisk_command.StrokeOptions: TPDFStrokeOptions;
  1293. begin
  1294. Result:=[soFill,soEvenOdd];
  1295. end;
  1296. { TPDFBcommand }
  1297. class function TPDFBcommand.RegisterCommandName: String;
  1298. begin
  1299. Result:='B';
  1300. end;
  1301. class function TPDFBcommand.StrokeOptions: TPDFStrokeOptions;
  1302. begin
  1303. Result:=[soStroke,soFill,soNonZeroWinding];
  1304. end;
  1305. { TPDFBAsteriskcommand }
  1306. class function TPDFBAsteriskcommand.RegisterCommandName: String;
  1307. begin
  1308. Result:='B*';
  1309. end;
  1310. class function TPDFBAsteriskcommand.StrokeOptions: TPDFStrokeOptions;
  1311. begin
  1312. Result:=[soStroke,soFill,soEvenOdd];
  1313. end;
  1314. { TPDFb_command }
  1315. class function TPDFb_command.RegisterCommandName: String;
  1316. begin
  1317. Result:='b';
  1318. end;
  1319. class function TPDFb_command.StrokeOptions: TPDFStrokeOptions;
  1320. begin
  1321. Result:=[soClose,soStroke,soFill,soNonZeroWinding];
  1322. end;
  1323. { TPDFbAsterisk_command }
  1324. class function TPDFbAsterisk_command.RegisterCommandName: String;
  1325. begin
  1326. Result:='b*';
  1327. end;
  1328. class function TPDFbAsterisk_command.StrokeOptions: TPDFStrokeOptions;
  1329. begin
  1330. Result:=[soStroke,soFill,soEvenOdd];
  1331. end;
  1332. { TPDFn_command }
  1333. class function TPDFn_command.RegisterCommandName: String;
  1334. begin
  1335. Result:='n';
  1336. end;
  1337. class function TPDFn_command.StrokeOptions: TPDFStrokeOptions;
  1338. begin
  1339. Result:=[soClose];
  1340. end;
  1341. { TPDFTj_Command }
  1342. class function TPDFTj_Command.RegisterCommandName: String;
  1343. begin
  1344. Result:='Tj';
  1345. end;
  1346. function TPDFTj_Command.GetFullText: RawByteString;
  1347. begin
  1348. Result:='';
  1349. if Length(Self.Tokens)>0 then
  1350. try
  1351. Result:=Tokens[0].AsString;
  1352. except
  1353. on E : exception do
  1354. begin
  1355. Writeln('Exception ',E.ClassName,'getting text for token: "',E.Message,'". Token data :',GetDescription);
  1356. Raise;
  1357. end;
  1358. end;
  1359. end;
  1360. { TPDFTfCommand }
  1361. function TPDFTf_Command.GetFontName: String;
  1362. begin
  1363. Result:='';
  1364. If (Length(Tokens)>0) then
  1365. if Tokens[0].IsString then
  1366. Result:=Tokens[0].AsString
  1367. else if Tokens[0].IsName then
  1368. Result:=Tokens[0].AsName;
  1369. end;
  1370. function TPDFTf_Command.GetFontSize: Integer;
  1371. begin
  1372. Result:=0;
  1373. If (Length(Tokens)>1) and Tokens[1].IsInteger then
  1374. Result:=Tokens[1].AsInteger
  1375. end;
  1376. class function TPDFTf_Command.RegisterCommandName: String;
  1377. begin
  1378. Result:='Tf';
  1379. end;
  1380. { TPDFTdCommand }
  1381. class function TPDFTDCommand.CommandType: TPDFCommandType;
  1382. begin
  1383. Result:=cmtTextState;
  1384. end;
  1385. class function TPDFTDCommand.RegisterCommandName: String;
  1386. begin
  1387. Result:='TD';
  1388. end;
  1389. { TPDFTm_Command }
  1390. class function TPDFTm_Command.CommandType: TPDFCommandType;
  1391. begin
  1392. Result:=cmtTextState;
  1393. end;
  1394. class function TPDFTm_Command.RegisterCommandName: String;
  1395. begin
  1396. Result:='Tm';
  1397. end;
  1398. { TPDFTAsterixCommand }
  1399. class function TPDFTAsterixCommand.CommandType: TPDFCommandType;
  1400. begin
  1401. Result:=cmtTextState;
  1402. end;
  1403. class function TPDFTAsterixCommand.RegisterCommandName: String;
  1404. begin
  1405. Result:='T*';
  1406. end;
  1407. { TPDFTc_Command }
  1408. class function TPDFTc_Command.CommandType: TPDFCommandType;
  1409. begin
  1410. Result:=cmtTextState;
  1411. end;
  1412. class function TPDFTc_Command.RegisterCommandName: String;
  1413. begin
  1414. Result:='Tc';
  1415. end;
  1416. { TPDFTw_Command }
  1417. class function TPDFTw_Command.CommandType: TPDFCommandType;
  1418. begin
  1419. Result:=cmtTextState;
  1420. end;
  1421. class function TPDFTw_Command.RegisterCommandName: String;
  1422. begin
  1423. Result:='Tw';
  1424. end;
  1425. { TPDFTz_Command }
  1426. class function TPDFTz_Command.CommandType: TPDFCommandType;
  1427. begin
  1428. Result:=cmtTextState;
  1429. end;
  1430. class function TPDFTz_Command.RegisterCommandName: String;
  1431. begin
  1432. Result:='Tz';
  1433. end;
  1434. { TPDFTLCommand }
  1435. class function TPDFTLCommand.CommandType: TPDFCommandType;
  1436. begin
  1437. Result:=cmtTextState;
  1438. end;
  1439. class function TPDFTLCommand.RegisterCommandName: String;
  1440. begin
  1441. Result:='TL';
  1442. end;
  1443. { TPDFTrCommand }
  1444. class function TPDFTr_Command.CommandType: TPDFCommandType;
  1445. begin
  1446. Result:=cmtTextState;
  1447. end;
  1448. class function TPDFTr_Command.RegisterCommandName: String;
  1449. begin
  1450. Result:='Tr';
  1451. end;
  1452. function TPDFTr_Command.RenderMode: TPDFTextRenderMode;
  1453. begin
  1454. Case Value of
  1455. 0 : Result:=[trmFill];
  1456. 1 : Result:=[trmStroke];
  1457. 2 : Result:=[trmFill,trmStroke];
  1458. 3 : Result:=[];
  1459. 4 : Result:=[trmFill,trmAddToClippingPath];
  1460. 5 : Result:=[trmStroke,trmAddToClippingPath];
  1461. 6 : Result:=[trmFill,trmStroke,trmAddToClippingPath];
  1462. 7 : Result:=[trmAddToClippingPath];
  1463. else
  1464. Result:=[trmFill];
  1465. end;
  1466. end;
  1467. { TPDFTsCommand }
  1468. class function TPDFTs_Command.CommandType: TPDFCommandType;
  1469. begin
  1470. Result:=cmtTextState;
  1471. end;
  1472. class function TPDFTs_Command.RegisterCommandName: String;
  1473. begin
  1474. Result:='Ts';
  1475. end;
  1476. { TPDFcm_Command }
  1477. class function TPDFcm_Command.RegisterCommandName: String;
  1478. begin
  1479. Result:='cm';
  1480. end;
  1481. class function TPDFcm_Command.CommandType: TPDFCommandType;
  1482. begin
  1483. Result:=cmtGraphicState;
  1484. end;
  1485. { TPDFTJCommand }
  1486. class function TPDFTJCommand.RegisterCommandName: String;
  1487. begin
  1488. Result:='TJ';
  1489. end;
  1490. function TPDFTJCommand.GetFullText(aUnicodeMap: TPDFCMap): RawByteString;
  1491. Var
  1492. i : integer;
  1493. begin
  1494. if aUnicodeMap=Nil then
  1495. Exit(GetFullText());
  1496. Result:='';
  1497. if Length(Tokens)>=2 then
  1498. For I:=1 to Length(Tokens)-2 do
  1499. case Tokens[I].TokenType of
  1500. ptString,ptHexString:
  1501. Result:=Result+aUnicodeMap.InterPret(Tokens[I].TokenData);
  1502. ptNumber:
  1503. if Abs(Tokens[i].AsDouble)>PDFTextArraySpaceTreshold then
  1504. Result:=Result+' ';
  1505. else
  1506. Raise EConvertError.Create('Unexpected char');
  1507. end;
  1508. end;
  1509. function TPDFTJCommand.GetFullText: RawByteString;
  1510. Var
  1511. i : integer;
  1512. begin
  1513. Result:='';
  1514. if Length(Tokens)>=2 then
  1515. For I:=1 to Length(Tokens)-2 do
  1516. begin
  1517. if Tokens[I].TokenType=ptString then
  1518. Result:=Result+Tokens[I].TokenData
  1519. else if Tokens[i].IsNumber then
  1520. begin
  1521. if Abs(Tokens[i].AsDouble)>PDFTextArraySpaceTreshold then
  1522. Result:=Result+' '
  1523. end
  1524. else if Tokens[I].TokenType=ptHexString then
  1525. Result:='' // Tokens[I].AsHexInteger
  1526. else
  1527. Raise EConvertError.Create('Unexpected char');
  1528. end;
  1529. end;
  1530. { TPDFETCommand }
  1531. class function TPDFETCommand.RegisterCommandName: String;
  1532. begin
  1533. Result:='ET';
  1534. end;
  1535. { TPDFEMCCommand }
  1536. class function TPDFEMCCommand.RegisterCommandName: String;
  1537. begin
  1538. Result:='EMC';
  1539. end;
  1540. { TPDFMPCommand }
  1541. class function TPDFMPCommand.RegisterCommandName: String;
  1542. begin
  1543. Result:='MP';
  1544. end;
  1545. { TPDFDPCommand }
  1546. class function TPDFDPCommand.RegisterCommandName: String;
  1547. begin
  1548. Result:='DP';
  1549. end;
  1550. { TPDFBTCommand }
  1551. class function TPDFBTCommand.RegisterCommandName: String;
  1552. begin
  1553. Result:='BT';
  1554. end;
  1555. { TPDFBDCCommand }
  1556. class function TPDFBDCCommand.RegisterCommandName: String;
  1557. begin
  1558. Result:='BDC';
  1559. end;
  1560. { TPDFBMCCommand }
  1561. class function TPDFBMCCommand.RegisterCommandName: String;
  1562. begin
  1563. Result:='BMC';
  1564. end;
  1565. { TPDFBXCommand }
  1566. class function TPDFBXCommand.RegisterCommandName: String;
  1567. begin
  1568. Result:='BX';
  1569. end;
  1570. { TPDFEXCommand }
  1571. class function TPDFEXCommand.RegisterCommandName: String;
  1572. begin
  1573. Result:='EX';
  1574. end;
  1575. { TPDFcmCommand }
  1576. class function TPDFcmCommand.RegisterCommandName: String;
  1577. begin
  1578. Result:='cm';
  1579. end;
  1580. { TPDFDCommand }
  1581. class function TPDFDoCommand.RegisterCommandName: String;
  1582. begin
  1583. Result:='Do';
  1584. end;
  1585. initialization
  1586. RegisterStandardCommands;
  1587. end.