-
Notifications
You must be signed in to change notification settings - Fork 1
/
OfdiumEx.cpp
2939 lines (2667 loc) · 114 KB
/
OfdiumEx.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// OfdiumEx.cpp : 定义 DLL 应用程序的导出函数。
//
#include "stdafx.h"
#include "OfdiumEx.h"
#include <stdio.h>
#include <fstream>
#include "OFDParser.h"
#include "OFD.h"
#include "ziptool.h"
#include "util.h"
#include "cairo.h"
#include "cairo-win32.h"
#include "cairo-ft.h"
#include <map>
#pragma comment(lib,"cairo.lib")
#include "freetype/freetype.h"
#pragma comment(lib,"freetype.lib")
#include <comutil.h>
#ifdef _DEBUG
#pragma comment(lib, "comsuppwd.lib")
#else
#pragma comment(lib, "comsuppw.lib")
#endif
#include <gdiplus.h>
#include "RefCounter.h"
#include "base64.h"
#include <direct.h>
#include <algorithm>
std::map<OFD *, OFDParser *> listOpenedOFD;
std::map<cairo_surface_t *, std::pair<Gdiplus::Bitmap *,Gdiplus::BitmapData *>> listUsedImage;
ULONG_PTR g_gdiplusToken;
static RefCounter refCounter;
int ii = 0;
//public static extern IntPtr FPDF_LoadCustomDocument([MarshalAs(UnmanagedType.LPStruct)]FPDF_FILEACCESS access, string password);
OFDIUMEX_API void *OFDIUM_LoadCustomDocument(const char *fileName, unsigned long openMode)
{
//_CrtSetBreakAlloc(1399);
char tmp[MAX_PATH] = { 0 };
GetTempPath(MAX_PATH, tmp);
PathAddBackslash(tmp);
PathAppend(tmp, GenerateGUIDString().c_str());
std::string dir = tmp;
ZipTool::extractDir(fileName, dir.c_str());
OFDParser *ofdpaser = new OFDParser(dir);
OFD *ofd = ofdpaser->getData();
int id = 0;
if (ofdpaser && ofd)
{
listOpenedOFD.insert(std::make_pair(ofd, ofdpaser));
}
return ofd;
}
OFDIUMEX_API void *OFDIUM_LoadMemDocument(const unsigned char *data, unsigned long len, unsigned long openMode)
{
char tmp[MAX_PATH] = { 0 };
GetTempPath(MAX_PATH, tmp);
PathAddBackslash(tmp);
PathAppend(tmp, GenerateGUIDString().append(".ofd").c_str());
std::string tmpofdfilename = tmp;
FILE *fp = nullptr;
fopen_s(&fp, tmpofdfilename.c_str(), "wb");
fwrite(data, 1, len, fp);
fflush(fp);
fclose(fp);
return OFDIUM_LoadCustomDocument(tmpofdfilename.c_str(), openMode);
}
//public static extern int FPDF_GetPageCount(IntPtr document);
OFDIUMEX_API int OFDIUM_GetPageCount(void *fileHandle)
{
if (listOpenedOFD.find((OFD *)fileHandle) == listOpenedOFD.end())
{
return -1;
}
auto *ofd = (OFD *)fileHandle;
if (ofd->documents.size() != 1)
{
return -1;
}
Document *doc = ofd->documents[0];
return doc->pages.size();
}
//public static extern uint FPDF_GetDocPermissions(IntPtr document);
OFDIUMEX_API void *OFDIUM_GetDocPermissions(void *fileHandle)
{
if (listOpenedOFD.find((OFD *)fileHandle) == listOpenedOFD.end())
{
return nullptr;
}
auto *ofd = (OFD *)fileHandle;
if (ofd->documents.size() != 1)
{
return nullptr;
}
Document *doc = ofd->documents[0];
return doc->permissions;
}
//public static extern IntPtr FPDFDOC_InitFormFillEnvironment(IntPtr document, FPDF_FORMFILLINFO formInfo);
OFDIUMEX_API void *OFDIUM_InitFormFillEnvironment(void *fileHandle, void *formInfo)
{
return nullptr;
}
//public static extern void FPDF_SetFormFieldHighlightColor(IntPtr hHandle, int fieldType, uint color);
OFDIUMEX_API void OFDIUM_SetFormFieldHighlightColor(void *hHandle, int fieldType, unsigned int color)
{
}
//public static extern void FPDF_SetFormFieldHighlightAlpha(IntPtr hHandle, byte alpha);
OFDIUMEX_API void OFDIUM_SetFormFieldHighlightAlpha(void *hHandle, unsigned char alpha)
{
}
//public static extern void FORM_DoDocumentJSAction(IntPtr hHandle);
OFDIUMEX_API void OFDIUM_DoDocumentJSAction(void *hHandle)
{
}
//public static extern void FORM_DoDocumentOpenAction(IntPtr hHandle);
OFDIUMEX_API void OFDIUM_DoDocumentOpenAction(void *hHandle)
{
}
//public static extern void FPDFDOC_ExitFormFillEnvironment(IntPtr hHandle);
OFDIUMEX_API void OFDIUM_ExitFormFillEnvironment(void *hHandle)
{
}
//public static extern void FORM_DoDocumentAAction(IntPtr hHandle, FPDFDOC_AACTION aaType);
OFDIUMEX_API void OFDIUM_DoDocumentAAction(void *hHandle, int aaType)
{
}
//public static extern IntPtr FPDF_LoadPage(IntPtr document, int page_index);
OFDIUMEX_API void *OFDIUM_LoadPage(void *fileHandle, int page_index)
{
if (listOpenedOFD.find((OFD *)fileHandle) == listOpenedOFD.end())
{
return nullptr;
}
auto *ofd = (OFD *)fileHandle;
if (ofd->documents.size() != 1)
{
return nullptr;
}
Document *doc = ofd->documents[0];
if (page_index >= (int)doc->pages.size())
{
return nullptr;
}
return doc->pages[page_index].second;
}
//public static extern IntPtr FPDFText_LoadPage(IntPtr page);
OFDIUMEX_API void *OFDIUM_Text_LoadPage(void *fileHandle, int page_index)
{
if (listOpenedOFD.find((OFD *)fileHandle) == listOpenedOFD.end())
{
return nullptr;
}
auto *ofd = (OFD *)fileHandle;
if (ofd->documents.size() != 1)
{
return nullptr;
}
Document *doc = ofd->documents[0];
if (page_index >= (int)doc->pages.size())
{
return nullptr;
}
return doc->pages[page_index].first;
}
//public static extern void FORM_OnAfterLoadPage(IntPtr page, IntPtr _form);
OFDIUMEX_API void OFDIUM_OnAfterLoadPage(void *pageHandle, void *formHandle)
{
}
//public static extern void FORM_DoPageAAction(IntPtr page, IntPtr _form, FPDFPAGE_AACTION fPDFPAGE_AACTION);
OFDIUMEX_API void OFDIUM_DoPageAAction(void *pageHandle, void *formHandle, int fPDFPAGE_AACTION)
{
}
//public static extern double FPDF_GetPageWidth(IntPtr page);
OFDIUMEX_API double OFDIUM_GetPageWidth(void *pageHandle)
{
if (pageHandle == nullptr)
{
return 0.0f;
}
auto *page = (Page *)pageHandle;
double page_w = page->area == nullptr ? MM2PIXEL72P(page->fromDoc->commonData->pageArea->physicalBox->w) : MM2PIXEL72P(page->area->physicalBox->w);
return page_w;
}
//public static extern double FPDF_GetPageHeight(IntPtr page);
OFDIUMEX_API double OFDIUM_GetPageHeight(void *pageHandle)
{
if (pageHandle == nullptr)
{
return 0.0f;
}
auto *page = (Page *)pageHandle;
double page_h = page->area == nullptr ? MM2PIXEL72P(page->fromDoc->commonData->pageArea->physicalBox->h) : MM2PIXEL72P(page->area->physicalBox->h);
return page_h;
}
//public static extern void FORM_OnBeforeClosePage(IntPtr page, IntPtr _form);
OFDIUMEX_API void OFDIUM_OnBeforeClosePage(void *pageHandle, void *formHandle)
{
}
//public static extern void FPDFText_ClosePage(IntPtr text_page);
OFDIUMEX_API void OFDIUM_Text_ClosePage(void *textPageHandle)
{
}
//public static extern void FPDF_ClosePage(IntPtr page);
OFDIUMEX_API void OFDIUM_ClosePage(void *pageHandle)
{
}
//public static extern void FPDF_RenderPage(IntPtr dc, IntPtr page, int start_x, int start_y, int size_x, int size_y, int rotate, FPDF flags);
OFDIUMEX_API void OFDIUM_RenderPage(void *dc, void *pageHandle, int start_x, int start_y, int size_x, int size_y, int rotate, int flags)
{
auto *page = (Page *)pageHandle;
return OFDIUM_RenderDocumentPageToDC(page->fromDoc, page->pageIndex, size_x, size_y, start_x, start_y, rotate, dc);
}
//public static extern void FPDF_RenderPageBitmap(IntPtr bitmapHandle, IntPtr page, int start_x, int start_y, int size_x, int size_y, int rotate, FPDF flags);
OFDIUMEX_API void OFDIUM_RenderPageBitmap(void *bitmapHandle, void *pageHandle, int start_x, int start_y, int size_x, int size_y, int rotate, int flags)
{
auto *page = (Page *)pageHandle;
cairo_surface_t *targetsurface = (cairo_surface_t *)bitmapHandle;
return OFDIUM_RenderDocumentPageToSurface(page->fromDoc->fromOfd, page->pageIndex, size_x, size_y, start_x, start_y, rotate, targetsurface);
}
//public static extern int FPDF_GetPageSizeByIndex(IntPtr document, int page_index, out double width, out double height);
OFDIUMEX_API int OFDIUM_GetPageSizeByIndex(void *fileHandle, int page_index, double *width, double *height)
{
if (listOpenedOFD.find((OFD *)fileHandle) == listOpenedOFD.end())
{
return NULL;
}
auto *ofd = (OFD *)fileHandle;
if (ofd->documents.size() != 1)
{
return NULL;
}
Document *doc = ofd->documents[0];
if (page_index >= (int)doc->pages.size())
{
return NULL;
}
Page *page = doc->pages[0].second;
*width = page->area == nullptr ? MM2PIXEL72P(page->fromDoc->commonData->pageArea->physicalBox->w) : MM2PIXEL72P(page->area->physicalBox->w);
*height = page->area == nullptr ? MM2PIXEL72P(page->fromDoc->commonData->pageArea->physicalBox->h) : MM2PIXEL72P(page->area->physicalBox->h);
return 0;
}
//public static extern IntPtr FPDFBitmap_CreateEx(int width, int height, int format, IntPtr first_scan, int stride);
OFDIUMEX_API void *OFDIUM_Bitmap_CreateEx(int width, int height, int format, unsigned char *first_scan, int stride)
{
cairo_surface_t *surfaceTarget = cairo_image_surface_create_for_data(first_scan, (cairo_format_t)format, width, height, stride);
return surfaceTarget;
}
//public static extern void FPDFBitmap_FillRect(IntPtr bitmapHandle, int left, int top, int width, int height, uint color);
OFDIUMEX_API void OFDIUM_Bitmap_FillRect(void *bitmapHandle, int left, int top, int width, int height, unsigned int color)
{
cairo_surface_t *targetsurface = (cairo_surface_t *)bitmapHandle;
cairo_t *cr = cairo_create(targetsurface);
cairo_set_source_rgba(cr, GetRValue(color), GetGValue(color), GetBValue(color), 255);
cairo_rectangle(cr, left, top, width, height);
cairo_fill(cr);
cairo_destroy(cr);
}
//public static extern IntPtr FPDFBitmap_Destroy(IntPtr bitmapHandle);
OFDIUMEX_API void *OFDIUM_Bitmap_Destroy(void *bitmapHandle)
{
cairo_surface_t *targetsurface = (cairo_surface_t *)bitmapHandle;
cairo_surface_destroy(targetsurface);
return nullptr;
}
//public static extern IntPtr FPDFText_FindStart(IntPtr page, byte[] findWhat, FPDF_SEARCH_FLAGS flags, int start_index);
OFDIUMEX_API void *OFDIUM_Text_FindStart(void *page, const unsigned short*findWhat, int flags, int start_index)
{
return nullptr;
}
//public static extern int FPDFText_GetSchResultIndex(IntPtr handle);
OFDIUMEX_API int OFDIUM_Text_GetSchResultIndex(void *handle)
{
return -1;
}
//public static extern int FPDFText_GetSchCount(IntPtr handle);
OFDIUMEX_API int OFDIUM_Text_GetSchCount(void *handle)
{
return -1;
}
//public static extern int FPDFText_GetText(IntPtr page, int start_index, int count, byte[] result);
OFDIUMEX_API int OFDIUM_Text_GetText(void *pageHandle, int start_index, int count, unsigned short* result)
{
return -1;
}
//public static extern void FPDFText_GetCharBox(IntPtr page, int index, out double left, out double right, out double bottom, out double top);
OFDIUMEX_API int OFDIUM_Text_GetCharBox(void *pageHandle, int index, double *left, double *right, double *bottom, double *top)
{
return 0;
}
//public static extern int FPDFText_CountChars(IntPtr page);
OFDIUMEX_API int OFDIUM_Text_CountChars(void *pageHandle)
{
return 0;
}
//public static extern bool FPDFText_FindNext(IntPtr handle);
OFDIUMEX_API bool OFDIUM_Text_FindNext(void *pageHandle)
{
return true;
}
//public static extern void FPDFText_FindClose(IntPtr handle);
OFDIUMEX_API void OFDIUM_Text_FindClose(void *pageHandle)
{
}
//public static extern bool FPDFLink_Enumerate(IntPtr page, ref int startPos, out IntPtr linkAnnot);
OFDIUMEX_API bool OFDIUM_Link_Enumerate(void *pageHandle, int *startPos, void **linkAnnot)
{
return false;
}
//public static extern IntPtr FPDFLink_GetDest(IntPtr document, IntPtr link);
OFDIUMEX_API void *OFDIUM_Link_GetDest(void *fileHandle, void *link)
{
return nullptr;
}
//public static extern uint FPDFDest_GetPageIndex(IntPtr document, IntPtr dest);
OFDIUMEX_API unsigned int OFDIUM_Dest_GetPageIndex(void *fileHandle, void *dest)
{
return 0;
}
//public static extern bool FPDFLink_GetAnnotRect(IntPtr linkAnnot, FS_RECTF rect);
OFDIUMEX_API bool OFDIUM_Link_GetAnnotRect(void *linkAnnot, void *rect)
{
return false;
}
//public static extern void FPDF_DeviceToPage(IntPtr page, int start_x, int start_y, int size_x, int size_y, int rotate, int device_x, int device_y, out double page_x, out double page_y);
OFDIUMEX_API void OFDIUM_DeviceToPage(void *pageHandle, int start_x, int start_y, int size_x, int size_y, int rotate, int device_x, int device_y, double *page_x, double *page_y)
{
}
//public static extern void FPDF_PageToDevice(IntPtr page, int start_x, int start_y, int size_x, int size_y, int rotate, double page_x, double page_y, out int device_x, out int device_y);
OFDIUMEX_API void OFDIUM_PageToDevice(void *pageHandle, int start_x, int start_y, int size_x, int size_y, int rotate, double page_x, double page_y, int *device_x, int *device_y)
{
}
//public static extern IntPtr FPDFLink_GetAction(IntPtr link);
OFDIUMEX_API void *OFDIUM_Link_GetAction(void *link)
{
return nullptr;
}
//public static extern uint FPDFAction_GetURIPath(IntPtr document, IntPtr action, StringBuilder buffer, uint buflen);
OFDIUMEX_API unsigned long OFDIUM_Action_GetURIPath(void *fileHandle, void *action, void *buffer, unsigned long buflen)
{
return 0;
}
//public static extern IntPtr FPDFBookmark_GetFirstChild(IntPtr document, IntPtr bookmark);
OFDIUMEX_API void *OFDIUM_Bookmark_GetFirstChild(void *fileHandle, void *bookmark)
{
return nullptr;
}
//public static extern IntPtr FPDFBookmark_GetNextSibling(IntPtr document, IntPtr bookmark);
OFDIUMEX_API void *OFDIUM_Bookmark_GetNextSibling(void *fileHandle, void *bookmark)
{
return nullptr;
}
//public static extern uint FPDFBookmark_GetTitle(IntPtr bookmark, byte[] buffer, uint buflen);
OFDIUMEX_API unsigned long OFDIUM_Bookmark_GetTitle(void *bookmark, void *buffer, unsigned long buflen)
{
return NULL;
}
//public static extern IntPtr FPDFBookmark_GetAction(IntPtr bookmark);
OFDIUMEX_API void *OFDIUM_Bookmark_GetAction(void *bookmark)
{
return nullptr;
}
//public static extern IntPtr FPDFBookmark_GetDest(IntPtr document, IntPtr bookmark);
OFDIUMEX_API void *OFDIUM_Bookmark_GetDest(void *fileHandle, void *bookmark)
{
return nullptr;
}
//public static extern uint FPDFAction_GetType(IntPtr action);
OFDIUMEX_API unsigned long OFDIUM_Action_GetType(void *action)
{
return NULL;
}
//public static extern uint FPDF_GetLastError();
OFDIUMEX_API unsigned long OFDIUM_GetLastError()
{
return 0;
}
//public static extern uint FPDF_GetMetaText(IntPtr document, string tag, byte[] buffer, uint buflen);
OFDIUMEX_API unsigned long OFDIUM_GetMetaText(void *fileHandle, char *tag, void *buffer, unsigned long buflen)
{
return NULL;
}
//public static extern void FPDF_FFLDraw(IntPtr form, IntPtr bitmap, IntPtr page, int start_x, int start_y, int size_x, int size_y, int rotate, FPDF flags);
OFDIUMEX_API void OFDIUM_FFLDraw(void *form, void *bitmap, void *page, int start_x, int start_y, int size_x, int size_y, int rotate, int flags)
{
}
//public static extern void FPDF_FFLDrawEx(IntPtr form, IntPtr bitmap, IntPtr page, int start_x, int start_y, int size_x, int size_y, int rotate, FPDF flags, string strJson);
OFDIUMEX_API void OFDIUM_FFLDrawEx(void *form, void *bitmap, void *page, int start_x, int start_y, int size_x, int size_y, int rotate, int flags, char *strJson)
{
}
//
OFDIUMEX_API int OFDIUM_GetDocumentPageWidth(void *fileHandle, int pageIndex)
{
if (listOpenedOFD.find((OFD *)fileHandle) == listOpenedOFD.end())
{
return -1;
}
auto *ofd = (OFD *)fileHandle;
if (ofd->documents.size() != 1)
{
return -1;
}
Document *doc = ofd->documents[0];
if ((int)doc->pages.size() - 1 < pageIndex || doc->pages[pageIndex].second == nullptr)
{
return -1;
}
Page *page = doc->pages[pageIndex].second;
int page_w = page->area == nullptr ? INTMM2PIXEL72P(doc->commonData->pageArea->physicalBox->w) : INTMM2PIXEL72P(page->area->physicalBox->w);
return page_w;
}
OFDIUMEX_API int OFDIUM_GetDocumentPageHeight(void *fileHandle, int pageIndex)
{
if (listOpenedOFD.find((OFD *)fileHandle) == listOpenedOFD.end())
{
return -1;
}
auto *ofd = (OFD *)fileHandle;
if (ofd->documents.size() != 1)
{
return -1;
}
Document *doc = ofd->documents[0];
if ((int)doc->pages.size() - 1 < pageIndex || doc->pages[pageIndex].second == nullptr)
{
return -1;
}
Page *page = doc->pages[pageIndex].second;
int page_h = page->area == nullptr ? INTMM2PIXEL72P(doc->commonData->pageArea->physicalBox->h) : INTMM2PIXEL72P(page->area->physicalBox->h);
return page_h;
}
void renderSealToCairoDevice(Document_Page *docpage, Signatures *signatures, cairo_t *cr)
{
for (std::pair<Signatures_Signature *, Signature *> ss : signatures->signatures)
{
for (StampAnnot *sa : ss.second->signedInfo->stampAnnots)
{
if (docpage->id == sa->pageRef)
{
SignedValue *signedValue = ss.second->signedValue.second;
V4_SES_Signature *v4_ses_signature = V4_SES_Signature_new();
const unsigned char *tmp = signedValue->val;
//std::ofstream outfile;
//outfile.open("s.data");
//outfile.write((const char *)signedValue->val, signedValue->len);
//outfile.flush();
//outfile.close();
d2i_V4_SES_Signature(&v4_ses_signature, &tmp, signedValue->len);
//print_errors();
SES_Signature *v1_ses_signature = SES_Signature_new();
if (v4_ses_signature==NULL)
{
d2i_SES_Signature(&v1_ses_signature, &tmp, signedValue->len);
if (v1_ses_signature == NULL)
{
continue;
}
}
unsigned char *imgdata = v4_ses_signature != NULL ? v4_ses_signature->toSign->eseal->esealInfo->picture->data->data : v1_ses_signature->toSign->eseal->esealInfo->picture->data->data;
int imglen = v4_ses_signature != NULL ? v4_ses_signature->toSign->eseal->esealInfo->picture->data->length : v1_ses_signature->toSign->eseal->esealInfo->picture->data->length;
st_png_data pngData = { (unsigned char*)imgdata, 0 };
cairo_move_to(cr, MM2PIXEL(sa->boundary->x), MM2PIXEL(sa->boundary->y));
std::string imgtype;
imgtype.assign((char *)(v4_ses_signature != NULL ? v4_ses_signature->toSign->eseal->esealInfo->picture->type->data : v1_ses_signature->toSign->eseal->esealInfo->picture->type->data), v4_ses_signature != NULL ? v4_ses_signature->toSign->eseal->esealInfo->picture->type->length : v1_ses_signature->toSign->eseal->esealInfo->picture->type->length);
if (_stricmp(imgtype.c_str(), "PNG") == 0)
{
//FILE *f = NULL;
//fopen_s(&f, "save.png", "wb+");
//fwrite(imgdata, 1, imglen, f);
//fflush(f);
//fclose(f);
cairo_save(cr);
cairo_surface_t *imagesurface = cairo_image_surface_create_from_png_stream(cairo_read_func_mine, &pngData);
cairo_t *crimg = cairo_create(imagesurface);
int image_w = cairo_image_surface_get_width(imagesurface);
int image_h = cairo_image_surface_get_height(imagesurface);
int boundary_w = INTMM2PIXEL(sa->boundary->w);
int boundary_h = INTMM2PIXEL(sa->boundary->h);
double factor_w = (double)boundary_w / (double)image_w;
double factor_h = (double)boundary_h / (double)image_h;
cairo_scale(cr, factor_w, factor_h);
imagesurface = cairo_get_target(crimg);
int image_w2 = cairo_image_surface_get_width(imagesurface);
int image_h2 = cairo_image_surface_get_height(imagesurface);
if (sa->clip)
{
double clip_x = MM2PIXEL(sa->boundary->x + sa->clip->x) / factor_w;
double clip_y = MM2PIXEL(sa->boundary->y + sa->clip->y) / factor_h;
double clip_w = MM2PIXEL(sa->clip->w) / factor_w;
double clip_h = MM2PIXEL(sa->clip->h) / factor_h;
cairo_rectangle(cr, clip_x, clip_y, clip_w, clip_h);
cairo_clip(cr);
}
cairo_set_source_surface(cr, imagesurface, MM2PIXEL(sa->boundary->x) / factor_w, MM2PIXEL(sa->boundary->y) / factor_h);
cairo_paint(cr);
cairo_surface_destroy(imagesurface);
cairo_restore(cr);
}
else if (_stricmp(imgtype.c_str(), "OFD") == 0)
{
cairo_save(cr);
cairo_surface_t *imagesurface = (cairo_surface_t *)cairo_image_surface_create_from_ofd_stream(imgdata, imglen, INTMM2PIXEL(ASN1_INTEGER_get(v4_ses_signature->toSign->eseal->esealInfo->picture->width)), INTMM2PIXEL(ASN1_INTEGER_get(v4_ses_signature->toSign->eseal->esealInfo->picture->height)));
if (imagesurface)
{
cairo_t *crimg = cairo_create(imagesurface);
int image_w = cairo_image_surface_get_width(imagesurface);
int image_h = cairo_image_surface_get_height(imagesurface);
int boundary_w = INTMM2PIXEL(sa->boundary->w);
int boundary_h = INTMM2PIXEL(sa->boundary->h);
double factor_w = (double)boundary_w / (double)image_w;
double factor_h = (double)boundary_h / (double)image_h;
cairo_scale(cr, factor_w, factor_h);
imagesurface = cairo_get_target(crimg);
int image_w2 = cairo_image_surface_get_width(imagesurface);
int image_h2 = cairo_image_surface_get_height(imagesurface);
if (sa->clip)
{
double clip_x = MM2PIXEL(sa->boundary->x + sa->clip->x) / factor_w;
double clip_y = MM2PIXEL(sa->boundary->y + sa->clip->y) / factor_h;
double clip_w = MM2PIXEL(sa->clip->w) / factor_w;
double clip_h = MM2PIXEL(sa->clip->h) / factor_h;
cairo_rectangle(cr, clip_x, clip_y, clip_w, clip_h);
cairo_clip(cr);
}
cairo_set_source_surface(cr, imagesurface, MM2PIXEL(sa->boundary->x) / factor_w, MM2PIXEL(sa->boundary->y) / factor_h);
cairo_paint(cr);
cairo_surface_destroy(imagesurface);
}
cairo_restore(cr);
}
SES_Signature_free(v1_ses_signature);
V4_SES_Signature_free(v4_ses_signature);
}
}
}
}
void renderDocumentTemplatePageToCairoDevice(OFD *ofd, Document* doc, cairo_t *cr)
{
if (doc == NULL || doc->commonData == NULL || doc->commonData->templatePages.size() == 0 || ofd == NULL)
{
return;
}
for (size_t ti = 0; ti < doc->commonData->templatePages.size();ti++)
{
for (std::pair<ST_ID, CT_Layer*> layerpair : doc->commonData->templatePages[ti].second->content->layers)
{
for (std::pair<CT_PageBlock::TYPE, CT_PageBlock::Data *> pageblockobject : layerpair.second->ct_pageBlock->d)
{
if (pageblockobject.first == CT_PageBlock::TYPE::TEXTOBJECT)
{
cairo_save(cr);
CT_Font *font = ofd->resAll->at(pageblockobject.second->textObject->ct_text->font).second->font;
std::string family = font->familyName.empty() ? "SimSun" : font->familyName;
cairo_surface_t *crtextsurface = cairo_image_surface_create(cairo_format_t::CAIRO_FORMAT_ARGB32, INTMM2PIXEL(pageblockobject.second->textObject->ct_text->ct_graphicUnit->boundary->w), INTMM2PIXEL(pageblockobject.second->textObject->ct_text->ct_graphicUnit->boundary->h));
cairo_t *cttext = cairo_create(crtextsurface);
cairo_font_options_t *option = cairo_font_options_create();
cairo_font_options_set_antialias(option, cairo_antialias_t::CAIRO_ANTIALIAS_BEST);
cairo_set_font_options(cttext, option);
cairo_select_font_face(cttext,
family.c_str(),
font->italic ? CAIRO_FONT_SLANT_ITALIC : CAIRO_FONT_SLANT_NORMAL,
font->bold || pageblockobject.second->textObject->ct_text->weight >= 700 ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL);
double ptSize = MM2PIXEL(pageblockobject.second->textObject->ct_text->size);
cairo_set_font_size(cttext, ptSize);
//TRACE("%d,%d,%d,%d\r\n", pageblockobject.second.textObject->ct_text->fillColor->valueR, pageblockobject.second.textObject->ct_text->fillColor->valueG, pageblockobject.second.textObject->ct_text->fillColor->valueB, pageblockobject.second.textObject->ct_text->fillColor->alpha);
cairo_set_source_rgba(cttext, pageblockobject.second->textObject->ct_text->fillColor->valueR, pageblockobject.second->textObject->ct_text->fillColor->valueG, pageblockobject.second->textObject->ct_text->fillColor->valueB, pageblockobject.second->textObject->ct_text->fillColor->alpha);
for (TextCode_And_CT_CGTransform* textcode_and_ct_cgtransform : pageblockobject.second->textObject->ct_text->textcode_and_ct_cgtransforms)
{
if (pageblockobject.second->textObject->ct_text->ct_graphicUnit->cTM != NULL)
{
cairo_matrix_t *ctm = new cairo_matrix_t();
ct_matrix_to_cairo_matrix(pageblockobject.second->textObject->ct_text->ct_graphicUnit->cTM, ctm);
cairo_set_matrix(cttext, ctm);
delete ctm;
}
if (textcode_and_ct_cgtransform->textCode->deltaX.size() > 1 || textcode_and_ct_cgtransform->textCode->deltaY.size() > 1)
{
std::vector<std::string> vec;
fnReadCharactersUTF8(textcode_and_ct_cgtransform->textCode->str.c_str(), vec);
double x0 = MM2PIXEL(textcode_and_ct_cgtransform->textCode->x);
double y0 = MM2PIXEL(textcode_and_ct_cgtransform->textCode->y);
double toMoveX = x0;
double toMoveY = y0;
for (size_t i = 0; i < vec.size(); i++)
{
std::string strCh = vec[i];
double deltaX = i < textcode_and_ct_cgtransform->textCode->deltaX.size() ? (MM2PIXEL(textcode_and_ct_cgtransform->textCode->deltaX[i])) : 0.0f;
double deltaY = i < textcode_and_ct_cgtransform->textCode->deltaY.size() ? (MM2PIXEL(textcode_and_ct_cgtransform->textCode->deltaY[i])) : 0.0f;
toMoveX += deltaX;
toMoveY += deltaY;
{
cairo_move_to(
cttext,
toMoveX,
toMoveY);
cairo_show_text(cttext, strCh.c_str());
}
}
}
else
{
cairo_move_to(cttext, MM2PIXEL(textcode_and_ct_cgtransform->textCode->x), MM2PIXEL(textcode_and_ct_cgtransform->textCode->y));
cairo_show_text(cttext, textcode_and_ct_cgtransform->textCode->str.c_str());
}
}
//char tmp[MAX_PATH] = { 0 };
//itoa(ii, tmp, 10);
//std::string outpath = tmp;
//outpath += ".png";
//cairo_surface_write_to_png(crtextsurface, outpath.c_str());
//ii++;
cairo_set_source_surface(cr, crtextsurface, MM2PIXEL(pageblockobject.second->textObject->ct_text->ct_graphicUnit->boundary->x), MM2PIXEL(pageblockobject.second->textObject->ct_text->ct_graphicUnit->boundary->y));
cairo_paint(cr);
cairo_restore(cr);
}
else if (pageblockobject.first == CT_PageBlock::TYPE::IMAGEOBJECT)
{
cairo_move_to(cr, MM2PIXEL(pageblockobject.second->imageObject->ct_imageObject->ct_graphicUnit->boundary->x), MM2PIXEL(pageblockobject.second->imageObject->ct_imageObject->ct_graphicUnit->boundary->y));
if (ofd->resAll->find(pageblockobject.second->imageObject->ct_imageObject->resourceID) != ofd->resAll->end())
{
CT_MultiMedia *multimedia = ofd->resAll->at(pageblockobject.second->imageObject->ct_imageObject->resourceID).second->multiMedia;
if (multimedia->format.compare("PNG") == 0)
{
cairo_save(cr);
cairo_surface_t *imagesurface = cairo_image_surface_create_from_png(multimedia->MediaFile->abs.c_str());
cairo_t *crimg = cairo_create(imagesurface);
int image_w = cairo_image_surface_get_width(imagesurface);
int image_h = cairo_image_surface_get_height(imagesurface);
int boundary_w = INTMM2PIXEL(pageblockobject.second->imageObject->ct_imageObject->ct_graphicUnit->boundary->w);
int boundary_h = INTMM2PIXEL(pageblockobject.second->imageObject->ct_imageObject->ct_graphicUnit->boundary->h);
double factor_w = (double)boundary_w / (double)image_w;
double factor_h = (double)boundary_h / (double)image_h;
cairo_scale(cr, factor_w, factor_h);
imagesurface = cairo_get_target(crimg);
int image_w2 = cairo_image_surface_get_width(imagesurface);
int image_h2 = cairo_image_surface_get_height(imagesurface);
cairo_set_source_surface(cr, imagesurface, MM2PIXEL(pageblockobject.second->imageObject->ct_imageObject->ct_graphicUnit->boundary->x), MM2PIXEL(pageblockobject.second->imageObject->ct_imageObject->ct_graphicUnit->boundary->y));
cairo_paint(cr);
cairo_surface_destroy(imagesurface);
cairo_restore(cr);
}
else if (multimedia->format.compare("JB2") == 0)
{
cairo_save(cr);
int image_w = 0;
int image_h = 0;
unsigned char*tmp = NULL;
cairo_surface_t *imagesurface = cairo_image_surface_create_from_jbig2(multimedia->MediaFile->abs.c_str(), &image_w, &image_h, &tmp);
cairo_t *crimg = cairo_create(imagesurface);
//int image_w = cairo_image_surface_get_width(imagesurface);
//int image_h = cairo_image_surface_get_height(imagesurface);
int boundary_w = INTMM2PIXEL(pageblockobject.second->imageObject->ct_imageObject->ct_graphicUnit->boundary->w);
int boundary_h = INTMM2PIXEL(pageblockobject.second->imageObject->ct_imageObject->ct_graphicUnit->boundary->h);
double factor_w = (double)boundary_w / (double)image_w;
double factor_h = (double)boundary_h / (double)image_h;
cairo_scale(cr, factor_w, factor_h);
imagesurface = cairo_get_target(crimg);
int image_w2 = cairo_image_surface_get_width(imagesurface);
int image_h2 = cairo_image_surface_get_height(imagesurface);
double image_x = MM2PIXEL(pageblockobject.second->imageObject->ct_imageObject->ct_graphicUnit->boundary->x) / factor_w;
double image_y = MM2PIXEL(pageblockobject.second->imageObject->ct_imageObject->ct_graphicUnit->boundary->y) / factor_h;
//char tmp[MAX_PATH] = { 0 };
//_itoa_s(ii, tmp, 10);
//std::string outpath = tmp;
//outpath += ".png";
//cairo_surface_write_to_png(imagesurface, outpath.c_str());
//ii++;
cairo_set_source_surface(cr, imagesurface, image_x, image_y);
cairo_paint(cr);
cairo_surface_destroy(imagesurface);
free(tmp);
cairo_restore(cr);
}
else
{
cairo_save(cr);
cairo_surface_t *imagesurface = cairo_image_surface_create_from_jpeg(multimedia->MediaFile->abs.c_str(), &listUsedImage, &g_gdiplusToken);
cairo_t *crimg = cairo_create(imagesurface);
int image_w = cairo_image_surface_get_width(imagesurface);
int image_h = cairo_image_surface_get_height(imagesurface);
int boundary_w = INTMM2PIXEL(pageblockobject.second->imageObject->ct_imageObject->ct_graphicUnit->boundary->w);
int boundary_h = INTMM2PIXEL(pageblockobject.second->imageObject->ct_imageObject->ct_graphicUnit->boundary->h);
double factor_w = (double)boundary_w / (double)image_w;
double factor_h = (double)boundary_h / (double)image_h;
cairo_scale(cr, factor_w, factor_h);
imagesurface = cairo_get_target(crimg);
int image_w2 = cairo_image_surface_get_width(imagesurface);
int image_h2 = cairo_image_surface_get_height(imagesurface);
double image_x = MM2PIXEL(pageblockobject.second->imageObject->ct_imageObject->ct_graphicUnit->boundary->x) / factor_w;
double image_y = MM2PIXEL(pageblockobject.second->imageObject->ct_imageObject->ct_graphicUnit->boundary->y) / factor_h;
cairo_set_source_surface(cr, imagesurface, image_x, image_y);
cairo_paint(cr);
cairo_image_surface_delete_from_jpeg(imagesurface, &listUsedImage, &g_gdiplusToken);
cairo_surface_destroy(imagesurface);
cairo_restore(cr);
}
}
}
else if (pageblockobject.first == CT_PageBlock::TYPE::PATHOBJECT)
{
cairo_move_to(cr, MM2PIXEL(pageblockobject.second->pathObject->ct_path->ct_graphicUnit->boundary->x), MM2PIXEL(pageblockobject.second->pathObject->ct_path->ct_graphicUnit->boundary->y));
cairo_save(cr);
cairo_surface_t *imagesurface = cairo_image_surface_create(cairo_format_t::CAIRO_FORMAT_ARGB32, INTMM2PIXEL(pageblockobject.second->pathObject->ct_path->ct_graphicUnit->boundary->w), INTMM2PIXEL(pageblockobject.second->pathObject->ct_path->ct_graphicUnit->boundary->h));
cairo_t *crimg = cairo_create(imagesurface);
double x0 = 0.0f;
double y0 = 0.0f;
for (AbbreviatedData * abb : pageblockobject.second->pathObject->ct_path->abbreviatedData)
{
if (abb->cMd.compare("S") == 0)
{
double x0 = abb->params[0];
double y0 = abb->params[1];
}
else if (abb->cMd.compare("M") == 0)
{
double x = abb->params[0];
double y = abb->params[1];
cairo_move_to(crimg, MM2PIXEL(x), MM2PIXEL(y));
}
else if (abb->cMd.compare("L") == 0)
{
double x = abb->params[0];
double y = abb->params[1];
cairo_line_to(crimg, MM2PIXEL(x), MM2PIXEL(y));
}
else if (abb->cMd.compare("Q") == 0)
{
double x1 = abb->params[0];
double y1 = abb->params[1];
double x2 = abb->params[2];
double y2 = abb->params[3];
cairo_quadratic_to(crimg, MM2PIXEL(x1), MM2PIXEL(y1), MM2PIXEL(x2), MM2PIXEL(y2));
}
else if (abb->cMd.compare("B") == 0)
{
double x1 = abb->params[0];
double y1 = abb->params[1];
double x2 = abb->params[2];
double y2 = abb->params[3];
double x3 = abb->params[4];
double y3 = abb->params[5];
cairo_curve_to(crimg, MM2PIXEL(x1), MM2PIXEL(y1), MM2PIXEL(x2), MM2PIXEL(y2), MM2PIXEL(x3), MM2PIXEL(y3));
}
else if (abb->cMd.compare("A") == 0)
{
double rx = abb->params[0];
double ry = abb->params[1];
double angle1 = abb->params[2];
double large = abb->params[3];
double sweep = abb->params[4];
double x = abb->params[5];
double y = abb->params[6];
//TODO 只会已知原点和长短轴及起始终止角度的椭圆圆弧
double x2, y2;
cairo_get_current_point(crimg, &x2, &y2);
cairo_quadratic_to(crimg, x2, y2, MM2PIXEL(x), MM2PIXEL(y));
}
else if (abb->cMd.compare("C") == 0)
{
cairo_close_path(crimg);
}
else
{
continue;
}
}
if (pageblockobject.second->pathObject->ct_path->stroke)
{
cairo_set_source_rgba(crimg, pageblockobject.second->pathObject->ct_path->strokeColor->valueR, pageblockobject.second->pathObject->ct_path->strokeColor->valueG, pageblockobject.second->pathObject->ct_path->strokeColor->valueB, pageblockobject.second->pathObject->ct_path->strokeColor->alpha);
cairo_stroke(crimg);
}
if (pageblockobject.second->pathObject->ct_path->fill)
{
cairo_set_source_rgba(crimg, pageblockobject.second->pathObject->ct_path->fillColor->valueR, pageblockobject.second->pathObject->ct_path->fillColor->valueG, pageblockobject.second->pathObject->ct_path->fillColor->valueB, pageblockobject.second->pathObject->ct_path->fillColor->alpha);
cairo_stroke(crimg);
}
cairo_set_source_surface(cr, imagesurface, MM2PIXEL(pageblockobject.second->pathObject->ct_path->ct_graphicUnit->boundary->x), MM2PIXEL(pageblockobject.second->pathObject->ct_path->ct_graphicUnit->boundary->y));
cairo_paint(cr);
cairo_surface_destroy(imagesurface);
cairo_restore(cr);
}
}
}
}
//char tmp[MAX_PATH] = { 0 };
//itoa(ii, tmp, 10);
//std::string outpath = tmp;
//outpath += ".png";
//cairo_surface_write_to_png(cairo_get_target(cr), outpath.c_str());
//ii++;
}
OFDIUMEX_API void OFDIUM_GetDocumentPagePNG(void *fileHandle, int pageIndex, int width, int height, unsigned char *pngData, int *pngDataLen)
{
if (pngData==nullptr)
{
*pngDataLen = width * height * 4;
return;
}
if (listOpenedOFD.find((OFD *)fileHandle) == listOpenedOFD.end())
{
return;
}
auto *ofd = (OFD *)fileHandle;
if (ofd->documents.size() != 1)
{
return;
}
Document *doc = ofd->documents[0];
if ((int)doc->pages.size() - 1 < pageIndex || doc->pages[pageIndex].second == nullptr)
{
return;
}
Page *page = doc->pages[pageIndex].second;
Document_Page *docpage = doc->pages[pageIndex].first;
cairo_surface_t *surface, *surfaceTarget;
cairo_t *cr, *crtarget;
int page_w = page->area == nullptr ? INTMM2PIXEL(doc->commonData->pageArea->physicalBox->w) : INTMM2PIXEL(page->area->physicalBox->w);
int page_h = page->area == nullptr ? INTMM2PIXEL(doc->commonData->pageArea->physicalBox->h) : INTMM2PIXEL(page->area->physicalBox->h);
int page_x = page->area == nullptr ? INTMM2PIXEL(doc->commonData->pageArea->physicalBox->x) : INTMM2PIXEL(page->area->physicalBox->x);
int page_y = page->area == nullptr ? INTMM2PIXEL(doc->commonData->pageArea->physicalBox->y) : INTMM2PIXEL(page->area->physicalBox->y);
surfaceTarget = cairo_image_surface_create(cairo_format_t::CAIRO_FORMAT_ARGB32, width, height);
crtarget = cairo_create(surfaceTarget);
surface = cairo_image_surface_create(cairo_format_t::CAIRO_FORMAT_ARGB32, page_w, page_h);
cr = cairo_create(surface);
//cairo_set_source_rgba(cr, 255, 255, 255, 255);
//cairo_rectangle(cr, page_x, page_y, page_w, page_h);
//cairo_fill(cr);
renderDocumentTemplatePageToCairoDevice(ofd, doc, cr);
//char tmp[MAX_PATH] = { 0 };
//itoa(ii, tmp, 10);
//std::string outpath = tmp;
//outpath += ".png";
//cairo_surface_write_to_png(cairo_get_target(cr), outpath.c_str());
//ii++;
for (std::pair<ST_ID, CT_Layer*> layerpair : page->content->layers)
{
for (std::pair<CT_PageBlock::TYPE, CT_PageBlock::Data*> pageblockobject : layerpair.second->ct_pageBlock->d)
{
if (pageblockobject.first == CT_PageBlock::TYPE::TEXTOBJECT)
{
cairo_save(cr);
CT_Font *font = ofd->resAll->at(pageblockobject.second->textObject->ct_text->font).second->font;
std::string family = font->familyName.empty() ? (font->fontName.empty() ? "SimSun" : font->fontName) : font->familyName;
cairo_surface_t *crtextsurface = cairo_image_surface_create(cairo_format_t::CAIRO_FORMAT_ARGB32, INTMM2PIXEL(pageblockobject.second->textObject->ct_text->ct_graphicUnit->boundary->w), INTMM2PIXEL(pageblockobject.second->textObject->ct_text->ct_graphicUnit->boundary->h));
cairo_t *cttext = cairo_create(crtextsurface);
cairo_font_options_t *option = cairo_font_options_create();
cairo_font_options_set_antialias(option, cairo_antialias_t::CAIRO_ANTIALIAS_BEST);
cairo_set_font_options(cttext, option);
cairo_select_font_face(cttext,
family.c_str(),
font->italic ? CAIRO_FONT_SLANT_ITALIC : CAIRO_FONT_SLANT_NORMAL,
font->bold || pageblockobject.second->textObject->ct_text->weight >= 700 ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL);
double ptSize = MM2PIXEL(pageblockobject.second->textObject->ct_text->size);
cairo_set_font_size(cttext, ptSize);
//TRACE("%d,%d,%d,%d\r\n", pageblockobject.second.textObject->ct_text->fillColor->valueR, pageblockobject.second.textObject->ct_text->fillColor->valueG, pageblockobject.second.textObject->ct_text->fillColor->valueB, pageblockobject.second.textObject->ct_text->fillColor->alpha);
cairo_set_source_rgba(cttext, pageblockobject.second->textObject->ct_text->fillColor->valueR, pageblockobject.second->textObject->ct_text->fillColor->valueG, pageblockobject.second->textObject->ct_text->fillColor->valueB, pageblockobject.second->textObject->ct_text->fillColor->alpha);
for (TextCode_And_CT_CGTransform* textcode_and_ct_cgtransform : pageblockobject.second->textObject->ct_text->textcode_and_ct_cgtransforms)
{
if (pageblockobject.second->textObject->ct_text->ct_graphicUnit->cTM != NULL)
{
cairo_matrix_t *ctm = new cairo_matrix_t();
ct_matrix_to_cairo_matrix(pageblockobject.second->textObject->ct_text->ct_graphicUnit->cTM, ctm);
cairo_set_matrix(cttext, ctm);
delete ctm;
}
if (textcode_and_ct_cgtransform->textCode->deltaX.size() > 1 || textcode_and_ct_cgtransform->textCode->deltaY.size() > 1)
{
std::vector<std::string> vec;
fnReadCharactersUTF8(textcode_and_ct_cgtransform->textCode->str.c_str(), vec);
double x0 = MM2PIXEL(textcode_and_ct_cgtransform->textCode->x);
double y0 = MM2PIXEL(textcode_and_ct_cgtransform->textCode->y);
double toMoveX = x0;
double toMoveY = y0;
for (size_t i = 0; i < vec.size(); i++)
{
std::string strCh = vec[i];
double deltaX = i < textcode_and_ct_cgtransform->textCode->deltaX.size() ? (MM2PIXEL(textcode_and_ct_cgtransform->textCode->deltaX[i])) : 0;
double deltaY = i < textcode_and_ct_cgtransform->textCode->deltaY.size() ? (MM2PIXEL(textcode_and_ct_cgtransform->textCode->deltaY[i])) : 0;
toMoveX += deltaX;
toMoveY += deltaY;
{
cairo_move_to(
cttext,
toMoveX,
toMoveY);
cairo_show_text(cttext, strCh.c_str());
}
}
}
else
{
cairo_move_to(cttext, MM2PIXEL(textcode_and_ct_cgtransform->textCode->x), MM2PIXEL(textcode_and_ct_cgtransform->textCode->y));