1 #ifndef __drvPPTX_h
2 #define __drvPPTX_h
3 
4 /*
5    drvooxml.h : This file is part of pstoedit
6    Backend for Office Open XML files
7    Contributed by: Scott Pakin <scott+ps2ed_AT_pakin.org>
8 
9    Copyright (C) 1993 - 2014 Wolfgang Glunz, wglunz35_AT_pstoedit.net
10 
11     This program is free software; you can redistribute it and/or modify
12     it under the terms of the GNU General Public License as published by
13     the Free Software Foundation; either version 2 of the License, or
14     (at your option) any later version.
15 
16     This program is distributed in the hope that it will be useful,
17     but WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19     GNU General Public License for more details.
20 
21     You should have received a copy of the GNU General Public License
22     along with this program; if not, write to the Free Software
23     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 
25 */
26 
27 #include "drvbase.h"
28 #include I_strstream
29 #include <set>
30 
31 class drvPPTX : public drvbase {
32 
33 public:
34 
35         derivedConstructor(drvPPTX);
36         ~drvPPTX(); // Destructor
37         class DriverOptions : public ProgramOptions {
38         public:
39                 OptionT < RSString, RSStringValueExtractor > colortype;
40                 OptionT < RSString, RSStringValueExtractor > fonttype;
41                 OptionT < RSString, RSStringValueExtractor > embeddedfonts;
DriverOptions()42         DriverOptions():
43                 colortype(true, "-colors", "string", 0,
44                           "\"original\" to retain original colors (default), \"theme\" to convert randomly to theme colors, or \"theme-lum\" also to vary luminance",
45                           NULL, "original"),
46                   fonttype(true, "-fonts", "string", 0,
47                            "use \"windows\" fonts (default), \"native\" fonts, or convert to the \"theme\" font",
48                            NULL, "windows"),
49                   embeddedfonts(true, "-embed", "string", 0,
50                                 "embed fonts, specified as a comma-separated list of EOT-format font files",
51                                 NULL, "")
52                 {
53                         ADD(colortype);
54                         ADD(fonttype);
55                         ADD(embeddedfonts);
56                 }
57         }*options;
58 
59 #include "drvfuncs.h"
60         void show_rectangle(const float llx, const float lly, const float urx, const float ury);
61         void show_text(const TextInfo & textInfo);
62 
63 public:
64 
65         virtual void    show_image(const PSImage & imageinfo);
66 
67 private:
68         struct zip * outzip;        // pptx file to generate (zip format)
69         ostringstream slidef;       // Contents of current slide
70         BBox slideBBox;             // Bounding box (all slides)
71         Point center_offset;        // Translation needed to center the current slide
72         unsigned long next_id;      // Next ID number for naming objects
73         unsigned long page_images;  // Number of images on the current page
74         unsigned long total_images; // Number of images in the entire document
75         set<string> eotlist;        // Set of EOT files to embed
76 
77         // OOXML requires a *lot* of boilerplate text.
78         static const char * const xml_rels;
79         static const char * const xml_slideLayout1_xml;
80         static const char * const xml_slideLayout1_xml_rels;
81         static const char * const xml_slideMaster1_xml;
82         static const char * const xml_slideMaster1_xml_rels;
83         static const char * const xml_theme1_xml;
84 
85         void create_pptx_file(const char * relname, const char * contents);
86         void create_pptx();
87         void print_coords(const BBox & pathBBox);
88         Point pathCentroid();
89         static Point rotate_pt_around (const Point & pt, float angle, const Point & pivot) ;
90 		static float angle_between(Point first, Point second);
91 		static void parse_xform_matrix(const float * origMatrix,
92 				bool * mirrored,
93 				float * xscale, float * yscale,
94 				float * rotation,
95 				float * xtrans, float * ytrans);
96         void print_connections(const BBox & pathBBox);
97         void print_color(int baseIndent, float redF, float greenF, float blueF);
98         void print_join();
99         void print_dash();
100         enum {C_ORIGINAL, C_THEME, C_THEME_PURE} color_type;
101         enum {F_WINDOWS, F_NATIVE, F_THEME} font_type;
102         const char * pt2emu(float x_bp, float y_bp,
103                             long int xshift_emu=0, long int yshift_emu=0,
104                             RSString x_name="x", RSString y_name="y",
105                             bool scaleOnly=false) const;
106 
107         static long int bp2emu (float bp); // implemented in cpp file because it used lroundf which is not visible from h file
108 
xtrans(float x_bp)109         long int xtrans (float x_bp) const {
110           // Convert an x coordinate from PostScript to OOXML.  To do
111           // this we shift the page to the origin, center it on the
112           // slide, and scale it from PostScript points to OOXML EMUs.
113           BBox pageBBox = getCurrentBBox();
114           return bp2emu(x_bp - pageBBox.ll.x_ + center_offset.x_);
115         }
116 
ytrans(float y_bp)117         long int ytrans (float y_bp) const {
118           // Convert a y coordinate from PostScript to OOXML.  To do
119           // this we shift the page to the origin, center it on the
120           // slide, flip it upside down, and scale it from PostScript
121           // points to OOXML EMUs.
122           BBox pageBBox = getCurrentBBox();
123           float pageHeight = pageBBox.ur.y_ - pageBBox.ll.y_;
124           return bp2emu(pageHeight - (y_bp - pageBBox.ll.y_) + center_offset.y_);
125         }
126 
127         static unsigned char panose2pitch (const unsigned int * panose_vals);
128         void get_font_props(const TextInfo & textinfo,
129                             RSString * typeface, RSString * panose,
130                             bool * isBold, bool * isItalic,
131                             unsigned char * pitchFamily);
132         void eot2texinfo(const string& eotfilename, TextInfo & textinfo);
133 
134         // Describe a theme color and modifications to it.
135         class ThemeColor {
136         public:
137           string name;            // Color name
138           unsigned int lum;       // New luminance (thousandths of a %)
139           ThemeColor(string tName="unknown", unsigned int tLum=~0U) :
name(tName)140             name(tName),
141             lum(tLum)
142           {}
143         };
144 
145         // Map an RGB value to a theme color.
146         typedef KeyValuePair<unsigned int, ThemeColor> RGB2Theme;
147 #ifndef BUGGYGPP
148 		Mapper<RGB2Theme /* , unsigned int, ThemeColor */ > rgb2theme;
149 #else
150         Mapper<RGB2Theme, unsigned int, ThemeColor> rgb2theme;
151 #endif
152 
153         // Map a PostScript core font to a Windows name + PANOSE characterization.
154 #ifndef BUGGYGPP
155         Mapper<FontMapping /*, RSString, RSString*/ > ps2win;
156 #else
157 		Mapper<FontMapping, RSString, RSString> ps2win;
158 #endif
159 };
160 
161 #endif
162