OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "../../../include/fxge/fx_ge.h" | 7 #include "../../../include/fxge/fx_ge.h" |
8 #include "../../../include/fxcodec/fx_codec.h" | 8 #include "../../../include/fxcodec/fx_codec.h" |
9 #include "text_int.h" | 9 #include "text_int.h" |
10 struct PSGlyph { | 10 struct PSGlyph { |
11 CFX_Font* m_pFont; | 11 CFX_Font* m_pFont; |
12 FX_DWORD m_GlyphIndex; | 12 FX_DWORD m_GlyphIndex; |
13 FX_BOOL» » » m_bGlyphAdjust; | 13 bool» » » m_bGlyphAdjust; |
14 FX_FLOAT m_AdjustMatrix[4]; | 14 FX_FLOAT m_AdjustMatrix[4]; |
15 }; | 15 }; |
16 class CPSFont | 16 class CPSFont |
17 { | 17 { |
18 public: | 18 public: |
19 PSGlyph m_Glyphs[256]; | 19 PSGlyph m_Glyphs[256]; |
20 int m_nGlyphs; | 20 int m_nGlyphs; |
21 }; | 21 }; |
22 CFX_PSRenderer::CFX_PSRenderer() | 22 CFX_PSRenderer::CFX_PSRenderer() |
23 { | 23 { |
24 m_pOutput = NULL; | 24 m_pOutput = NULL; |
25 m_bColorSet = m_bGraphStateSet = FALSE; | 25 m_bColorSet = m_bGraphStateSet = false; |
26 m_bInited = FALSE; | 26 m_bInited = false; |
27 } | 27 } |
28 CFX_PSRenderer::~CFX_PSRenderer() | 28 CFX_PSRenderer::~CFX_PSRenderer() |
29 { | 29 { |
30 for (int i = 0; i < (int)m_PSFontList.GetSize(); i ++) { | 30 for (int i = 0; i < (int)m_PSFontList.GetSize(); i ++) { |
31 CPSFont* pFont = m_PSFontList[i]; | 31 CPSFont* pFont = m_PSFontList[i]; |
32 delete pFont; | 32 delete pFont; |
33 } | 33 } |
34 } | 34 } |
35 #define OUTPUT_PS(str) m_pOutput->OutputPS(str, sizeof str-1) | 35 #define OUTPUT_PS(str) m_pOutput->OutputPS(str, sizeof str-1) |
36 void CFX_PSRenderer::Init(IFX_PSOutput* pOutput, int pslevel, int width, int hei
ght, FX_BOOL bCmykOutput) | 36 void CFX_PSRenderer::Init(IFX_PSOutput* pOutput, int pslevel, int width, int hei
ght, bool bCmykOutput) |
37 { | 37 { |
38 m_PSLevel = pslevel; | 38 m_PSLevel = pslevel; |
39 m_pOutput = pOutput; | 39 m_pOutput = pOutput; |
40 m_ClipBox.left = m_ClipBox.top = 0; | 40 m_ClipBox.left = m_ClipBox.top = 0; |
41 m_ClipBox.right = width; | 41 m_ClipBox.right = width; |
42 m_ClipBox.bottom = height; | 42 m_ClipBox.bottom = height; |
43 m_bCmykOutput = bCmykOutput; | 43 m_bCmykOutput = bCmykOutput; |
44 } | 44 } |
45 FX_BOOL CFX_PSRenderer::StartRendering() | 45 bool CFX_PSRenderer::StartRendering() |
46 { | 46 { |
47 if (m_bInited) { | 47 if (m_bInited) { |
48 return TRUE; | 48 return true; |
49 } | 49 } |
50 static const char init_str[] = "\nsave\n/im/initmatrix load def\n" | 50 static const char init_str[] = "\nsave\n/im/initmatrix load def\n" |
51 "/n/newpath load def/m/moveto load def/l/line
to load def/c/curveto load def/h/closepath load def\n" | 51 "/n/newpath load def/m/moveto load def/l/line
to load def/c/curveto load def/h/closepath load def\n" |
52 "/f/fill load def/F/eofill load def/s/stroke
load def/W/clip load def/W*/eoclip load def\n" | 52 "/f/fill load def/F/eofill load def/s/stroke
load def/W/clip load def/W*/eoclip load def\n" |
53 "/rg/setrgbcolor load def/k/setcmykcolor load
def\n" | 53 "/rg/setrgbcolor load def/k/setcmykcolor load
def\n" |
54 "/J/setlinecap load def/j/setlinejoin load de
f/w/setlinewidth load def/M/setmiterlimit load def/d/setdash load def\n" | 54 "/J/setlinecap load def/j/setlinejoin load de
f/w/setlinewidth load def/M/setmiterlimit load def/d/setdash load def\n" |
55 "/q/gsave load def/Q/grestore load def/iM/ima
gemask load def\n" | 55 "/q/gsave load def/Q/grestore load def/iM/ima
gemask load def\n" |
56 "/Tj/show load def/Ff/findfont load def/Fs/sc
alefont load def/Sf/setfont load def\n" | 56 "/Tj/show load def/Ff/findfont load def/Fs/sc
alefont load def/Sf/setfont load def\n" |
57 "/cm/concat load def/Cm/currentmatrix load de
f/mx/matrix load def/sm/setmatrix load def\n" | 57 "/cm/concat load def/Cm/currentmatrix load de
f/mx/matrix load def/sm/setmatrix load def\n" |
58 ; | 58 ; |
59 OUTPUT_PS(init_str); | 59 OUTPUT_PS(init_str); |
60 m_bInited = TRUE; | 60 m_bInited = true; |
61 return TRUE; | 61 return true; |
62 } | 62 } |
63 void CFX_PSRenderer::EndRendering() | 63 void CFX_PSRenderer::EndRendering() |
64 { | 64 { |
65 if (m_bInited) { | 65 if (m_bInited) { |
66 OUTPUT_PS("\nrestore\n"); | 66 OUTPUT_PS("\nrestore\n"); |
67 } | 67 } |
68 m_bInited = FALSE; | 68 m_bInited = false; |
69 } | 69 } |
70 void CFX_PSRenderer::SaveState() | 70 void CFX_PSRenderer::SaveState() |
71 { | 71 { |
72 StartRendering(); | 72 StartRendering(); |
73 OUTPUT_PS("q\n"); | 73 OUTPUT_PS("q\n"); |
74 m_ClipBoxStack.Add(m_ClipBox); | 74 m_ClipBoxStack.Add(m_ClipBox); |
75 } | 75 } |
76 void CFX_PSRenderer::RestoreState(FX_BOOL bKeepSaved) | 76 void CFX_PSRenderer::RestoreState(bool bKeepSaved) |
77 { | 77 { |
78 StartRendering(); | 78 StartRendering(); |
79 if (bKeepSaved) { | 79 if (bKeepSaved) { |
80 OUTPUT_PS("Q\nq\n"); | 80 OUTPUT_PS("Q\nq\n"); |
81 } else { | 81 } else { |
82 OUTPUT_PS("Q\n"); | 82 OUTPUT_PS("Q\n"); |
83 } | 83 } |
84 m_bColorSet = m_bGraphStateSet = FALSE; | 84 m_bColorSet = m_bGraphStateSet = false; |
85 m_ClipBox = m_ClipBoxStack.GetAt(m_ClipBoxStack.GetSize() - 1); | 85 m_ClipBox = m_ClipBoxStack.GetAt(m_ClipBoxStack.GetSize() - 1); |
86 if (!bKeepSaved) { | 86 if (!bKeepSaved) { |
87 m_ClipBoxStack.RemoveAt(m_ClipBoxStack.GetSize() - 1); | 87 m_ClipBoxStack.RemoveAt(m_ClipBoxStack.GetSize() - 1); |
88 } | 88 } |
89 } | 89 } |
90 void CFX_PSRenderer::OutputPath(const CFX_PathData* pPathData, const CFX_AffineM
atrix* pObject2Device) | 90 void CFX_PSRenderer::OutputPath(const CFX_PathData* pPathData, const CFX_AffineM
atrix* pObject2Device) |
91 { | 91 { |
92 int nPoints = pPathData->GetPointCount(); | 92 int nPoints = pPathData->GetPointCount(); |
93 CFX_ByteTextBuf buf; | 93 CFX_ByteTextBuf buf; |
94 buf.EstimateSize(nPoints * 10); | 94 buf.EstimateSize(nPoints * 10); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 OutputPath(pPathData, NULL); | 168 OutputPath(pPathData, NULL); |
169 CFX_FloatRect rect = pPathData->GetBoundingBox(pGraphState->m_LineWidth, pGr
aphState->m_MiterLimit); | 169 CFX_FloatRect rect = pPathData->GetBoundingBox(pGraphState->m_LineWidth, pGr
aphState->m_MiterLimit); |
170 rect.Transform(pObject2Device); | 170 rect.Transform(pObject2Device); |
171 m_ClipBox.Intersect(rect.GetOutterRect()); | 171 m_ClipBox.Intersect(rect.GetOutterRect()); |
172 if (pObject2Device) { | 172 if (pObject2Device) { |
173 OUTPUT_PS("strokepath W n sm\n"); | 173 OUTPUT_PS("strokepath W n sm\n"); |
174 } else { | 174 } else { |
175 OUTPUT_PS("strokepath W n\n"); | 175 OUTPUT_PS("strokepath W n\n"); |
176 } | 176 } |
177 } | 177 } |
178 FX_BOOL CFX_PSRenderer::DrawPath(const CFX_PathData* pPathData, | 178 bool CFX_PSRenderer::DrawPath(const CFX_PathData* pPathData, |
179 const CFX_AffineMatrix* pObject2Device, | 179 const CFX_AffineMatrix* pObject2Device, |
180 const CFX_GraphStateData* pGraphState, | 180 const CFX_GraphStateData* pGraphState, |
181 FX_DWORD fill_color, | 181 FX_DWORD fill_color, |
182 FX_DWORD stroke_color, | 182 FX_DWORD stroke_color, |
183 int fill_mode, | 183 int fill_mode, |
184 int alpha_flag, | 184 int alpha_flag, |
185 void* pIccTransform | 185 void* pIccTransform |
186 ) | 186 ) |
187 { | 187 { |
188 StartRendering(); | 188 StartRendering(); |
189 int fill_alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_FILL(alph
a_flag) : FXARGB_A(fill_color); | 189 int fill_alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_FILL(alph
a_flag) : FXARGB_A(fill_color); |
190 int stroke_alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_STROKE(
alpha_flag) : FXARGB_A(stroke_color); | 190 int stroke_alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_STROKE(
alpha_flag) : FXARGB_A(stroke_color); |
191 if (fill_alpha && fill_alpha < 255) { | 191 if (fill_alpha && fill_alpha < 255) { |
192 return FALSE; | 192 return false; |
193 } | 193 } |
194 if (stroke_alpha && stroke_alpha < 255) { | 194 if (stroke_alpha && stroke_alpha < 255) { |
195 return FALSE; | 195 return false; |
196 } | 196 } |
197 if (fill_alpha == 0 && stroke_alpha == 0) { | 197 if (fill_alpha == 0 && stroke_alpha == 0) { |
198 return FALSE; | 198 return false; |
199 } | 199 } |
200 if (stroke_alpha) { | 200 if (stroke_alpha) { |
201 SetGraphState(pGraphState); | 201 SetGraphState(pGraphState); |
202 if (pObject2Device) { | 202 if (pObject2Device) { |
203 CFX_ByteTextBuf buf; | 203 CFX_ByteTextBuf buf; |
204 buf << FX_BSTRC("mx Cm [") << pObject2Device->a << FX_BSTRC(" ") <<
pObject2Device->b << FX_BSTRC(" ") << | 204 buf << FX_BSTRC("mx Cm [") << pObject2Device->a << FX_BSTRC(" ") <<
pObject2Device->b << FX_BSTRC(" ") << |
205 pObject2Device->c << FX_BSTRC(" ") << pObject2Device->d << FX_BS
TRC(" ") << pObject2Device->e << | 205 pObject2Device->c << FX_BSTRC(" ") << pObject2Device->d << FX_BS
TRC(" ") << pObject2Device->e << |
206 FX_BSTRC(" ") << pObject2Device->f << FX_BSTRC("]cm "); | 206 FX_BSTRC(" ") << pObject2Device->f << FX_BSTRC("]cm "); |
207 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); | 207 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); |
208 } | 208 } |
(...skipping 17 matching lines...) Expand all Loading... |
226 } | 226 } |
227 if (stroke_alpha) { | 227 if (stroke_alpha) { |
228 SetColor(stroke_color, alpha_flag, pIccTransform); | 228 SetColor(stroke_color, alpha_flag, pIccTransform); |
229 if (pObject2Device) { | 229 if (pObject2Device) { |
230 OUTPUT_PS("s sm"); | 230 OUTPUT_PS("s sm"); |
231 } else { | 231 } else { |
232 OUTPUT_PS("s"); | 232 OUTPUT_PS("s"); |
233 } | 233 } |
234 } | 234 } |
235 OUTPUT_PS("\n"); | 235 OUTPUT_PS("\n"); |
236 return TRUE; | 236 return true; |
237 } | 237 } |
238 void CFX_PSRenderer::SetGraphState(const CFX_GraphStateData* pGraphState) | 238 void CFX_PSRenderer::SetGraphState(const CFX_GraphStateData* pGraphState) |
239 { | 239 { |
240 CFX_ByteTextBuf buf; | 240 CFX_ByteTextBuf buf; |
241 if (!m_bGraphStateSet || m_CurGraphState.m_LineCap != pGraphState->m_LineCap
) { | 241 if (!m_bGraphStateSet || m_CurGraphState.m_LineCap != pGraphState->m_LineCap
) { |
242 buf << pGraphState->m_LineCap << FX_BSTRC(" J\n"); | 242 buf << pGraphState->m_LineCap << FX_BSTRC(" J\n"); |
243 } | 243 } |
244 if (!m_bGraphStateSet || m_CurGraphState.m_DashCount != pGraphState->m_DashC
ount || | 244 if (!m_bGraphStateSet || m_CurGraphState.m_DashCount != pGraphState->m_DashC
ount || |
245 FXSYS_memcmp(m_CurGraphState.m_DashArray, pGraphState->m_DashArray,
sizeof(FX_FLOAT)*m_CurGraphState.m_DashCount)) { | 245 FXSYS_memcmp(m_CurGraphState.m_DashArray, pGraphState->m_DashArray,
sizeof(FX_FLOAT)*m_CurGraphState.m_DashCount)) { |
246 buf << FX_BSTRC("["); | 246 buf << FX_BSTRC("["); |
247 for (int i = 0; i < pGraphState->m_DashCount; i ++) { | 247 for (int i = 0; i < pGraphState->m_DashCount; i ++) { |
248 buf << pGraphState->m_DashArray[i] << FX_BSTRC(" "); | 248 buf << pGraphState->m_DashArray[i] << FX_BSTRC(" "); |
249 } | 249 } |
250 buf << FX_BSTRC("]") << pGraphState->m_DashPhase << FX_BSTRC(" d\n"); | 250 buf << FX_BSTRC("]") << pGraphState->m_DashPhase << FX_BSTRC(" d\n"); |
251 } | 251 } |
252 if (!m_bGraphStateSet || m_CurGraphState.m_LineJoin != pGraphState->m_LineJo
in) { | 252 if (!m_bGraphStateSet || m_CurGraphState.m_LineJoin != pGraphState->m_LineJo
in) { |
253 buf << pGraphState->m_LineJoin << FX_BSTRC(" j\n"); | 253 buf << pGraphState->m_LineJoin << FX_BSTRC(" j\n"); |
254 } | 254 } |
255 if (!m_bGraphStateSet || m_CurGraphState.m_LineWidth != pGraphState->m_LineW
idth) { | 255 if (!m_bGraphStateSet || m_CurGraphState.m_LineWidth != pGraphState->m_LineW
idth) { |
256 buf << pGraphState->m_LineWidth << FX_BSTRC(" w\n"); | 256 buf << pGraphState->m_LineWidth << FX_BSTRC(" w\n"); |
257 } | 257 } |
258 if (!m_bGraphStateSet || m_CurGraphState.m_MiterLimit != pGraphState->m_Mite
rLimit) { | 258 if (!m_bGraphStateSet || m_CurGraphState.m_MiterLimit != pGraphState->m_Mite
rLimit) { |
259 buf << pGraphState->m_MiterLimit << FX_BSTRC(" M\n"); | 259 buf << pGraphState->m_MiterLimit << FX_BSTRC(" M\n"); |
260 } | 260 } |
261 m_CurGraphState.Copy(*pGraphState); | 261 m_CurGraphState.Copy(*pGraphState); |
262 m_bGraphStateSet = TRUE; | 262 m_bGraphStateSet = true; |
263 if (buf.GetSize()) { | 263 if (buf.GetSize()) { |
264 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); | 264 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); |
265 } | 265 } |
266 } | 266 } |
267 static void FaxCompressData(uint8_t* src_buf, int width, int height, uint8_t*& d
est_buf, FX_DWORD& dest_size) | 267 static void FaxCompressData(uint8_t* src_buf, int width, int height, uint8_t*& d
est_buf, FX_DWORD& dest_size) |
268 { | 268 { |
269 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); | 269 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); |
270 if (width * height > 128 && pEncoders && pEncoders->GetFaxModule()->Encode(s
rc_buf, width, height, (width + 7) / 8, dest_buf, dest_size)) { | 270 if (width * height > 128 && pEncoders && pEncoders->GetFaxModule()->Encode(s
rc_buf, width, height, (width + 7) / 8, dest_buf, dest_size)) { |
271 FX_Free(src_buf); | 271 FX_Free(src_buf); |
272 } else { | 272 } else { |
(...skipping 25 matching lines...) Expand all Loading... |
298 if (dest_size < src_size) { | 298 if (dest_size < src_size) { |
299 output_buf = dest_buf; | 299 output_buf = dest_buf; |
300 output_size = dest_size; | 300 output_size = dest_size; |
301 } else { | 301 } else { |
302 filter = NULL; | 302 filter = NULL; |
303 if (dest_buf) { | 303 if (dest_buf) { |
304 FX_Free(dest_buf); | 304 FX_Free(dest_buf); |
305 } | 305 } |
306 } | 306 } |
307 } | 307 } |
308 FX_BOOL CFX_PSRenderer::SetDIBits(const CFX_DIBSource* pSource, FX_DWORD color,
int left, int top, | 308 bool CFX_PSRenderer::SetDIBits(const CFX_DIBSource* pSource, FX_DWORD color, int
left, int top, |
309 int alpha_flag, void* pIccTransform) | 309 int alpha_flag, void* pIccTransform) |
310 { | 310 { |
311 StartRendering(); | 311 StartRendering(); |
312 CFX_AffineMatrix matrix((FX_FLOAT)(pSource->GetWidth()), 0.0f, 0.0f, -(FX_FL
OAT)(pSource->GetHeight()), | 312 CFX_AffineMatrix matrix((FX_FLOAT)(pSource->GetWidth()), 0.0f, 0.0f, -(FX_FL
OAT)(pSource->GetHeight()), |
313 (FX_FLOAT)(left), (FX_FLOAT)(top + pSource->GetHeigh
t())); | 313 (FX_FLOAT)(left), (FX_FLOAT)(top + pSource->GetHeigh
t())); |
314 return DrawDIBits(pSource, color, &matrix, 0, alpha_flag, pIccTransform); | 314 return DrawDIBits(pSource, color, &matrix, 0, alpha_flag, pIccTransform); |
315 } | 315 } |
316 FX_BOOL CFX_PSRenderer::StretchDIBits(const CFX_DIBSource* pSource, FX_DWORD col
or, int dest_left, int dest_top, | 316 bool CFX_PSRenderer::StretchDIBits(const CFX_DIBSource* pSource, FX_DWORD color,
int dest_left, int dest_top, |
317 int dest_width, int dest_height, FX_DWORD
flags, | 317 int dest_width, int dest_height, FX_DWORD
flags, |
318 int alpha_flag, void* pIccTransform) | 318 int alpha_flag, void* pIccTransform) |
319 { | 319 { |
320 StartRendering(); | 320 StartRendering(); |
321 CFX_AffineMatrix matrix((FX_FLOAT)(dest_width), 0.0f, 0.0f, (FX_FLOAT)(-dest
_height), | 321 CFX_AffineMatrix matrix((FX_FLOAT)(dest_width), 0.0f, 0.0f, (FX_FLOAT)(-dest
_height), |
322 (FX_FLOAT)(dest_left), (FX_FLOAT)(dest_top + dest_he
ight)); | 322 (FX_FLOAT)(dest_left), (FX_FLOAT)(dest_top + dest_he
ight)); |
323 return DrawDIBits(pSource, color, &matrix, flags, alpha_flag, pIccTransform)
; | 323 return DrawDIBits(pSource, color, &matrix, flags, alpha_flag, pIccTransform)
; |
324 } | 324 } |
325 FX_BOOL CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource, FX_DWORD color, | 325 bool CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource, FX_DWORD color, |
326 const CFX_AffineMatrix* pMatrix, FX_DWORD fla
gs, | 326 const CFX_AffineMatrix* pMatrix, FX_DWORD fla
gs, |
327 int alpha_flag, void* pIccTransform) | 327 int alpha_flag, void* pIccTransform) |
328 { | 328 { |
329 StartRendering(); | 329 StartRendering(); |
330 if ((pMatrix->a == 0 && pMatrix->b == 0) || (pMatrix->c == 0 && pMatrix->d =
= 0)) { | 330 if ((pMatrix->a == 0 && pMatrix->b == 0) || (pMatrix->c == 0 && pMatrix->d =
= 0)) { |
331 return TRUE; | 331 return true; |
332 } | 332 } |
333 if (pSource->HasAlpha()) { | 333 if (pSource->HasAlpha()) { |
334 return FALSE; | 334 return false; |
335 } | 335 } |
336 int alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_FILL(color) :
FXARGB_A(color); | 336 int alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_FILL(color) :
FXARGB_A(color); |
337 if (pSource->IsAlphaMask() && (alpha < 255 || pSource->GetBPP() != 1)) { | 337 if (pSource->IsAlphaMask() && (alpha < 255 || pSource->GetBPP() != 1)) { |
338 return FALSE; | 338 return false; |
339 } | 339 } |
340 OUTPUT_PS("q\n"); | 340 OUTPUT_PS("q\n"); |
341 CFX_ByteTextBuf buf; | 341 CFX_ByteTextBuf buf; |
342 buf << FX_BSTRC("[") << pMatrix->a << FX_BSTRC(" ") << pMatrix->b << FX_BSTR
C(" ") << | 342 buf << FX_BSTRC("[") << pMatrix->a << FX_BSTRC(" ") << pMatrix->b << FX_BSTR
C(" ") << |
343 pMatrix->c << FX_BSTRC(" ") << pMatrix->d << FX_BSTRC(" ") << pMatrix->e
<< | 343 pMatrix->c << FX_BSTRC(" ") << pMatrix->d << FX_BSTRC(" ") << pMatrix->e
<< |
344 FX_BSTRC(" ") << pMatrix->f << FX_BSTRC("]cm "); | 344 FX_BSTRC(" ") << pMatrix->f << FX_BSTRC("]cm "); |
345 int width = pSource->GetWidth(); | 345 int width = pSource->GetWidth(); |
346 int height = pSource->GetHeight(); | 346 int height = pSource->GetHeight(); |
347 buf << width << FX_BSTRC(" ") << height; | 347 buf << width << FX_BSTRC(" ") << height; |
348 if (pSource->GetBPP() == 1 && pSource->GetPalette() == NULL) { | 348 if (pSource->GetBPP() == 1 && pSource->GetPalette() == NULL) { |
349 int pitch = (width + 7) / 8; | 349 int pitch = (width + 7) / 8; |
350 FX_DWORD src_size = height * pitch; | 350 FX_DWORD src_size = height * pitch; |
351 uint8_t* src_buf = FX_Alloc(uint8_t, src_size); | 351 uint8_t* src_buf = FX_Alloc(uint8_t, src_size); |
352 for (int row = 0; row < height; row ++) { | 352 for (int row = 0; row < height; row ++) { |
353 const uint8_t* src_scan = pSource->GetScanline(row); | 353 const uint8_t* src_scan = pSource->GetScanline(row); |
354 FXSYS_memcpy(src_buf + row * pitch, src_scan, pitch); | 354 FXSYS_memcpy(src_buf + row * pitch, src_scan, pitch); |
355 } | 355 } |
356 uint8_t* output_buf; | 356 uint8_t* output_buf; |
357 FX_DWORD output_size; | 357 FX_DWORD output_size; |
358 FaxCompressData(src_buf, width, height, output_buf, output_size); | 358 FaxCompressData(src_buf, width, height, output_buf, output_size); |
359 if (pSource->IsAlphaMask()) { | 359 if (pSource->IsAlphaMask()) { |
360 SetColor(color, alpha_flag, pIccTransform); | 360 SetColor(color, alpha_flag, pIccTransform); |
361 m_bColorSet = FALSE; | 361 m_bColorSet = false; |
362 buf << FX_BSTRC(" true["); | 362 buf << FX_BSTRC(" true["); |
363 } else { | 363 } else { |
364 buf << FX_BSTRC(" 1["); | 364 buf << FX_BSTRC(" 1["); |
365 } | 365 } |
366 buf << width << FX_BSTRC(" 0 0 -") << height << FX_BSTRC(" 0 ") << heigh
t << | 366 buf << width << FX_BSTRC(" 0 0 -") << height << FX_BSTRC(" 0 ") << heigh
t << |
367 FX_BSTRC("]currentfile/ASCII85Decode filter "); | 367 FX_BSTRC("]currentfile/ASCII85Decode filter "); |
368 if (output_buf != src_buf) | 368 if (output_buf != src_buf) |
369 buf << FX_BSTRC("<</K -1/EndOfBlock false/Columns ") << width << FX_
BSTRC("/Rows ") << height << | 369 buf << FX_BSTRC("<</K -1/EndOfBlock false/Columns ") << width << FX_
BSTRC("/Rows ") << height << |
370 FX_BSTRC(">>/CCITTFaxDecode filter "); | 370 FX_BSTRC(">>/CCITTFaxDecode filter "); |
371 if (pSource->IsAlphaMask()) { | 371 if (pSource->IsAlphaMask()) { |
(...skipping 27 matching lines...) Expand all Loading... |
399 if (pSource->GetPalette() != NULL) { | 399 if (pSource->GetPalette() != NULL) { |
400 pConverted = pSource->CloneConvert(FXDIB_Cmyk); | 400 pConverted = pSource->CloneConvert(FXDIB_Cmyk); |
401 } | 401 } |
402 break; | 402 break; |
403 default: | 403 default: |
404 break; | 404 break; |
405 } | 405 } |
406 } | 406 } |
407 if (pConverted == NULL) { | 407 if (pConverted == NULL) { |
408 OUTPUT_PS("\nQ\n"); | 408 OUTPUT_PS("\nQ\n"); |
409 return FALSE; | 409 return false; |
410 } | 410 } |
411 int Bpp = pConverted->GetBPP() / 8; | 411 int Bpp = pConverted->GetBPP() / 8; |
412 uint8_t* output_buf = NULL; | 412 uint8_t* output_buf = NULL; |
413 FX_STRSIZE output_size = 0; | 413 FX_STRSIZE output_size = 0; |
414 const FX_CHAR* filter = NULL; | 414 const FX_CHAR* filter = NULL; |
415 if (flags & FXRENDER_IMAGE_LOSSY) { | 415 if (flags & FXRENDER_IMAGE_LOSSY) { |
416 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); | 416 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); |
417 if (pEncoders && pEncoders->GetJpegModule()->Encode(pConverted, outp
ut_buf, output_size)) { | 417 if (pEncoders && pEncoders->GetJpegModule()->Encode(pConverted, outp
ut_buf, output_size)) { |
418 filter = "/DCTDecode filter "; | 418 filter = "/DCTDecode filter "; |
419 } | 419 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 if (filter) { | 455 if (filter) { |
456 buf << filter; | 456 buf << filter; |
457 } | 457 } |
458 buf << FX_BSTRC("false ") << Bpp; | 458 buf << FX_BSTRC("false ") << Bpp; |
459 buf << FX_BSTRC(" colorimage\n"); | 459 buf << FX_BSTRC(" colorimage\n"); |
460 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); | 460 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); |
461 WritePSBinary(output_buf, output_size); | 461 WritePSBinary(output_buf, output_size); |
462 FX_Free(output_buf); | 462 FX_Free(output_buf); |
463 } | 463 } |
464 OUTPUT_PS("\nQ\n"); | 464 OUTPUT_PS("\nQ\n"); |
465 return TRUE; | 465 return true; |
466 } | 466 } |
467 void CFX_PSRenderer::SetColor(FX_DWORD color, int alpha_flag, void* pIccTransfor
m) | 467 void CFX_PSRenderer::SetColor(FX_DWORD color, int alpha_flag, void* pIccTransfor
m) |
468 { | 468 { |
469 if (!CFX_GEModule::Get()->GetCodecModule() || !CFX_GEModule::Get()->GetCodec
Module()->GetIccModule()) { | 469 if (!CFX_GEModule::Get()->GetCodecModule() || !CFX_GEModule::Get()->GetCodec
Module()->GetIccModule()) { |
470 pIccTransform = NULL; | 470 pIccTransform = NULL; |
471 } | 471 } |
472 FX_BOOL bCMYK = FALSE; | 472 bool bCMYK = false; |
473 if (pIccTransform) { | 473 if (pIccTransform) { |
474 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge
tIccModule(); | 474 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge
tIccModule(); |
475 color = FXGETFLAG_COLORTYPE(alpha_flag) ? FXCMYK_TODIB(color) : FXARGB_T
ODIB(color); | 475 color = FXGETFLAG_COLORTYPE(alpha_flag) ? FXCMYK_TODIB(color) : FXARGB_T
ODIB(color); |
476 uint8_t* pColor = (uint8_t*)&color; | 476 uint8_t* pColor = (uint8_t*)&color; |
477 pIccModule->TranslateScanline(pIccTransform, pColor, pColor, 1); | 477 pIccModule->TranslateScanline(pIccTransform, pColor, pColor, 1); |
478 color = m_bCmykOutput ? FXCMYK_TODIB(color) : FXARGB_TODIB(color); | 478 color = m_bCmykOutput ? FXCMYK_TODIB(color) : FXARGB_TODIB(color); |
479 bCMYK = m_bCmykOutput; | 479 bCMYK = m_bCmykOutput; |
480 } else { | 480 } else { |
481 bCMYK = FXGETFLAG_COLORTYPE(alpha_flag); | 481 bCMYK = FXGETFLAG_COLORTYPE(alpha_flag); |
482 } | 482 } |
483 if (bCMYK != m_bCmykOutput || !m_bColorSet || m_LastColor != color) { | 483 if (bCMYK != m_bCmykOutput || !m_bColorSet || m_LastColor != color) { |
484 CFX_ByteTextBuf buf; | 484 CFX_ByteTextBuf buf; |
485 if (bCMYK) { | 485 if (bCMYK) { |
486 buf << FXSYS_GetCValue(color) / 255.0 << FX_BSTRC(" ") << FXSYS_GetM
Value(color) / 255.0 << FX_BSTRC(" ") | 486 buf << FXSYS_GetCValue(color) / 255.0 << FX_BSTRC(" ") << FXSYS_GetM
Value(color) / 255.0 << FX_BSTRC(" ") |
487 << FXSYS_GetYValue(color) / 255.0 << FX_BSTRC(" ") << FXSYS_GetK
Value(color) / 255.0 << FX_BSTRC(" k\n"); | 487 << FXSYS_GetYValue(color) / 255.0 << FX_BSTRC(" ") << FXSYS_GetK
Value(color) / 255.0 << FX_BSTRC(" k\n"); |
488 } else { | 488 } else { |
489 buf << FXARGB_R(color) / 255.0 << FX_BSTRC(" ") << FXARGB_G(color) /
255.0 << FX_BSTRC(" ") | 489 buf << FXARGB_R(color) / 255.0 << FX_BSTRC(" ") << FXARGB_G(color) /
255.0 << FX_BSTRC(" ") |
490 << FXARGB_B(color) / 255.0 << FX_BSTRC(" rg\n"); | 490 << FXARGB_B(color) / 255.0 << FX_BSTRC(" rg\n"); |
491 } | 491 } |
492 if (bCMYK == m_bCmykOutput) { | 492 if (bCMYK == m_bCmykOutput) { |
493 m_bColorSet = TRUE; | 493 m_bColorSet = true; |
494 m_LastColor = color; | 494 m_LastColor = color; |
495 } | 495 } |
496 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); | 496 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); |
497 } | 497 } |
498 } | 498 } |
499 void CFX_PSRenderer::FindPSFontGlyph(CFX_FaceCache* pFaceCache, CFX_Font* pFont,
const FXTEXT_CHARPOS& charpos, | 499 void CFX_PSRenderer::FindPSFontGlyph(CFX_FaceCache* pFaceCache, CFX_Font* pFont,
const FXTEXT_CHARPOS& charpos, |
500 int& ps_fontnum, int &ps_glyphindex) | 500 int& ps_fontnum, int &ps_glyphindex) |
501 { | 501 { |
502 for (int i = 0; i < (int)m_PSFontList.GetSize(); i ++) { | 502 for (int i = 0; i < (int)m_PSFontList.GetSize(); i ++) { |
503 CPSFont* pPSFont = m_PSFontList[i]; | 503 CPSFont* pPSFont = m_PSFontList[i]; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 break; | 581 break; |
582 } | 582 } |
583 } | 583 } |
584 } | 584 } |
585 buf << FX_BSTRC("f"); | 585 buf << FX_BSTRC("f"); |
586 buf << FX_BSTRC("}bind def end\n"); | 586 buf << FX_BSTRC("}bind def end\n"); |
587 buf << FX_BSTRC("/X") << ps_fontnum << FX_BSTRC(" Ff/Encoding get ") << ps_g
lyphindex | 587 buf << FX_BSTRC("/X") << ps_fontnum << FX_BSTRC(" Ff/Encoding get ") << ps_g
lyphindex |
588 << FX_BSTRC("/") << ps_glyphindex << FX_BSTRC(" put\n"); | 588 << FX_BSTRC("/") << ps_glyphindex << FX_BSTRC(" put\n"); |
589 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); | 589 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); |
590 } | 590 } |
591 FX_BOOL CFX_PSRenderer::DrawText(int nChars, const FXTEXT_CHARPOS* pCharPos, CFX
_Font* pFont, | 591 bool CFX_PSRenderer::DrawText(int nChars, const FXTEXT_CHARPOS* pCharPos, CFX_Fo
nt* pFont, |
592 CFX_FontCache* pCache, const CFX_AffineMatrix*
pObject2Device, | 592 CFX_FontCache* pCache, const CFX_AffineMatrix*
pObject2Device, |
593 FX_FLOAT font_size, FX_DWORD color, | 593 FX_FLOAT font_size, FX_DWORD color, |
594 int alpha_flag, void* pIccTransform) | 594 int alpha_flag, void* pIccTransform) |
595 { | 595 { |
596 StartRendering(); | 596 StartRendering(); |
597 int alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_FILL(alpha_fla
g) : FXARGB_A(color); | 597 int alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_FILL(alpha_fla
g) : FXARGB_A(color); |
598 if (alpha < 255) { | 598 if (alpha < 255) { |
599 return FALSE; | 599 return false; |
600 } | 600 } |
601 if ((pObject2Device->a == 0 && pObject2Device->b == 0) || (pObject2Device->c
== 0 && pObject2Device->d == 0)) { | 601 if ((pObject2Device->a == 0 && pObject2Device->b == 0) || (pObject2Device->c
== 0 && pObject2Device->d == 0)) { |
602 return TRUE; | 602 return true; |
603 } | 603 } |
604 SetColor(color, alpha_flag, pIccTransform); | 604 SetColor(color, alpha_flag, pIccTransform); |
605 CFX_ByteTextBuf buf; | 605 CFX_ByteTextBuf buf; |
606 buf << FX_BSTRC("q[") << pObject2Device->a << FX_BSTRC(" ") << pObject2Devic
e->b << FX_BSTRC(" ") | 606 buf << FX_BSTRC("q[") << pObject2Device->a << FX_BSTRC(" ") << pObject2Devic
e->b << FX_BSTRC(" ") |
607 << pObject2Device->c << FX_BSTRC(" ") << pObject2Device->d; | 607 << pObject2Device->c << FX_BSTRC(" ") << pObject2Device->d; |
608 buf << FX_BSTRC(" ") << pObject2Device->e << FX_BSTRC(" ") << pObject2Device
->f << "]cm\n"; | 608 buf << FX_BSTRC(" ") << pObject2Device->e << FX_BSTRC(" ") << pObject2Device
->f << "]cm\n"; |
609 if (pCache == NULL) { | 609 if (pCache == NULL) { |
610 pCache = CFX_GEModule::Get()->GetFontCache(); | 610 pCache = CFX_GEModule::Get()->GetFontCache(); |
611 } | 611 } |
612 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont); | 612 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont); |
613 FX_FONTCACHE_DEFINE(pCache, pFont); | 613 FX_FONTCACHE_DEFINE(pCache, pFont); |
614 int last_fontnum = -1; | 614 int last_fontnum = -1; |
615 for (int i = 0; i < nChars; i ++) { | 615 for (int i = 0; i < nChars; i ++) { |
616 int ps_fontnum, ps_glyphindex; | 616 int ps_fontnum, ps_glyphindex; |
617 FindPSFontGlyph(pFaceCache, pFont, pCharPos[i], ps_fontnum, ps_glyphinde
x); | 617 FindPSFontGlyph(pFaceCache, pFont, pCharPos[i], ps_fontnum, ps_glyphinde
x); |
618 if (last_fontnum != ps_fontnum) { | 618 if (last_fontnum != ps_fontnum) { |
619 buf << FX_BSTRC("/X") << ps_fontnum << FX_BSTRC(" Ff ") << font_size | 619 buf << FX_BSTRC("/X") << ps_fontnum << FX_BSTRC(" Ff ") << font_size |
620 << FX_BSTRC(" Fs Sf "); | 620 << FX_BSTRC(" Fs Sf "); |
621 last_fontnum = ps_fontnum; | 621 last_fontnum = ps_fontnum; |
622 } | 622 } |
623 buf << pCharPos[i].m_OriginX << FX_BSTRC(" ") | 623 buf << pCharPos[i].m_OriginX << FX_BSTRC(" ") |
624 << pCharPos[i].m_OriginY << FX_BSTRC(" m"); | 624 << pCharPos[i].m_OriginY << FX_BSTRC(" m"); |
625 CFX_ByteString hex; | 625 CFX_ByteString hex; |
626 hex.Format("<%02X>", ps_glyphindex); | 626 hex.Format("<%02X>", ps_glyphindex); |
627 buf << hex << FX_BSTRC("Tj\n"); | 627 buf << hex << FX_BSTRC("Tj\n"); |
628 } | 628 } |
629 buf << FX_BSTRC("Q\n"); | 629 buf << FX_BSTRC("Q\n"); |
630 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); | 630 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); |
631 return TRUE; | 631 return true; |
632 } | 632 } |
633 void CFX_PSRenderer::WritePSBinary(const uint8_t* data, int len) | 633 void CFX_PSRenderer::WritePSBinary(const uint8_t* data, int len) |
634 { | 634 { |
635 uint8_t* dest_buf; | 635 uint8_t* dest_buf; |
636 FX_DWORD dest_size; | 636 FX_DWORD dest_size; |
637 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); | 637 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); |
638 if (pEncoders && pEncoders->GetBasicModule()->A85Encode(data, len, dest_buf,
dest_size)) { | 638 if (pEncoders && pEncoders->GetBasicModule()->A85Encode(data, len, dest_buf,
dest_size)) { |
639 m_pOutput->OutputPS((const FX_CHAR*)dest_buf, dest_size); | 639 m_pOutput->OutputPS((const FX_CHAR*)dest_buf, dest_size); |
640 FX_Free(dest_buf); | 640 FX_Free(dest_buf); |
641 } else { | 641 } else { |
642 m_pOutput->OutputPS((const FX_CHAR*)data, len); | 642 m_pOutput->OutputPS((const FX_CHAR*)data, len); |
643 } | 643 } |
644 } | 644 } |
OLD | NEW |