]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/mpdf/classes/wmf.php
13 function _getWMFimage($data) {
16 $this->gdiObjectArray
= array();
17 $a=unpack('stest',"\1\0");
19 return array(0, 'Error parsing WMF image - Big-endian architecture not supported');
20 // check for Aldus placeable metafile header
21 $key = unpack('Lmagic', substr($data, 0, 4));
22 $p = 18; // WMF header
23 if ($key['magic'] == (int)0x9AC6CDD7) { $p +
=22; } // Aldus header
24 // define some state variables
25 $wo=null; // window origin
26 $we=null; // window extent
32 while ($p < strlen($data) && !$endRecord) {
33 $recordInfo = unpack('Lsize/Sfunc', substr($data, $p, 6)); $p +
= 6;
34 // size of record given in WORDs (= 2 bytes)
35 $size = $recordInfo['size'];
36 // func is number of GDI function
37 $func = $recordInfo['func'];
39 $parms = substr($data, $p, 2*($size-3)); $p +
= 2*($size-3);
42 case 0x020b: // SetWindowOrg
43 // do not allow window origin to be changed
44 // after drawing has begun
46 $wo = array_reverse(unpack('s2', $parms));
48 case 0x020c: // SetWindowExt
49 // do not allow window extent to be changed
50 // after drawing has begun
52 $we = array_reverse(unpack('s2', $parms));
54 case 0x02fc: // CreateBrushIndirect
55 $brush = unpack('sstyle/Cr/Cg/Cb/Ca/Shatch', $parms);
57 $this->_AddGDIObject($brush);
59 case 0x02fa: // CreatePenIndirect
60 $pen = unpack('Sstyle/swidth/sdummy/Cr/Cg/Cb/Ca', $parms);
61 // convert width from twips to user unit
62 $pen['width'] /= (20 * $k);
64 $this->_AddGDIObject($pen);
67 // MUST create other GDI objects even if we don't handle them
68 case 0x06fe: // CreateBitmap
69 case 0x02fd: // CreateBitmapIndirect
70 case 0x00f8: // CreateBrush
71 case 0x02fb: // CreateFontIndirect
72 case 0x00f7: // CreatePalette
73 case 0x01f9: // CreatePatternBrush
74 case 0x06ff: // CreateRegion
75 case 0x0142: // DibCreatePatternBrush
76 $dummyObject = array('type'=>'D');
77 $this->_AddGDIObject($dummyObject);
79 case 0x0106: // SetPolyFillMode
80 $polyFillMode = unpack('smode', $parms);
81 $polyFillMode = $polyFillMode['mode'];
83 case 0x01f0: // DeleteObject
84 $idx = unpack('Sidx', $parms);
86 $this->_DeleteGDIObject($idx);
88 case 0x012d: // SelectObject
89 $idx = unpack('Sidx', $parms);
91 $obj = $this->_GetGDIObject($idx);
92 switch ($obj['type']) {
95 if ($obj['style'] == 1) { $nullBrush
= true; }
97 $wmfdata .= $this->mpdf
->SetFColor($this->mpdf
->ConvertColor('rgb('.$obj['r'].','.$obj['g'].','.$obj['b'].')'), true)."\n";
102 $dashArray = array();
103 // dash parameters are custom
104 switch ($obj['style']) {
108 $dashArray = array(3,1);
111 $dashArray = array(0.5,0.5);
113 case 3: // PS_DASHDOT
114 $dashArray = array(2,1,0.5,1);
116 case 4: // PS_DASHDOTDOT
117 $dashArray = array(2,1,0.5,1,0.5,1);
124 $wmfdata .= $this->mpdf
->SetDColor($this->mpdf
->ConvertColor('rgb('.$obj['r'].','.$obj['g'].','.$obj['b'].')'), true)."\n";
125 $wmfdata .= sprintf("%.3F w\n",$obj['width']*$k);
127 if (!empty($dashArray)) {
129 for ($i=0; $i<count($dashArray);$i++
) {
130 $s .= $dashArray[$i] * $k;
131 if ($i != count($dashArray)-1) { $s
.= ' '; }
139 case 0x0325: // Polyline
140 case 0x0324: // Polygon
141 $coords = unpack('s'.($size-3), $parms);
142 $numpoints = $coords[1];
143 for ($i = $numpoints; $i > 0; $i--) {
145 $py = $coords[2*$i+
1];
147 if ($i < $numpoints) { $wmfdata
.= $this
->_LineTo($px
, $py
); }
148 else { $wmfdata
.= $this
->_MoveTo($px
, $py
); }
150 if ($func == 0x0325) { $op
= 's'; }
151 else if ($func == 0x0324) {
153 if ($nullBrush) { $op
= 'n'; } // no op
154 else { $op
= 'f'; } // fill
157 if ($nullBrush) { $op
= 's'; } // stroke
158 else { $op
= 'b'; } // stroke and fill
160 if ($polyFillMode==1 && ($op=='b' || $op=='f')) { $op
.= '*'; } // use even-odd fill rule
162 $wmfdata .= $op."\n";
164 case 0x0538: // PolyPolygon
165 $coords = unpack('s'.($size-3), $parms);
166 $numpolygons = $coords[1];
167 $adjustment = $numpolygons;
168 for ($j = 1; $j <= $numpolygons; $j++
) {
169 $numpoints = $coords[$j +
1];
170 for ($i = $numpoints; $i > 0; $i--) {
171 $px = $coords[2*$i +
$adjustment];
172 $py = $coords[2*$i+
1 +
$adjustment];
173 if ($i == $numpoints) { $wmfdata
.= $this
->_MoveTo($px
, $py
); }
174 else { $wmfdata
.= $this
->_LineTo($px
, $py
); }
176 $adjustment +
= $numpoints * 2;
180 if ($nullBrush) { $op
= 'n'; } // no op
181 else { $op
= 'f'; } // fill
184 if ($nullBrush) { $op
= 's'; } // stroke
185 else { $op
= 'b'; } // stroke and fill
187 if ($polyFillMode==1 && ($op=='b' || $op=='f')) { $op
.= '*'; } // use even-odd fill rule
188 $wmfdata .= $op."\n";
197 return array(1,$wmfdata,$wo,$we);
201 function _MoveTo($x, $y) {
205 // a line must have been started using _MoveTo() first
206 function _LineTo($x, $y) {
210 function _AddGDIObject($obj) {
211 // find next available slot
213 if (!empty($this->gdiObjectArray
)) {
217 $empty = !isset($this->gdiObjectArray
[$i]);
222 $this->gdiObjectArray
[$idx] = $obj;
225 function _GetGDIObject($idx) {
226 return $this->gdiObjectArray
[$idx];
229 function _DeleteGDIObject($idx) {
230 unset($this->gdiObjectArray
[$idx]);