Myo Scol plugin
Loading...
Searching...
No Matches
scolplugin.cpp
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2014 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25/*
26 PDF document generator for Scol
27 First version : October 2014
28 Author : Bastien BOURINEAU - I-Maginer
29*/
30
31#include "sPdf.h"
32#include <scolMemoryHelper.hpp>
33#include <cmath>
34
36#ifdef SCOL_STATIC
37extern cbmachine ww;
38extern mmachine mm;
39#else
40cbmachine ww;
41mmachine mm;
42#endif
43
44int OBJ_PDFDOC_SCOL;
45int OBJ_PDFPAGE_SCOL;
46
69int destroyPdfObj(mmachine m, SCOL_PTR_TYPE handsys, int handscol)
70{
71 SPdfDoc* pdfdoc = MMgetPointer<SPdfDoc*>(m, MTOP(handscol));
72 SAFE_DELETE(pdfdoc);
73
74 MMsetPointer<SPdfDoc*>(m, MTOP(handscol), 0);
75
76 // Display debug message
77 MMechostr(MSKDEBUG, "ObjPdfDoc destroyed.\n");
78 return 0;
79}
80
81
88int destroyPdfPageObj(mmachine m, SCOL_PTR_TYPE handsys, int handscol)
89{
90 HPDF_Page pdfpage = MMgetPointer<HPDF_Page>(m, MTOP(handscol));
91 MMsetPointer<HPDF_Page>(m, MTOP(handscol), 0);
92
93 // Display debug message
94 MMechostr(MSKDEBUG, "ObjPdfPage destroyed.\n");
95 return 0;
96}
97
98
111int _CRpdfDocument(mmachine m)
112{
113#ifdef _SCOL_DEBUG_
114 MMechostr(0,"_CRpdfDocument\n");
115#endif
116 // Declare local variables
117 int k = 0;
118
119 int pDpi = MMpull(m);
120 int pAuthor = MMpull(m);
121 int pCreator = MMpull(m);
122 int pTitle = MMpull(m);
123
124 // Get the channel without pulling it (first element in the stack)
125 int channel = MMget(m, 0);
126
127 // Test the channel
128 if (channel == NIL)
129 {
130 MMechostr(MSKDEBUG, "_CRpdfDocument : Channel NIL\n");
131 return 0;
132 }
133
134 std::string title = MMstartstr(m, MTOP(pTitle));
135 std::string creator = MMstartstr(m, MTOP(pCreator));
136 std::string author = MMstartstr(m, MTOP(pAuthor));
137
138 unsigned int dpiRes = 72;
139 if (pDpi != NIL)
140 dpiRes = std::abs(MTOI(pDpi));
141
142 SPdfDoc* pdfdoc = new SPdfDoc(title, creator, author, dpiRes);
143 if (pdfdoc == NULL)
144 {
145 MMechostr(MSKDEBUG, "_CRpdfDocument : new PDF document failed\n");
146 MMset(m, 0, NIL);
147 return 0;
148 }
149
150 // Allocate a space in the stack for a table
151 if ((MMpushPointer(m, pdfdoc) != 0))
152 {
153 SAFE_DELETE(pdfdoc);
154 MMset(m, 0, NIL);
155 return MERRMEM;
156 }
157
158 // Create a new scol myo object
159 k = OBJcreate(m, OBJ_PDFDOC_SCOL, SCOL_PTR pdfdoc, NIL, 0);
160
161#ifdef _SCOL_DEBUG_
162 MMechostr(0,"ok\n");
163#endif
164
165 return k;
166}
167
175int _DSpdfDocument(mmachine m)
176{
177#ifdef _SCOL_DEBUG_
178 MMechostr(MSKDEBUG,"_DSpdfDocument\n");
179#endif
180
181 int pdfTab = MMget(m, 0);
182 if (pdfTab == NIL)
183 {
184 MMset(m, 0, NIL);
185 return 0;
186 }
187
188 OBJdelTM(m, OBJ_PDFDOC_SCOL, pdfTab);
189 MMset(m, 0, ITOM(0));
190
191#ifdef _SCOL_DEBUG_
192 MMechostr(MSKDEBUG,"ok\n");
193#endif
194 return 0;
195}
196
197
236{
237#ifdef _SCOL_DEBUG_
238 MMechostr(MSKDEBUG,"_SetPdfDocumentCharset\n");
239#endif
240
241 int pCharset = MMpull(m);
242 int pdfTab = MMget(m, 0);
243 if ((pdfTab == NIL) || (pCharset == NIL))
244 {
245 MMset(m, 0, NIL);
246 return 0;
247 }
248
249 SPdfDoc* pdfdoc = MMgetPointer<SPdfDoc*>(m, MTOP(pdfTab));
250 if (!pdfdoc)
251 {
252 MMset(m, 0, NIL);
253 return 0;
254 }
255
256 std::string charset = MMstartstr(m, MTOP(pCharset));
257 try
258 {
259 pdfdoc->SetCharset(charset);
260 }
261 catch(std::exception &)
262 {
263 MMset(m, 0, NIL);
264 return 0;
265 }
266
267 MMset(m, 0, ITOM(0));
268
269#ifdef _SCOL_DEBUG_
270 MMechostr(MSKDEBUG,"ok\n");
271#endif
272 return 0;
273}
274
275
284int _SavePdfDocument(mmachine m)
285{
286#ifdef _SCOL_DEBUG_
287 MMechostr(MSKDEBUG,"_SavePdfDocument\n");
288#endif
289
290 int pFile = MMpull(m);
291 int pdfTab = MMget(m, 0);
292 if ((pdfTab == NIL) || (pFile == NIL))
293 {
294 MMset(m, 0, NIL);
295 return 0;
296 }
297
298 SPdfDoc* pdfdoc = MMgetPointer<SPdfDoc*>(m, MTOP(pdfTab));
299 if (!pdfdoc)
300 {
301 MMset(m, 0, NIL);
302 return 0;
303 }
304
305 std::string path = MMstartstr(m, MTOP(pFile));
306 try
307 {
308 pdfdoc->SaveToFile(path);
309 }
310 catch(std::exception &)
311 {
312 MMset(m, 0, NIL);
313 return 0;
314 }
315
316 MMset(m, 0, ITOM(0));
317
318#ifdef _SCOL_DEBUG_
319 MMechostr(MSKDEBUG,"ok\n");
320#endif
321 return 0;
322}
323
324
338int _SetPdfPageMode(mmachine m)
339{
340#ifdef _SCOL_DEBUG_
341 MMechostr(MSKDEBUG,"_SetPdfPageMode\n");
342#endif
343
344 int pMode = MMpull(m);
345 int pdfTab = MMget(m, 0);
346 if ((pdfTab == NIL) || (pMode == NIL))
347 {
348 MMset(m, 0, NIL);
349 return 0;
350 }
351
352 SPdfDoc* pdfdoc = MMgetPointer<SPdfDoc*>(m, MTOP(pdfTab));
353 if (!pdfdoc)
354 {
355 MMset(m, 0, NIL);
356 return 0;
357 }
358
359 int mode = MTOI(pMode);
360 try
361 {
362 pdfdoc->SetPageMode((HPDF_PageMode)mode);
363 }
364 catch(std::exception &)
365 {
366 MMset(m, 0, NIL);
367 return 0;
368 }
369
370 MMset(m, 0, ITOM(0));
371
372#ifdef _SCOL_DEBUG_
373 MMechostr(MSKDEBUG,"ok\n");
374#endif
375 return 0;
376}
377
378
394int _SetPdfLayoutMode(mmachine m)
395{
396#ifdef _SCOL_DEBUG_
397 MMechostr(MSKDEBUG,"_SetPdfLayoutMode\n");
398#endif
399
400 int pMode = MMpull(m);
401 int pdfTab = MMget(m, 0);
402 if ((pdfTab == NIL) || (pMode == NIL))
403 {
404 MMset(m, 0, NIL);
405 return 0;
406 }
407
408 SPdfDoc* pdfdoc = MMgetPointer<SPdfDoc*>(m, MTOP(pdfTab));
409 if (!pdfdoc)
410 {
411 MMset(m, 0, NIL);
412 return 0;
413 }
414
415 int mode = MTOI(pMode);
416 try
417 {
418 pdfdoc->SetPageLayout((HPDF_PageLayout)mode);
419 }
420 catch(std::exception &)
421 {
422 MMset(m, 0, NIL);
423 return 0;
424 }
425
426 MMset(m, 0, ITOM(0));
427
428#ifdef _SCOL_DEBUG_
429 MMechostr(MSKDEBUG,"ok\n");
430#endif
431 return 0;
432}
433
434
443int _LoadPdfTrueTypeFont(mmachine m)
444{
445#ifdef _SCOL_DEBUG_
446 MMechostr(MSKDEBUG,"_LoadPdfTrueTypeFont\n");
447#endif
448
449 int pFile = MMpull(m);
450 int pdfTab = MMget(m, 0);
451 if ((pdfTab == NIL) || (pFile == NIL))
452 {
453 MMset(m, 0, NIL);
454 return 0;
455 }
456
457 SPdfDoc* pdfdoc = MMgetPointer<SPdfDoc*>(m, MTOP(pdfTab));
458 if (!pdfdoc)
459 {
460 MMset(m, 0, NIL);
461 return 0;
462 }
463
464 std::string path = MMstartstr(m, MTOP(pFile));
465 std::string fontname;
466 try
467 {
468 fontname = pdfdoc->LoadFontTTF(path);
469 }
470 catch(std::exception &)
471 {
472 MMset(m, 0, NIL);
473 return 0;
474 }
475 MMpull(m);
476 Mpushstrbloc(m, (char*)fontname.c_str());
477
478#ifdef _SCOL_DEBUG_
479 MMechostr(MSKDEBUG,"ok\n");
480#endif
481 return 0;
482}
483
484
493int _GetPdfPageSize(mmachine m)
494{
495#ifdef _SCOL_DEBUG_
496 MMechostr(MSKDEBUG,"_GetPdfPageSize\n");
497#endif
498
499 int pPage = MMpull(m);
500 int pdfTab = MMget(m, 0);
501 if ((pdfTab == NIL) || (pPage == NIL))
502 {
503 MMset(m, 0, NIL);
504 return 0;
505 }
506
507 SPdfDoc* pdfdoc = MMgetPointer<SPdfDoc*>(m, MTOP(pdfTab));
508 if (!pdfdoc)
509 {
510 MMset(m, 0, NIL);
511 return 0;
512 }
513
514 HPDF_Page page = MMgetPointer<HPDF_Page>(m, MTOP(pPage));
515 if (!page)
516 {
517 MMset(m, 0, NIL);
518 return 0;
519 }
520
521 float width = 0;
522 float height = 0;
523 try
524 {
525 width = pdfdoc->GetPageWidth(page);
526 height = pdfdoc->GetPageHeight(page);
527 }
528 catch(std::exception &)
529 {
530 MMset(m, 0, NIL);
531 return 0;
532 }
533
534 int tuple = MMmalloc(m, 2, TYPETAB);
535 if(tuple==NIL)
536 {
537 MMset(m, 0, NIL);
538 return MERRMEM;
539 }
540 MMstore(m, tuple, 0, FTOM(width));
541 MMstore(m, tuple, 1, FTOM(height));
542 MMset(m, 0, PTOM(tuple));
543
544#ifdef _SCOL_DEBUG_
545 MMechostr(MSKDEBUG,"ok\n");
546#endif
547 return 0;
548}
549
550
562int _GetPdfPageTextWidth(mmachine m)
563{
564#ifdef _SCOL_DEBUG_
565 MMechostr(MSKDEBUG,"_GetPdfPageTextWidth\n");
566#endif
567
568 int pFontSize = MMpull(m);
569 int pFontName = MMpull(m);
570 int pText = MMpull(m);
571 int pPage = MMpull(m);
572 int pdfTab = MMget(m, 0);
573 if ((pdfTab == NIL) || (pPage == NIL) || (pText == NIL))
574 {
575 MMset(m, 0, NIL);
576 return 0;
577 }
578
579 SPdfDoc* pdfdoc = MMgetPointer<SPdfDoc*>(m, MTOP(pdfTab));
580 if (!pdfdoc)
581 {
582 MMset(m, 0, NIL);
583 return 0;
584 }
585
586 HPDF_Page page = MMgetPointer<HPDF_Page>(m, MTOP(pPage));
587 if (!page)
588 {
589 MMset(m, 0, NIL);
590 return 0;
591 }
592
593 std::string text = MMstartstr(m, MTOP(pText));
594
595 std::string fontName("Helvetica");
596 if (pFontName != NIL)
597 fontName = MMstartstr(m, MTOP(pFontName));
598
599 float fontSize = 10;
600 if (pFontSize != NIL)
601 fontSize = MTOF(pFontSize);
602
603 float width = 0;
604 try
605 {
606 width = pdfdoc->GetTextWidth(page, text, fontName, fontSize);
607 }
608 catch(std::exception &)
609 {
610 MMset(m, 0, NIL);
611 return 0;
612 }
613
614 MMset(m, 0, FTOM(width));
615
616#ifdef _SCOL_DEBUG_
617 MMechostr(MSKDEBUG,"ok\n");
618#endif
619 return 0;
620}
621
622
648int _AddPdfPage(mmachine m)
649{
650#ifdef _SCOL_DEBUG_
651 MMechostr(MSKDEBUG,"_AddPdfPage\n");
652#endif
653
654 int pDir = MMpull(m);
655 int pSize = MMpull(m);
656 int pdfTab = MMget(m, 0);
657 if (pdfTab == NIL)
658 {
659 MMset(m, 0, NIL);
660 return 0;
661 }
662
663 SPdfDoc* pdfdoc = MMgetPointer<SPdfDoc*>(m, MTOP(pdfTab));
664 if (!pdfdoc)
665 {
666 MMset(m, 0, NIL);
667 return 0;
668 }
669
670 HPDF_PageSizes size = HPDF_PAGE_SIZE_A4;
671 HPDF_PageDirection dir = HPDF_PAGE_PORTRAIT;
672
673 if (pSize != NIL)
674 size = (HPDF_PageSizes)MTOI(pSize);
675
676 if (pDir != NIL)
677 dir = (HPDF_PageDirection)MTOI(pDir);
678
679 HPDF_Page page = 0;
680 try
681 {
682 page = pdfdoc->AddPage(size, dir);
683 }
684 catch(std::exception &)
685 {
686 MMset(m, 0, NIL);
687 return 0;
688 }
689
690 //remove last param
691 MMpull(m);
692
693 //get channel
694 int p = OBJfindTH(m, OBJ_PDFDOC_SCOL, SCOL_PTR pdfdoc);
695 //push channel
696 MMpush(m, MMfetch(m, p, OFFOBJCHN));
697
698 MMpushPointer(m, page);
699
700 // Create a new scol myo object
701 int k = OBJcreate(m, OBJ_PDFPAGE_SCOL, SCOL_PTR page, OBJ_PDFDOC_SCOL, SCOL_PTR pdfdoc);
702
703#ifdef _SCOL_DEBUG_
704 MMechostr(MSKDEBUG,"ok\n");
705#endif
706 return k;
707}
708
709
745int _AddPdfPageText(mmachine m)
746{
747#ifdef _SCOL_DEBUG_
748 MMechostr(MSKDEBUG,"_AddPdfPageText\n");
749#endif
750
751 int pAlign = MMpull(m);
752 int pFontSize = MMpull(m);
753 int pFontName = MMpull(m);
754 int pColor = MMpull(m);
755 int pPos = MMpull(m);
756 int pText = MMpull(m);
757 int pPage = MMpull(m);
758 int pdfTab = MMget(m, 0);
759 if ((pdfTab == NIL) || (pPage == NIL) || (pText == NIL))
760 {
761 MMset(m, 0, NIL);
762 return 0;
763 }
764
765 SPdfDoc* pdfdoc = MMgetPointer<SPdfDoc*>(m, MTOP(pdfTab));
766 if (!pdfdoc)
767 {
768 MMset(m, 0, NIL);
769 return 0;
770 }
771
772 HPDF_Page page = MMgetPointer<HPDF_Page>(m, MTOP(pPage));
773 if (!page)
774 {
775 MMset(m, 0, NIL);
776 return 0;
777 }
778 std::string text = MMstartstr(m, MTOP(pText));
779
780 float xPos = (pPos == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pPos), 0));
781 float yPos = (pPos == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pPos), 1));
782
783 int color = 0;
784 if (pColor != NIL)
785 color = MTOI(pColor);
786
787 std::string fontName("Helvetica");
788 if (pFontName != NIL)
789 fontName = MMstartstr(m, MTOP(pFontName));
790
791 float fontSize = 10;
792 if (pFontSize != NIL)
793 fontSize = MTOF(pFontSize);
794
795 int align = SPdfDoc::EM_LEFT|SPdfDoc::EM_TOP;
796 if (pAlign != NIL)
797 align = MTOI(pAlign);
798
799 try
800 {
801 pdfdoc->AddPageText(page, text, xPos, yPos, color, fontName, fontSize, align);
802 }
803 catch(std::exception &)
804 {
805 MMset(m, 0, NIL);
806 return 0;
807 }
808
809 MMset(m, 0, ITOM(0));
810
811#ifdef _SCOL_DEBUG_
812 MMechostr(MSKDEBUG,"ok\n");
813#endif
814 return 0;
815}
816
817
836int _AddPdfPageBitmap(mmachine m)
837{
838#ifdef _SCOL_DEBUG_
839 MMechostr(MSKDEBUG,"_AddPdfPageBitmap\n");
840#endif
841
842 int pAlign = MMpull(m);
843 int pSize = MMpull(m);
844 int pPos = MMpull(m);
845 int pBmp = MMpull(m);
846 int pPage = MMpull(m);
847 int pdfTab = MMget(m, 0);
848 if ((pdfTab == NIL) || (pPage == NIL) || (pBmp == NIL))
849 {
850 MMset(m, 0, NIL);
851 return 0;
852 }
853
854 SPdfDoc* pdfdoc = MMgetPointer<SPdfDoc*>(m, MTOP(pdfTab));
855 if (!pdfdoc)
856 {
857 MMset(m, 0, NIL);
858 return 0;
859 }
860
861 HPDF_Page page = MMgetPointer<HPDF_Page>(m, MTOP(pPage));
862 if (!page)
863 {
864 MMset(m, 0, NIL);
865 return 0;
866 }
867
868 PtrObjVoid scolPtr = (PtrObjVoid) MMstart(m, MTOP(pBmp));
869 if(scolPtr->Type != OBJ_TYPE_BITMAP << 1)
870 {
871 MMpush(m, NIL);
872 return 0;
873 }
874 PtrObjBitmap bitmap = (PtrObjBitmap) MMstart(m, MTOP(scolPtr->Buffer));
875
876 float xPos = (pPos == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pPos), 0));
877 float yPos = (pPos == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pPos), 1));
878
879
880 float width = (pSize == NIL) ? (float)bitmap->TailleW : MTOF(MMfetch(m, MTOP(pSize), 0));
881 float height = (pSize == NIL) ? (float)bitmap->TailleH : MTOF(MMfetch(m, MTOP(pSize), 1));
882
883 int align = SPdfDoc::EM_LEFT|SPdfDoc::EM_TOP;
884 if (pAlign != NIL)
885 align = MTOI(pAlign);
886
887 try
888 {
889 pdfdoc->AddPageBitmap(page, bitmap, xPos, yPos, width, height, align);
890 }
891 catch(std::exception &)
892 {
893 MMset(m, 0, NIL);
894 return 0;
895 }
896
897 MMset(m, 0, ITOM(0));
898
899#ifdef _SCOL_DEBUG_
900 MMechostr(MSKDEBUG,"ok\n");
901#endif
902 return 0;
903}
904
905
924int _AddPdfPageImage(mmachine m)
925{
926#ifdef _SCOL_DEBUG_
927 MMechostr(MSKDEBUG,"_AddPdfPageImage\n");
928#endif
929
930 int pAlign = MMpull(m);
931 int pSize = MMpull(m);
932 int pPos = MMpull(m);
933 int pPath = MMpull(m);
934 int pPage = MMpull(m);
935 int pdfTab = MMget(m, 0);
936 if ((pdfTab == NIL) || (pPage == NIL) || (pPath == NIL))
937 {
938 MMset(m, 0, NIL);
939 return 0;
940 }
941
942 SPdfDoc* pdfdoc = MMgetPointer<SPdfDoc*>(m, MTOP(pdfTab));
943 if (!pdfdoc)
944 {
945 MMset(m, 0, NIL);
946 return 0;
947 }
948
949 HPDF_Page page = MMgetPointer<HPDF_Page>(m, MTOP(pPage));
950 if (!page)
951 {
952 MMset(m, 0, NIL);
953 return 0;
954 }
955
956 std::string path = MMstartstr(m, MTOP(pPath));
957
958 float xPos = (pPos == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pPos), 0));
959 float yPos = (pPos == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pPos), 1));
960
961 float width = (pSize == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pSize), 0));
962 float height = (pSize == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pSize), 1));
963
964 int align = SPdfDoc::EM_LEFT|SPdfDoc::EM_TOP;
965 if (pAlign != NIL)
966 align = MTOI(pAlign);
967
968 try
969 {
970 pdfdoc->AddPageImage(page, path, xPos, yPos, width, height, align);
971 }
972 catch(std::exception &)
973 {
974 MMset(m, 0, NIL);
975 return 0;
976 }
977
978 MMset(m, 0, ITOM(0));
979
980#ifdef _SCOL_DEBUG_
981 MMechostr(MSKDEBUG,"ok\n");
982#endif
983 return 0;
984}
985
986
1009{
1010#ifdef _SCOL_DEBUG_
1011 MMechostr(MSKDEBUG,"_AddPdfPageRectangle\n");
1012#endif
1013
1014 int pAlign = MMpull(m);
1015 int pFilled = MMpull(m);
1016 int pFillColor = MMpull(m);
1017 int pLineColor = MMpull(m);
1018 int pLineWidth = MMpull(m);
1019 int pSize = MMpull(m);
1020 int pPos = MMpull(m);
1021 int pPage = MMpull(m);
1022 int pdfTab = MMget(m, 0);
1023 if ((pdfTab == NIL) || (pPage == NIL) || (pSize == NIL))
1024 {
1025 MMset(m, 0, NIL);
1026 return 0;
1027 }
1028
1029 SPdfDoc* pdfdoc = MMgetPointer<SPdfDoc*>(m, MTOP(pdfTab));
1030 if (!pdfdoc)
1031 {
1032 MMset(m, 0, NIL);
1033 return 0;
1034 }
1035
1036 HPDF_Page page = MMgetPointer<HPDF_Page>(m, MTOP(pPage));
1037 if (!page)
1038 {
1039 MMset(m, 0, NIL);
1040 return 0;
1041 }
1042
1043 float xPos = (pPos == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pPos), 0));
1044 float yPos = (pPos == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pPos), 1));
1045
1046 float width = (pSize == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pSize), 0));
1047 float height = (pSize == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pSize), 1));
1048
1049 float lineWidth = 1.0f;
1050 if (pLineWidth != NIL)
1051 lineWidth = std::abs(MTOF(pLineWidth));
1052
1053 unsigned int lineColor = 0;
1054 if (pLineColor != NIL)
1055 lineColor = MTOI(pLineColor);
1056
1057 unsigned int fillColor = 0;
1058 if (pFillColor != NIL)
1059 fillColor = MTOI(pFillColor);
1060
1061 bool filled = false;
1062 if (pFilled != NIL)
1063 filled = (MTOI(pFilled) > 0) ? true : false;
1064
1065 int align = SPdfDoc::EM_LEFT|SPdfDoc::EM_TOP;
1066 if (pAlign != NIL)
1067 align = MTOI(pAlign);
1068
1069 try
1070 {
1071 pdfdoc->AddPageRectangle(page, xPos, yPos, width, height, lineWidth, lineColor, fillColor, filled, align);
1072 }
1073 catch(std::exception &)
1074 {
1075 MMset(m, 0, NIL);
1076 return 0;
1077 }
1078
1079 MMset(m, 0, ITOM(0));
1080
1081#ifdef _SCOL_DEBUG_
1082 MMechostr(MSKDEBUG,"ok\n");
1083#endif
1084 return 0;
1085}
1086
1087
1109int _AddPdfPageEllipse(mmachine m)
1110{
1111#ifdef _SCOL_DEBUG_
1112 MMechostr(MSKDEBUG,"_AddPdfPageEllipse\n");
1113#endif
1114
1115 int pAlign = MMpull(m);
1116 int pFilled = MMpull(m);
1117 int pFillColor = MMpull(m);
1118 int pLineColor = MMpull(m);
1119 int pLineWidth = MMpull(m);
1120 int pSize = MMpull(m);
1121 int pPos = MMpull(m);
1122 int pPage = MMpull(m);
1123 int pdfTab = MMget(m, 0);
1124 if ((pdfTab == NIL) || (pPage == NIL) || (pSize == NIL))
1125 {
1126 MMset(m, 0, NIL);
1127 return 0;
1128 }
1129
1130 SPdfDoc* pdfdoc = MMgetPointer<SPdfDoc*>(m, MTOP(pdfTab));
1131 if (!pdfdoc)
1132 {
1133 MMset(m, 0, NIL);
1134 return 0;
1135 }
1136
1137 HPDF_Page page = MMgetPointer<HPDF_Page>(m, MTOP(pPage));
1138 if (!page)
1139 {
1140 MMset(m, 0, NIL);
1141 return 0;
1142 }
1143
1144 float xPos = (pPos == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pPos), 0));
1145 float yPos = (pPos == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pPos), 1));
1146
1147 float width = (pSize == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pSize), 0));
1148 float height = (pSize == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pSize), 1));
1149
1150 float lineWidth = 1.0f;
1151 if (pLineWidth != NIL)
1152 lineWidth = std::abs(MTOF(pLineWidth));
1153
1154 unsigned int lineColor = 0;
1155 if (pLineColor != NIL)
1156 lineColor = MTOI(pLineColor);
1157
1158 unsigned int fillColor = 0;
1159 if (pFillColor != NIL)
1160 fillColor = MTOI(pFillColor);
1161
1162 bool filled = false;
1163 if (pFilled != NIL)
1164 filled = (MTOI(pFilled) > 0) ? true : false;
1165
1166 int align = SPdfDoc::EM_LEFT|SPdfDoc::EM_TOP;
1167 if (pAlign != NIL)
1168 align = MTOI(pAlign);
1169
1170 try
1171 {
1172 pdfdoc->AddPageEllipse(page, xPos, yPos, width, height, lineWidth, lineColor, fillColor, filled, align);
1173 }
1174 catch(std::exception &)
1175 {
1176 MMset(m, 0, NIL);
1177 return 0;
1178 }
1179
1180 MMset(m, 0, ITOM(0));
1181
1182#ifdef _SCOL_DEBUG_
1183 MMechostr(MSKDEBUG,"ok\n");
1184#endif
1185 return 0;
1186}
1187
1188
1201int _AddPdfPageLine(mmachine m)
1202{
1203#ifdef _SCOL_DEBUG_
1204 MMechostr(MSKDEBUG,"_AddPdfPageLine\n");
1205#endif
1206
1207 int pLineColor = MMpull(m);
1208 int pLineWidth = MMpull(m);
1209 int pDest = MMpull(m);
1210 int pPos = MMpull(m);
1211 int pPage = MMpull(m);
1212 int pdfTab = MMget(m, 0);
1213 if ((pdfTab == NIL) || (pPage == NIL) || (pPos == NIL) || (pDest == NIL))
1214 {
1215 MMset(m, 0, NIL);
1216 return 0;
1217 }
1218
1219 SPdfDoc* pdfdoc = MMgetPointer<SPdfDoc*>(m, MTOP(pdfTab));
1220 if (!pdfdoc)
1221 {
1222 MMset(m, 0, NIL);
1223 return 0;
1224 }
1225
1226 HPDF_Page page = MMgetPointer<HPDF_Page>(m, MTOP(pPage));
1227 if (!page)
1228 {
1229 MMset(m, 0, NIL);
1230 return 0;
1231 }
1232
1233 float xPos = (pPos == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pPos), 0));
1234 float yPos = (pPos == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pPos), 1));
1235
1236 float xDest = (pDest == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pDest), 0));
1237 float yDest = (pDest == NIL) ? 0.0f : MTOF(MMfetch(m, MTOP(pDest), 1));
1238
1239 float lineWidth = 1.0f;
1240 if (pLineWidth != NIL)
1241 lineWidth = std::abs(MTOF(pLineWidth));
1242
1243 unsigned int lineColor = 0;
1244 if (pLineColor != NIL)
1245 lineColor = MTOI(pLineColor);
1246
1247 try
1248 {
1249 pdfdoc->AddPageLine(page, xPos, yPos, xDest, yDest, lineWidth, lineColor);
1250 }
1251 catch(std::exception &)
1252 {
1253 MMset(m, 0, NIL);
1254 return 0;
1255 }
1256
1257 MMset(m, 0, ITOM(0));
1258
1259#ifdef _SCOL_DEBUG_
1260 MMechostr(MSKDEBUG,"ok\n");
1261#endif
1262 return 0;
1263}
1264
1265
1269char* mPDFname[]=
1270{
1271 "ObjPdfDoc",
1272 "ObjPdfPage",
1273
1274 "PDF_PAGE_A3",
1275 "PDF_PAGE_A4",
1276 "PDF_PAGE_A5",
1277 "PDF_PAGE_B4",
1278 "PDF_PAGE_B5",
1279 "PDF_PAGE_COMM1",
1280 "PDF_PAGE_EOF",
1281 "PDF_PAGE_EXECUTIVE",
1282 "PDF_PAGE_LEGAL",
1283 "PDF_PAGE_LETTER",
1284 "PDF_PAGE_US4X6",
1285 "PDF_PAGE_US4X8",
1286 "PDF_PAGE_US5X7",
1287
1288 "PDF_PAGE_PORTRAIT",
1289 "PDF_PAGE_LANDSCAPE",
1290
1291 "PDF_PAGE_MODE_EOF",
1292 "PDF_PAGE_MODE_FULLSCREEN",
1293 "PDF_PAGE_MODE_NONE",
1294 "PDF_PAGE_MODE_OUTLINE",
1295 "PDF_PAGE_MODE_THUMBS",
1296
1297 "PDF_PAGE_LAYOUT_EOF",
1298 "PDF_PAGE_LAYOUT_ONE_COLUMN",
1299 "PDF_PAGE_LAYOUT_SINGLE",
1300 "PDF_PAGE_LAYOUT_TWO_COLUMN_LEFT",
1301 "PDF_PAGE_LAYOUT_TWO_COLUMN_RIGHT",
1302 "PDF_PAGE_LAYOUT_TWO_PAGE_LEFT",
1303 "PDF_PAGE_LAYOUT_TWO_PAGE_RIGHT",
1304
1305 "PDF_ALIGN_LEFT",
1306 "PDF_ALIGN_RIGHT",
1307 "PDF_ALIGN_CENTER",
1308 "PDF_ALIGN_TOP",
1309 "PDF_ALIGN_BOTTOM",
1310 "PDF_ALIGN_MIDDLE",
1311
1312 "_CRpdfDocument",
1313 "_DSpdfDocument",
1314 "_SetPdfDocumentCharset",
1315 "_SavePdfDocument",
1316 "_SetPdfPageMode",
1317 "_SetPdfLayoutMode",
1318 "_LoadPdfTrueTypeFont",
1319 "_GetPdfPageSize",
1320 "_GetPdfPageTextWidth",
1321 "_AddPdfPage",
1322 "_AddPdfPageText",
1323 "_AddPdfPageBitmap",
1324 "_AddPdfPageImage",
1325 "_AddPdfPageRectangle",
1326 "_AddPdfPageEllipse",
1327 "_AddPdfPageLine"
1328};
1329
1333#define NPDFPKG (sizeof(mPDFname)/sizeof(char*))
1334
1338int (*mPDFfun[NPDFPKG])(mmachine m)=
1339{
1340 NULL, //ObjPdfDoc
1341 NULL, //ObjPdfPage
1342
1343 SCOL_TYPTYPE(HPDF_PAGE_SIZE_A3), //PDF_PAGE_A3
1344 SCOL_TYPTYPE(HPDF_PAGE_SIZE_A4), //PDF_PAGE_A4
1345 SCOL_TYPTYPE(HPDF_PAGE_SIZE_A5), //PDF_PAGE_A5
1346 SCOL_TYPTYPE(HPDF_PAGE_SIZE_B4), //PDF_PAGE_B4
1347 SCOL_TYPTYPE(HPDF_PAGE_SIZE_B5), //PDF_PAGE_B5
1348 SCOL_TYPTYPE(HPDF_PAGE_SIZE_COMM10), //PDF_PAGE_COMM10
1349 SCOL_TYPTYPE(HPDF_PAGE_SIZE_EOF), //PDF_PAGE_EOF
1350 SCOL_TYPTYPE(HPDF_PAGE_SIZE_EXECUTIVE), //PDF_PAGE_EXECUTIVE
1351 SCOL_TYPTYPE(HPDF_PAGE_SIZE_LEGAL), //PDF_PAGE_LEGAL
1352 SCOL_TYPTYPE(HPDF_PAGE_SIZE_LETTER), //PDF_PAGE_LETTER
1353 SCOL_TYPTYPE(HPDF_PAGE_SIZE_US4x6), //PDF_PAGE_US4X6
1354 SCOL_TYPTYPE(HPDF_PAGE_SIZE_US4x8), //PDF_PAGE_US4X8
1355 SCOL_TYPTYPE(HPDF_PAGE_SIZE_US5x7), //PDF_PAGE_US5X7
1356
1357 SCOL_TYPTYPE(HPDF_PAGE_PORTRAIT), //PDF_PAGE_PORTRAIT
1358 SCOL_TYPTYPE(HPDF_PAGE_LANDSCAPE), //PDF_PAGE_LANDSCAPE
1359
1360 SCOL_TYPTYPE(HPDF_PAGE_MODE_EOF), //PDF_PAGE_MODE_EOF
1361 SCOL_TYPTYPE(HPDF_PAGE_MODE_FULL_SCREEN), //PDF_PAGE_MODE_FULLSCREEN
1362 SCOL_TYPTYPE(HPDF_PAGE_MODE_USE_NONE), //PDF_PAGE_MODE_NONE
1363 SCOL_TYPTYPE(HPDF_PAGE_MODE_USE_OUTLINE), //PDF_PAGE_MODE_OUTLINE
1364 SCOL_TYPTYPE(HPDF_PAGE_MODE_USE_THUMBS), //PDF_PAGE_MODE_THUMBS
1365
1366 SCOL_TYPTYPE(HPDF_PAGE_LAYOUT_EOF), //PDF_PAGE_LAYOUT_EOF
1367 SCOL_TYPTYPE(HPDF_PAGE_LAYOUT_ONE_COLUMN), //PDF_PAGE_LAYOUT_ONE_COLUMN
1368 SCOL_TYPTYPE(HPDF_PAGE_LAYOUT_SINGLE), //PDF_PAGE_LAYOUT_SINGLE
1369 SCOL_TYPTYPE(HPDF_PAGE_LAYOUT_TWO_COLUMN_LEFT), //PDF_PAGE_LAYOUT_TWO_COLUMN_LEFT
1370 SCOL_TYPTYPE(HPDF_PAGE_LAYOUT_TWO_COLUMN_RIGHT), //PDF_PAGE_LAYOUT_TWO_COLUMN_RIGHT
1371 SCOL_TYPTYPE(HPDF_PAGE_LAYOUT_TWO_PAGE_LEFT), //PDF_PAGE_LAYOUT_TWO_PAGE_LEFT
1372 SCOL_TYPTYPE(HPDF_PAGE_LAYOUT_TWO_PAGE_RIGHT), //PDF_PAGE_LAYOUT_TWO_PAGE_RIGHT
1373
1374 SCOL_TYPTYPE(SPdfDoc::EM_LEFT), //PDF_ALIGN_LEFT
1375 SCOL_TYPTYPE(SPdfDoc::EM_RIGHT), //PDF_ALIGN_RIGHT
1376 SCOL_TYPTYPE(SPdfDoc::EM_CENTER), //PDF_ALIGN_CENTER
1377 SCOL_TYPTYPE(SPdfDoc::EM_TOP), //PDF_ALIGN_TOP
1378 SCOL_TYPTYPE(SPdfDoc::EM_BOTTOM), //PDF_ALIGN_BOTTOM
1379 SCOL_TYPTYPE(SPdfDoc::EM_MIDDLE), //PDF_ALIGN_MIDDLE
1380
1397};
1398
1402int mPDFnarg[NPDFPKG]=
1403{
1404 TYPTYPE, //ObjPdfDoc
1405 TYPTYPE, //ObjPdfPage
1406
1407 TYPVAR, //PDF_PAGE_A3
1408 TYPVAR, //PDF_PAGE_A4
1409 TYPVAR, //PDF_PAGE_A5
1410 TYPVAR, //PDF_PAGE_B4
1411 TYPVAR, //PDF_PAGE_B5
1412 TYPVAR, //PDF_PAGE_COMM10
1413 TYPVAR, //PDF_PAGE_EOF
1414 TYPVAR, //PDF_PAGE_EXECUTIVE
1415 TYPVAR, //PDF_PAGE_LEGAL
1416 TYPVAR, //PDF_PAGE_LETTER
1417 TYPVAR, //PDF_PAGE_US4X6
1418 TYPVAR, //PDF_PAGE_US4X8
1419 TYPVAR, //PDF_PAGE_US5X7
1420
1421 TYPVAR, //PDF_PAGE_PORTRAIT
1422 TYPVAR, //PDF_PAGE_LANDSCAPE
1423
1424 TYPVAR, //PDF_PAGE_MODE_EOF
1425 TYPVAR, //PDF_PAGE_MODE_FULLSCREEN
1426 TYPVAR, //PDF_PAGE_MODE_NONE
1427 TYPVAR, //PDF_PAGE_MODE_OUTLINE
1428 TYPVAR, //PDF_PAGE_MODE_THUMBS
1429
1430 TYPVAR, //PDF_PAGE_LAYOUT_EOF
1431 TYPVAR, //PDF_PAGE_LAYOUT_ONE_COLUMN
1432 TYPVAR, //PDF_PAGE_LAYOUT_SINGLE
1433 TYPVAR, //PDF_PAGE_LAYOUT_TWO_COLUMN_LEFT
1434 TYPVAR, //PDF_PAGE_LAYOUT_TWO_COLUMN_RIGHT
1435 TYPVAR, //PDF_PAGE_LAYOUT_TWO_PAGE_LEFT
1436 TYPVAR, //PDF_PAGE_LAYOUT_TWO_PAGE_RIGHT
1437
1438 TYPVAR, //PDF_ALIGN_LEFT
1439 TYPVAR, //PDF_ALIGN_RIGHT
1440 TYPVAR, //PDF_ALIGN_CENTER
1441 TYPVAR, //PDF_ALIGN_TOP
1442 TYPVAR, //PDF_ALIGN_BOTTOM
1443 TYPVAR, //PDF_ALIGN_MIDDLE
1444
1445 5, //_CRpdfDocument
1446 1, //_DSpdfDocument
1447 2, //_SetPdfDocumentCharset
1448 2, //_SavePdfDocument
1449 2, //_SetPdfPageMode
1450 2, //_SetPdfLayoutMode
1451 2, //_LoadPdfTrueTypeFont
1452 2, //_GetPdfPageSize
1453 5, //_GetPdfPageTextWidth
1454 3, //_AddPdfPage
1455 8, //_AddPdfPageText
1456 6, //_AddPdfPageBitmap
1457 6, //_AddPdfPageImage
1458 9, //_AddPdfPageRectangle
1459 9, //_AddPdfPageEllipse
1460 6 //_AddPdfPageLine
1461};
1462
1466char* mPDFtype[NPDFPKG]=
1467{
1468 NULL, //ObjPdfDoc
1469 NULL, //ObjPdfPage
1470
1471 "I", //PDF_PAGE_A3
1472 "I", //PDF_PAGE_A4
1473 "I", //PDF_PAGE_A5
1474 "I", //PDF_PAGE_B4
1475 "I", //PDF_PAGE_B5
1476 "I", //PDF_PAGE_COMM10
1477 "I", //PDF_PAGE_EOF
1478 "I", //PDF_PAGE_EXECUTIVE
1479 "I", //PDF_PAGE_LEGAL
1480 "I", //PDF_PAGE_LETTER
1481 "I", //PDF_PAGE_US4X6
1482 "I", //PDF_PAGE_US4X8
1483 "I", //PDF_PAGE_US5X7
1484
1485 "I", //PDF_PAGE_PORTRAIT
1486 "I", //PDF_PAGE_LANDSCAPE
1487
1488 "I", //PDF_PAGE_MODE_EOF
1489 "I", //PDF_PAGE_MODE_FULLSCREEN
1490 "I", //PDF_PAGE_MODE_NONE
1491 "I", //PDF_PAGE_MODE_OUTLINE
1492 "I", //PDF_PAGE_MODE_THUMBS
1493
1494 "I", //PDF_PAGE_LAYOUT_EOF
1495 "I", //PDF_PAGE_LAYOUT_ONE_COLUMN
1496 "I", //PDF_PAGE_LAYOUT_SINGLE
1497 "I", //PDF_PAGE_LAYOUT_TWO_COLUMN_LEFT
1498 "I", //PDF_PAGE_LAYOUT_TWO_COLUMN_RIGHT
1499 "I", //PDF_PAGE_LAYOUT_TWO_PAGE_LEFT
1500 "I", //PDF_PAGE_LAYOUT_TWO_PAGE_RIGHT
1501
1502 "I", //PDF_ALIGN_LEFT
1503 "I", //PDF_ALIGN_RIGHT
1504 "I", //PDF_ALIGN_CENTER
1505 "I", //PDF_ALIGN_TOP
1506 "I", //PDF_ALIGN_BOTTOM
1507 "I", //PDF_ALIGN_MIDDLE
1508
1509 "fun [Chn S S S I] ObjPdfDoc", //_CRpdfDocument
1510 "fun [ObjPdfDoc] I", //_DSpdfDocument
1511 "fun [ObjPdfDoc S] I", //_SetPdfDocumentCharset
1512 "fun [ObjPdfDoc W] I", //_SavePdfDocument
1513 "fun [ObjPdfDoc I] I", //_SetPdfPageMode
1514 "fun [ObjPdfDoc I] I", //_SetPdfLayoutMode
1515 "fun [ObjPdfDoc P] S", //_LoadPdfTrueTypeFont
1516 "fun [ObjPdfDoc ObjPdfPage] [F F]", //_GetPdfPageSize
1517 "fun [ObjPdfDoc ObjPdfPage S S F] F", //_GetPdfPageTextWidth
1518 "fun [ObjPdfDoc I I] ObjPdfPage", //_AddPdfPage
1519 "fun [ObjPdfDoc ObjPdfPage S [F F] I S F I] I", //_AddPdfPageText
1520 "fun [ObjPdfDoc ObjPdfPage ObjBitmap [F F] [F F] I] I", //_AddPdfPageBitmap
1521 "fun [ObjPdfDoc ObjPdfPage P [F F] [F F] I] I", //_AddPdfPageImage
1522 "fun [ObjPdfDoc ObjPdfPage [F F] [F F] F I I I I] I", //_AddPdfPageRectangle
1523 "fun [ObjPdfDoc ObjPdfPage [F F] [F F] F I I I I] I", //_AddPdfPageEllipse
1524 "fun [ObjPdfDoc ObjPdfPage [F F] [F F] F I] I" //_AddPdfPageLine
1525};
1526
1527
1528// Everything inside _cond and _endcond is ignored by doxygen
1530
1535int LoadPdfDoc(mmachine m)
1536{
1537 int k = 0;
1538
1539 MMechostr(MSKDEBUG,"\n" );
1540 MMechostr(MSKDEBUG," > Loading PDF document Support\n");
1541
1542 // Declare a new type of object ("ObjPdfDoc")
1543 OBJ_PDFDOC_SCOL = OBJregister(0 /*nb of callback*/, 0, destroyPdfObj, "OBJ_PDFDOC_SCOL");
1544 OBJ_PDFPAGE_SCOL = OBJregister(0 /*nb of callback*/, 1, destroyPdfPageObj, "OBJ_PDFPAGE_SCOL");
1545 k = PKhardpak(m, "mPDFDOC.pkg-1.0", NPDFPKG, mPDFname, mPDFfun, mPDFnarg, mPDFtype);
1546
1547 MMechostr(MSKDEBUG," > Successfully Loaded\n\n");
1548 return k;
1549}
1550
1551int ClosePdfDoc()
1552{
1553 MMechostr(MSKDEBUG,"\n" );
1554 MMechostr(MSKDEBUG," > Unloading PDF document Support\n");
1555
1556 MMechostr(MSKDEBUG," > Successfully unloaded\n\n");
1557 return 0;
1558}
1559
1561
1562
1567#ifndef SCOL_STATIC
1568extern "C" SCOL_EXPORT int ScolLoadPlugin(mmachine m, cbmachine w)
1569#else
1570extern "C" SCOL_EXPORT int ScolSPdfLoadPlugin(mmachine m, cbmachine w)
1571#endif
1572{
1573 SCOLinitplugin(w);
1574 mm = m;
1575
1576 return LoadPdfDoc(m);
1577}
1578
1583#ifndef SCOL_STATIC
1584extern "C" SCOL_EXPORT int ScolUnloadPlugin()
1585#else
1586extern "C" SCOL_EXPORT int ScolSPdfUnloadPlugin()
1587#endif
1588{
1589 return ClosePdfDoc();
1590}
Definition sPdf.h:36
int _GetPdfPageTextWidth(mmachine m)
_GetPdfPageTextWidth : Get a PDF text width from a font
int _AddPdfPageLine(mmachine m)
_AddPdfPageLine : Add a line to a PDF page
int _CRpdfDocument(mmachine m)
_CRpdfDocument : This function create a PDF document object
int _AddPdfPageBitmap(mmachine m)
_AddPdfPageBitmap : Add a bitmap to a PDF page
int _GetPdfPageSize(mmachine m)
_GetPdfPageSize : Get a PDF page size
int _SetPdfPageMode(mmachine m)
_SetPdfPageMode : Set the page mode of a PDF document
int _SetPdfLayoutMode(mmachine m)
_SetPdfLayoutMode : Set the layout mode of a PDF document
int _SetPdfDocumentCharset(mmachine m)
_SetPdfDocumentCharset : Set the current charset of a PDF document
int _LoadPdfTrueTypeFont(mmachine m)
_LoadPdfTrueTypeFont : load a TrueType font file into a PDF document
int _AddPdfPage(mmachine m)
_AddPdfPage : Add a page to a PDF document
int _AddPdfPageText(mmachine m)
_AddPdfPageText : Add text to a PDF page
int _SavePdfDocument(mmachine m)
_SavePdfDocument : Save a PDF document to a file
int _AddPdfPageRectangle(mmachine m)
_AddPdfPageRectangle : Add a ractangle to a PDF page
int _DSpdfDocument(mmachine m)
_DSpdfDocument : Destroy PDF document object
int _AddPdfPageImage(mmachine m)
_AddPdfPageImage : Add an image to a PDF page from a jpg or png file
int _AddPdfPageEllipse(mmachine m)
_AddPdfPageEllipse : Add an ellipse to a PDF page