1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "fpdfsdk/include/pdfwindow/PWL_Utils.h"
8 
9 #include <algorithm>
10 
11 #include "fpdfsdk/include/pdfwindow/PWL_Icon.h"
12 #include "fpdfsdk/include/pdfwindow/PWL_Wnd.h"
13 
14 #define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
15 #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
16 #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
17 #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb))
18 
GetAppStreamFromArray(const CPWL_PathData * pPathData,int32_t nCount)19 CFX_ByteString CPWL_Utils::GetAppStreamFromArray(const CPWL_PathData* pPathData,
20                                                  int32_t nCount) {
21   CFX_ByteTextBuf csAP;
22 
23   for (int32_t i = 0; i < nCount; i++) {
24     switch (pPathData[i].type) {
25       case PWLPT_MOVETO:
26         csAP << pPathData[i].point.x << " " << pPathData[i].point.y << " m\n";
27         break;
28       case PWLPT_LINETO:
29         csAP << pPathData[i].point.x << " " << pPathData[i].point.y << " l\n";
30         break;
31       case PWLPT_BEZIERTO:
32         csAP << pPathData[i].point.x << " " << pPathData[i].point.y << " "
33              << pPathData[i + 1].point.x << " " << pPathData[i + 1].point.y
34              << " " << pPathData[i + 2].point.x << " "
35              << pPathData[i + 2].point.y << " c\n";
36 
37         i += 2;
38         break;
39       default:
40         break;
41     }
42   }
43 
44   return csAP.GetByteString();
45 }
46 
GetPathDataFromArray(CFX_PathData & path,const CPWL_PathData * pPathData,int32_t nCount)47 void CPWL_Utils::GetPathDataFromArray(CFX_PathData& path,
48                                       const CPWL_PathData* pPathData,
49                                       int32_t nCount) {
50   path.SetPointCount(nCount);
51 
52   for (int32_t i = 0; i < nCount; i++) {
53     switch (pPathData[i].type) {
54       case PWLPT_MOVETO:
55         path.SetPoint(i, pPathData[i].point.x, pPathData[i].point.y,
56                       FXPT_MOVETO);
57         break;
58       case PWLPT_LINETO:
59         path.SetPoint(i, pPathData[i].point.x, pPathData[i].point.y,
60                       FXPT_LINETO);
61         break;
62       case PWLPT_BEZIERTO:
63         path.SetPoint(i, pPathData[i].point.x, pPathData[i].point.y,
64                       FXPT_BEZIERTO);
65         break;
66       default:
67         break;
68     }
69   }
70 }
71 
MaxRect(const CPDF_Rect & rect1,const CPDF_Rect & rect2)72 CPDF_Rect CPWL_Utils::MaxRect(const CPDF_Rect& rect1, const CPDF_Rect& rect2) {
73   CPDF_Rect rcRet;
74 
75   rcRet.left = PWL_MIN(rect1.left, rect2.left);
76   rcRet.bottom = PWL_MIN(rect1.bottom, rect2.bottom);
77   rcRet.right = PWL_MAX(rect1.right, rect2.right);
78   rcRet.top = PWL_MAX(rect1.top, rect2.top);
79 
80   return rcRet;
81 }
82 
OffsetRect(const CPDF_Rect & rect,FX_FLOAT x,FX_FLOAT y)83 CPDF_Rect CPWL_Utils::OffsetRect(const CPDF_Rect& rect,
84                                  FX_FLOAT x,
85                                  FX_FLOAT y) {
86   return CPDF_Rect(rect.left + x, rect.bottom + y, rect.right + x,
87                    rect.top + y);
88 }
89 
ContainsRect(const CPDF_Rect & rcParent,const CPDF_Rect & rcChild)90 FX_BOOL CPWL_Utils::ContainsRect(const CPDF_Rect& rcParent,
91                                  const CPDF_Rect& rcChild) {
92   return rcChild.left >= rcParent.left && rcChild.bottom >= rcParent.bottom &&
93          rcChild.right <= rcParent.right && rcChild.top <= rcParent.top;
94 }
95 
IntersectRect(const CPDF_Rect & rect1,const CPDF_Rect & rect2)96 FX_BOOL CPWL_Utils::IntersectRect(const CPDF_Rect& rect1,
97                                   const CPDF_Rect& rect2) {
98   FX_FLOAT left = rect1.left > rect2.left ? rect1.left : rect2.left;
99   FX_FLOAT right = rect1.right < rect2.right ? rect1.right : rect2.right;
100   FX_FLOAT bottom = rect1.bottom > rect2.bottom ? rect1.bottom : rect2.bottom;
101   FX_FLOAT top = rect1.top < rect2.top ? rect1.top : rect2.top;
102 
103   return left < right && bottom < top;
104 }
105 
OffsetPoint(const CPDF_Point & point,FX_FLOAT x,FX_FLOAT y)106 CPDF_Point CPWL_Utils::OffsetPoint(const CPDF_Point& point,
107                                    FX_FLOAT x,
108                                    FX_FLOAT y) {
109   return CPDF_Point(point.x + x, point.y + y);
110 }
111 
OverlapWordRange(const CPVT_WordRange & wr1,const CPVT_WordRange & wr2)112 CPVT_WordRange CPWL_Utils::OverlapWordRange(const CPVT_WordRange& wr1,
113                                             const CPVT_WordRange& wr2) {
114   CPVT_WordRange wrRet;
115 
116   if (wr2.EndPos.WordCmp(wr1.BeginPos) < 0 ||
117       wr2.BeginPos.WordCmp(wr1.EndPos) > 0)
118     return wrRet;
119   if (wr1.EndPos.WordCmp(wr2.BeginPos) < 0 ||
120       wr1.BeginPos.WordCmp(wr2.EndPos) > 0)
121     return wrRet;
122 
123   if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0) {
124     wrRet.BeginPos = wr2.BeginPos;
125   } else {
126     wrRet.BeginPos = wr1.BeginPos;
127   }
128 
129   if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) {
130     wrRet.EndPos = wr1.EndPos;
131   } else {
132     wrRet.EndPos = wr2.EndPos;
133   }
134 
135   return wrRet;
136 }
137 
GetAP_Check(const CPDF_Rect & crBBox)138 CFX_ByteString CPWL_Utils::GetAP_Check(const CPDF_Rect& crBBox) {
139   const FX_FLOAT fWidth = crBBox.right - crBBox.left;
140   const FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
141 
142   CPWL_Point pts[8][3] = {{CPWL_Point(0.28f, 0.52f), CPWL_Point(0.27f, 0.48f),
143                            CPWL_Point(0.29f, 0.40f)},
144                           {CPWL_Point(0.30f, 0.33f), CPWL_Point(0.31f, 0.29f),
145                            CPWL_Point(0.31f, 0.28f)},
146                           {CPWL_Point(0.39f, 0.28f), CPWL_Point(0.49f, 0.29f),
147                            CPWL_Point(0.77f, 0.67f)},
148                           {CPWL_Point(0.76f, 0.68f), CPWL_Point(0.78f, 0.69f),
149                            CPWL_Point(0.76f, 0.75f)},
150                           {CPWL_Point(0.76f, 0.75f), CPWL_Point(0.73f, 0.80f),
151                            CPWL_Point(0.68f, 0.75f)},
152                           {CPWL_Point(0.68f, 0.74f), CPWL_Point(0.68f, 0.74f),
153                            CPWL_Point(0.44f, 0.47f)},
154                           {CPWL_Point(0.43f, 0.47f), CPWL_Point(0.40f, 0.47f),
155                            CPWL_Point(0.41f, 0.58f)},
156                           {CPWL_Point(0.40f, 0.60f), CPWL_Point(0.28f, 0.66f),
157                            CPWL_Point(0.30f, 0.56f)}};
158 
159   for (size_t i = 0; i < FX_ArraySize(pts); ++i) {
160     for (size_t j = 0; j < FX_ArraySize(pts[0]); ++j) {
161       pts[i][j].x = pts[i][j].x * fWidth + crBBox.left;
162       pts[i][j].y *= pts[i][j].y * fHeight + crBBox.bottom;
163     }
164   }
165 
166   CFX_ByteTextBuf csAP;
167   csAP << pts[0][0].x << " " << pts[0][0].y << " m\n";
168 
169   for (size_t i = 0; i < FX_ArraySize(pts); ++i) {
170     size_t nNext = i < FX_ArraySize(pts) - 1 ? i + 1 : 0;
171 
172     FX_FLOAT px1 = pts[i][1].x - pts[i][0].x;
173     FX_FLOAT py1 = pts[i][1].y - pts[i][0].y;
174     FX_FLOAT px2 = pts[i][2].x - pts[nNext][0].x;
175     FX_FLOAT py2 = pts[i][2].y - pts[nNext][0].y;
176 
177     csAP << pts[i][0].x + px1 * PWL_BEZIER << " "
178          << pts[i][0].y + py1 * PWL_BEZIER << " "
179          << pts[nNext][0].x + px2 * PWL_BEZIER << " "
180          << pts[nNext][0].y + py2 * PWL_BEZIER << " " << pts[nNext][0].x << " "
181          << pts[nNext][0].y << " c\n";
182   }
183 
184   return csAP.GetByteString();
185 }
186 
GetAP_Circle(const CPDF_Rect & crBBox)187 CFX_ByteString CPWL_Utils::GetAP_Circle(const CPDF_Rect& crBBox) {
188   CFX_ByteTextBuf csAP;
189 
190   FX_FLOAT fWidth = crBBox.right - crBBox.left;
191   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
192 
193   CPDF_Point pt1(crBBox.left, crBBox.bottom + fHeight / 2);
194   CPDF_Point pt2(crBBox.left + fWidth / 2, crBBox.top);
195   CPDF_Point pt3(crBBox.right, crBBox.bottom + fHeight / 2);
196   CPDF_Point pt4(crBBox.left + fWidth / 2, crBBox.bottom);
197 
198   csAP << pt1.x << " " << pt1.y << " m\n";
199 
200   FX_FLOAT px = pt2.x - pt1.x;
201   FX_FLOAT py = pt2.y - pt1.y;
202 
203   csAP << pt1.x << " " << pt1.y + py * PWL_BEZIER << " "
204        << pt2.x - px * PWL_BEZIER << " " << pt2.y << " " << pt2.x << " "
205        << pt2.y << " c\n";
206 
207   px = pt3.x - pt2.x;
208   py = pt2.y - pt3.y;
209 
210   csAP << pt2.x + px * PWL_BEZIER << " " << pt2.y << " " << pt3.x << " "
211        << pt3.y + py * PWL_BEZIER << " " << pt3.x << " " << pt3.y << " c\n";
212 
213   px = pt3.x - pt4.x;
214   py = pt3.y - pt4.y;
215 
216   csAP << pt3.x << " " << pt3.y - py * PWL_BEZIER << " "
217        << pt4.x + px * PWL_BEZIER << " " << pt4.y << " " << pt4.x << " "
218        << pt4.y << " c\n";
219 
220   px = pt4.x - pt1.x;
221   py = pt1.y - pt4.y;
222 
223   csAP << pt4.x - px * PWL_BEZIER << " " << pt4.y << " " << pt1.x << " "
224        << pt1.y - py * PWL_BEZIER << " " << pt1.x << " " << pt1.y << " c\n";
225 
226   return csAP.GetByteString();
227 }
228 
GetAP_Cross(const CPDF_Rect & crBBox)229 CFX_ByteString CPWL_Utils::GetAP_Cross(const CPDF_Rect& crBBox) {
230   CFX_ByteTextBuf csAP;
231 
232   csAP << crBBox.left << " " << crBBox.top << " m\n";
233   csAP << crBBox.right << " " << crBBox.bottom << " l\n";
234   csAP << crBBox.left << " " << crBBox.bottom << " m\n";
235   csAP << crBBox.right << " " << crBBox.top << " l\n";
236 
237   return csAP.GetByteString();
238 }
239 
GetAP_Diamond(const CPDF_Rect & crBBox)240 CFX_ByteString CPWL_Utils::GetAP_Diamond(const CPDF_Rect& crBBox) {
241   CFX_ByteTextBuf csAP;
242 
243   FX_FLOAT fWidth = crBBox.right - crBBox.left;
244   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
245 
246   CPDF_Point pt1(crBBox.left, crBBox.bottom + fHeight / 2);
247   CPDF_Point pt2(crBBox.left + fWidth / 2, crBBox.top);
248   CPDF_Point pt3(crBBox.right, crBBox.bottom + fHeight / 2);
249   CPDF_Point pt4(crBBox.left + fWidth / 2, crBBox.bottom);
250 
251   csAP << pt1.x << " " << pt1.y << " m\n";
252   csAP << pt2.x << " " << pt2.y << " l\n";
253   csAP << pt3.x << " " << pt3.y << " l\n";
254   csAP << pt4.x << " " << pt4.y << " l\n";
255   csAP << pt1.x << " " << pt1.y << " l\n";
256 
257   return csAP.GetByteString();
258 }
259 
GetAP_Square(const CPDF_Rect & crBBox)260 CFX_ByteString CPWL_Utils::GetAP_Square(const CPDF_Rect& crBBox) {
261   CFX_ByteTextBuf csAP;
262 
263   csAP << crBBox.left << " " << crBBox.top << " m\n";
264   csAP << crBBox.right << " " << crBBox.top << " l\n";
265   csAP << crBBox.right << " " << crBBox.bottom << " l\n";
266   csAP << crBBox.left << " " << crBBox.bottom << " l\n";
267   csAP << crBBox.left << " " << crBBox.top << " l\n";
268 
269   return csAP.GetByteString();
270 }
271 
GetAP_Star(const CPDF_Rect & crBBox)272 CFX_ByteString CPWL_Utils::GetAP_Star(const CPDF_Rect& crBBox) {
273   CFX_ByteTextBuf csAP;
274 
275   FX_FLOAT fRadius =
276       (crBBox.top - crBBox.bottom) / (1 + (FX_FLOAT)cos(PWL_PI / 5.0f));
277   CPDF_Point ptCenter = CPDF_Point((crBBox.left + crBBox.right) / 2.0f,
278                                    (crBBox.top + crBBox.bottom) / 2.0f);
279 
280   FX_FLOAT px[5], py[5];
281 
282   FX_FLOAT fAngel = PWL_PI / 10.0f;
283 
284   for (int32_t i = 0; i < 5; i++) {
285     px[i] = ptCenter.x + fRadius * (FX_FLOAT)cos(fAngel);
286     py[i] = ptCenter.y + fRadius * (FX_FLOAT)sin(fAngel);
287 
288     fAngel += PWL_PI * 2 / 5.0f;
289   }
290 
291   csAP << px[0] << " " << py[0] << " m\n";
292 
293   int32_t nNext = 0;
294   for (int32_t j = 0; j < 5; j++) {
295     nNext += 2;
296     if (nNext >= 5)
297       nNext -= 5;
298     csAP << px[nNext] << " " << py[nNext] << " l\n";
299   }
300 
301   return csAP.GetByteString();
302 }
303 
GetAP_HalfCircle(const CPDF_Rect & crBBox,FX_FLOAT fRotate)304 CFX_ByteString CPWL_Utils::GetAP_HalfCircle(const CPDF_Rect& crBBox,
305                                             FX_FLOAT fRotate) {
306   CFX_ByteTextBuf csAP;
307 
308   FX_FLOAT fWidth = crBBox.right - crBBox.left;
309   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
310 
311   CPDF_Point pt1(-fWidth / 2, 0);
312   CPDF_Point pt2(0, fHeight / 2);
313   CPDF_Point pt3(fWidth / 2, 0);
314 
315   FX_FLOAT px, py;
316 
317   csAP << cos(fRotate) << " " << sin(fRotate) << " " << -sin(fRotate) << " "
318        << cos(fRotate) << " " << crBBox.left + fWidth / 2 << " "
319        << crBBox.bottom + fHeight / 2 << " cm\n";
320 
321   csAP << pt1.x << " " << pt1.y << " m\n";
322 
323   px = pt2.x - pt1.x;
324   py = pt2.y - pt1.y;
325 
326   csAP << pt1.x << " " << pt1.y + py * PWL_BEZIER << " "
327        << pt2.x - px * PWL_BEZIER << " " << pt2.y << " " << pt2.x << " "
328        << pt2.y << " c\n";
329 
330   px = pt3.x - pt2.x;
331   py = pt2.y - pt3.y;
332 
333   csAP << pt2.x + px * PWL_BEZIER << " " << pt2.y << " " << pt3.x << " "
334        << pt3.y + py * PWL_BEZIER << " " << pt3.x << " " << pt3.y << " c\n";
335 
336   return csAP.GetByteString();
337 }
338 
InflateRect(const CPDF_Rect & rcRect,FX_FLOAT fSize)339 CPDF_Rect CPWL_Utils::InflateRect(const CPDF_Rect& rcRect, FX_FLOAT fSize) {
340   if (rcRect.IsEmpty())
341     return rcRect;
342 
343   CPDF_Rect rcNew(rcRect.left - fSize, rcRect.bottom - fSize,
344                   rcRect.right + fSize, rcRect.top + fSize);
345   rcNew.Normalize();
346   return rcNew;
347 }
348 
DeflateRect(const CPDF_Rect & rcRect,FX_FLOAT fSize)349 CPDF_Rect CPWL_Utils::DeflateRect(const CPDF_Rect& rcRect, FX_FLOAT fSize) {
350   if (rcRect.IsEmpty())
351     return rcRect;
352 
353   CPDF_Rect rcNew(rcRect.left + fSize, rcRect.bottom + fSize,
354                   rcRect.right - fSize, rcRect.top - fSize);
355   rcNew.Normalize();
356   return rcNew;
357 }
358 
ScaleRect(const CPDF_Rect & rcRect,FX_FLOAT fScale)359 CPDF_Rect CPWL_Utils::ScaleRect(const CPDF_Rect& rcRect, FX_FLOAT fScale) {
360   FX_FLOAT fHalfWidth = (rcRect.right - rcRect.left) / 2.0f;
361   FX_FLOAT fHalfHeight = (rcRect.top - rcRect.bottom) / 2.0f;
362 
363   CPDF_Point ptCenter = CPDF_Point((rcRect.left + rcRect.right) / 2,
364                                    (rcRect.top + rcRect.bottom) / 2);
365 
366   return CPDF_Rect(
367       ptCenter.x - fHalfWidth * fScale, ptCenter.y - fHalfHeight * fScale,
368       ptCenter.x + fHalfWidth * fScale, ptCenter.y + fHalfHeight * fScale);
369 }
370 
GetRectFillAppStream(const CPDF_Rect & rect,const CPWL_Color & color)371 CFX_ByteString CPWL_Utils::GetRectFillAppStream(const CPDF_Rect& rect,
372                                                 const CPWL_Color& color) {
373   CFX_ByteTextBuf sAppStream;
374 
375   CFX_ByteString sColor = GetColorAppStream(color, TRUE);
376   if (sColor.GetLength() > 0) {
377     sAppStream << "q\n" << sColor;
378     sAppStream << rect.left << " " << rect.bottom << " "
379                << rect.right - rect.left << " " << rect.top - rect.bottom
380                << " re f\nQ\n";
381   }
382 
383   return sAppStream.GetByteString();
384 }
385 
GetCircleFillAppStream(const CPDF_Rect & rect,const CPWL_Color & color)386 CFX_ByteString CPWL_Utils::GetCircleFillAppStream(const CPDF_Rect& rect,
387                                                   const CPWL_Color& color) {
388   CFX_ByteTextBuf sAppStream;
389 
390   CFX_ByteString sColor = GetColorAppStream(color, TRUE);
391   if (sColor.GetLength() > 0) {
392     sAppStream << "q\n" << sColor << CPWL_Utils::GetAP_Circle(rect) << "f\nQ\n";
393   }
394 
395   return sAppStream.GetByteString();
396 }
397 
GetCenterSquare(const CPDF_Rect & rect)398 CPDF_Rect CPWL_Utils::GetCenterSquare(const CPDF_Rect& rect) {
399   FX_FLOAT fWidth = rect.right - rect.left;
400   FX_FLOAT fHeight = rect.top - rect.bottom;
401 
402   FX_FLOAT fCenterX = (rect.left + rect.right) / 2.0f;
403   FX_FLOAT fCenterY = (rect.top + rect.bottom) / 2.0f;
404 
405   FX_FLOAT fRadius = (fWidth > fHeight) ? fHeight / 2 : fWidth / 2;
406 
407   return CPDF_Rect(fCenterX - fRadius, fCenterY - fRadius, fCenterX + fRadius,
408                    fCenterY + fRadius);
409 }
410 
GetEditAppStream(IFX_Edit * pEdit,const CPDF_Point & ptOffset,const CPVT_WordRange * pRange,FX_BOOL bContinuous,FX_WORD SubWord)411 CFX_ByteString CPWL_Utils::GetEditAppStream(IFX_Edit* pEdit,
412                                             const CPDF_Point& ptOffset,
413                                             const CPVT_WordRange* pRange,
414                                             FX_BOOL bContinuous,
415                                             FX_WORD SubWord) {
416   return IFX_Edit::GetEditAppearanceStream(pEdit, ptOffset, pRange, bContinuous,
417                                            SubWord);
418 }
419 
GetEditSelAppStream(IFX_Edit * pEdit,const CPDF_Point & ptOffset,const CPVT_WordRange * pRange)420 CFX_ByteString CPWL_Utils::GetEditSelAppStream(IFX_Edit* pEdit,
421                                                const CPDF_Point& ptOffset,
422                                                const CPVT_WordRange* pRange) {
423   return IFX_Edit::GetSelectAppearanceStream(pEdit, ptOffset, pRange);
424 }
425 
GetSquigglyAppearanceStream(FX_FLOAT fStartX,FX_FLOAT fEndX,FX_FLOAT fY,FX_FLOAT fStep)426 static CFX_ByteString GetSquigglyAppearanceStream(FX_FLOAT fStartX,
427                                                   FX_FLOAT fEndX,
428                                                   FX_FLOAT fY,
429                                                   FX_FLOAT fStep) {
430   CFX_ByteTextBuf sRet;
431 
432   sRet << "0 w\n" << fStartX << " " << fY << " m\n";
433 
434   FX_FLOAT fx;
435   int32_t i;
436 
437   for (i = 1, fx = fStartX + fStep; fx < fEndX; fx += fStep, i++) {
438     sRet << fx << " " << fY + (i & 1) * fStep << " l\n";
439   }
440 
441   sRet << "S\n";
442 
443   return sRet.GetByteString();
444 }
445 
GetWordSpellCheckAppearanceStream(IFX_Edit_Iterator * pIterator,const CPDF_Point & ptOffset,const CPVT_WordRange & wrWord)446 static CFX_ByteString GetWordSpellCheckAppearanceStream(
447     IFX_Edit_Iterator* pIterator,
448     const CPDF_Point& ptOffset,
449     const CPVT_WordRange& wrWord) {
450   CFX_ByteTextBuf sRet;
451 
452   FX_FLOAT fStartX = 0.0f;
453   FX_FLOAT fEndX = 0.0f;
454   FX_FLOAT fY = 0.0f;
455   FX_FLOAT fStep = 0.0f;
456 
457   FX_BOOL bBreak = FALSE;
458 
459   if (pIterator) {
460     pIterator->SetAt(wrWord.BeginPos);
461 
462     do {
463       CPVT_WordPlace place = pIterator->GetAt();
464 
465       CPVT_Line line;
466       if (pIterator->GetLine(line)) {
467         fY = line.ptLine.y;
468         fStep = (line.fLineAscent - line.fLineDescent) / 16.0f;
469       }
470 
471       if (place.LineCmp(wrWord.BeginPos) == 0) {
472         pIterator->SetAt(wrWord.BeginPos);
473         CPVT_Word word;
474         if (pIterator->GetWord(word)) {
475           fStartX = word.ptWord.x;
476         }
477       } else {
478         fStartX = line.ptLine.x;
479       }
480 
481       if (place.LineCmp(wrWord.EndPos) == 0) {
482         pIterator->SetAt(wrWord.EndPos);
483         CPVT_Word word;
484         if (pIterator->GetWord(word)) {
485           fEndX = word.ptWord.x + word.fWidth;
486         }
487 
488         bBreak = TRUE;
489       } else {
490         fEndX = line.ptLine.x + line.fLineWidth;
491       }
492 
493       sRet << GetSquigglyAppearanceStream(
494           fStartX + ptOffset.x, fEndX + ptOffset.x, fY + ptOffset.y, fStep);
495 
496       if (bBreak)
497         break;
498     } while (pIterator->NextLine());
499   }
500 
501   return sRet.GetByteString();
502 }
503 
GetSpellCheckAppStream(IFX_Edit * pEdit,IPWL_SpellCheck * pSpellCheck,const CPDF_Point & ptOffset,const CPVT_WordRange * pRange)504 CFX_ByteString CPWL_Utils::GetSpellCheckAppStream(
505     IFX_Edit* pEdit,
506     IPWL_SpellCheck* pSpellCheck,
507     const CPDF_Point& ptOffset,
508     const CPVT_WordRange* pRange) {
509   CFX_ByteTextBuf sRet;
510 
511   if (pRange && pRange->IsExist()) {
512     if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) {
513       pIterator->SetAt(pRange->BeginPos);
514 
515       FX_BOOL bLatinWord = FALSE;
516       CPVT_WordPlace wpWordStart;
517       CFX_ByteString sWord;
518 
519       CPVT_WordPlace oldplace;
520       while (pIterator->NextWord()) {
521         CPVT_WordPlace place = pIterator->GetAt();
522         if (pRange && place.WordCmp(pRange->EndPos) > 0)
523           break;
524 
525         CPVT_Word word;
526         if (pIterator->GetWord(word)) {
527           if (FX_EDIT_ISLATINWORD(word.Word)) {
528             if (!bLatinWord) {
529               wpWordStart = place;
530               bLatinWord = TRUE;
531             }
532 
533             sWord += (char)word.Word;
534             oldplace = place;
535           } else {
536             if (bLatinWord) {
537               if (!pSpellCheck->CheckWord(sWord)) {
538                 sRet << GetWordSpellCheckAppearanceStream(
539                     pIterator, ptOffset, CPVT_WordRange(wpWordStart, oldplace));
540                 pIterator->SetAt(place);
541               }
542               bLatinWord = FALSE;
543             }
544 
545             sWord.Empty();
546           }
547         } else {
548           if (bLatinWord) {
549             if (!pSpellCheck->CheckWord(sWord))
550               sRet << GetWordSpellCheckAppearanceStream(
551                   pIterator, ptOffset, CPVT_WordRange(wpWordStart, oldplace));
552             bLatinWord = FALSE;
553             sWord.Empty();
554           }
555         }
556       }
557 
558       if (bLatinWord) {
559         if (!pSpellCheck->CheckWord(sWord))
560           sRet << GetWordSpellCheckAppearanceStream(
561               pIterator, ptOffset, CPVT_WordRange(wpWordStart, oldplace));
562 
563         bLatinWord = FALSE;
564         sWord.Empty();
565       }
566     }
567   }
568 
569   return sRet.GetByteString();
570 }
571 
GetTextAppStream(const CPDF_Rect & rcBBox,IFX_Edit_FontMap * pFontMap,const CFX_WideString & sText,int32_t nAlignmentH,int32_t nAlignmentV,FX_FLOAT fFontSize,FX_BOOL bMultiLine,FX_BOOL bAutoReturn,const CPWL_Color & crText)572 CFX_ByteString CPWL_Utils::GetTextAppStream(const CPDF_Rect& rcBBox,
573                                             IFX_Edit_FontMap* pFontMap,
574                                             const CFX_WideString& sText,
575                                             int32_t nAlignmentH,
576                                             int32_t nAlignmentV,
577                                             FX_FLOAT fFontSize,
578                                             FX_BOOL bMultiLine,
579                                             FX_BOOL bAutoReturn,
580                                             const CPWL_Color& crText) {
581   CFX_ByteTextBuf sRet;
582 
583   if (IFX_Edit* pEdit = IFX_Edit::NewEdit()) {
584     pEdit->SetFontMap(pFontMap);
585     pEdit->SetPlateRect(rcBBox);
586     pEdit->SetAlignmentH(nAlignmentH);
587     pEdit->SetAlignmentV(nAlignmentV);
588     pEdit->SetMultiLine(bMultiLine);
589     pEdit->SetAutoReturn(bAutoReturn);
590     if (IsFloatZero(fFontSize))
591       pEdit->SetAutoFontSize(TRUE);
592     else
593       pEdit->SetFontSize(fFontSize);
594 
595     pEdit->Initialize();
596     pEdit->SetText(sText.c_str());
597 
598     CFX_ByteString sEdit =
599         CPWL_Utils::GetEditAppStream(pEdit, CPDF_Point(0.0f, 0.0f));
600     if (sEdit.GetLength() > 0) {
601       sRet << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit
602            << "ET\n";
603     }
604     IFX_Edit::DelEdit(pEdit);
605   }
606 
607   return sRet.GetByteString();
608 }
609 
GetPushButtonAppStream(const CPDF_Rect & rcBBox,IFX_Edit_FontMap * pFontMap,CPDF_Stream * pIconStream,CPDF_IconFit & IconFit,const CFX_WideString & sLabel,const CPWL_Color & crText,FX_FLOAT fFontSize,int32_t nLayOut)610 CFX_ByteString CPWL_Utils::GetPushButtonAppStream(const CPDF_Rect& rcBBox,
611                                                   IFX_Edit_FontMap* pFontMap,
612                                                   CPDF_Stream* pIconStream,
613                                                   CPDF_IconFit& IconFit,
614                                                   const CFX_WideString& sLabel,
615                                                   const CPWL_Color& crText,
616                                                   FX_FLOAT fFontSize,
617                                                   int32_t nLayOut) {
618   const FX_FLOAT fAutoFontScale = 1.0f / 3.0f;
619 
620   if (IFX_Edit* pEdit = IFX_Edit::NewEdit()) {
621     pEdit->SetFontMap(pFontMap);
622     pEdit->SetAlignmentH(1);
623     pEdit->SetAlignmentV(1);
624     pEdit->SetMultiLine(FALSE);
625     pEdit->SetAutoReturn(FALSE);
626     if (IsFloatZero(fFontSize))
627       pEdit->SetAutoFontSize(TRUE);
628     else
629       pEdit->SetFontSize(fFontSize);
630 
631     pEdit->Initialize();
632     pEdit->SetText(sLabel.c_str());
633 
634     CPDF_Rect rcLabelContent = pEdit->GetContentRect();
635     CPWL_Icon Icon;
636     PWL_CREATEPARAM cp;
637     cp.dwFlags = PWS_VISIBLE;
638     Icon.Create(cp);
639     Icon.SetIconFit(&IconFit);
640     Icon.SetPDFStream(pIconStream);
641 
642     CPDF_Rect rcLabel = CPDF_Rect(0, 0, 0, 0);
643     CPDF_Rect rcIcon = CPDF_Rect(0, 0, 0, 0);
644     FX_FLOAT fWidth = 0.0f;
645     FX_FLOAT fHeight = 0.0f;
646 
647     switch (nLayOut) {
648       case PPBL_LABEL:
649         rcLabel = rcBBox;
650         rcIcon = CPDF_Rect(0, 0, 0, 0);
651         break;
652       case PPBL_ICON:
653         rcIcon = rcBBox;
654         rcLabel = CPDF_Rect(0, 0, 0, 0);
655         break;
656       case PPBL_ICONTOPLABELBOTTOM:
657 
658         if (pIconStream) {
659           if (IsFloatZero(fFontSize)) {
660             fHeight = rcBBox.top - rcBBox.bottom;
661             rcLabel = CPDF_Rect(rcBBox.left, rcBBox.bottom, rcBBox.right,
662                                 rcBBox.bottom + fHeight * fAutoFontScale);
663             rcIcon =
664                 CPDF_Rect(rcBBox.left, rcLabel.top, rcBBox.right, rcBBox.top);
665           } else {
666             fHeight = rcLabelContent.Height();
667 
668             if (rcBBox.bottom + fHeight > rcBBox.top) {
669               rcIcon = CPDF_Rect(0, 0, 0, 0);
670               rcLabel = rcBBox;
671             } else {
672               rcLabel = CPDF_Rect(rcBBox.left, rcBBox.bottom, rcBBox.right,
673                                   rcBBox.bottom + fHeight);
674               rcIcon =
675                   CPDF_Rect(rcBBox.left, rcLabel.top, rcBBox.right, rcBBox.top);
676             }
677           }
678         } else {
679           rcLabel = rcBBox;
680           rcIcon = CPDF_Rect(0, 0, 0, 0);
681         }
682 
683         break;
684       case PPBL_LABELTOPICONBOTTOM:
685 
686         if (pIconStream) {
687           if (IsFloatZero(fFontSize)) {
688             fHeight = rcBBox.top - rcBBox.bottom;
689             rcLabel =
690                 CPDF_Rect(rcBBox.left, rcBBox.top - fHeight * fAutoFontScale,
691                           rcBBox.right, rcBBox.top);
692             rcIcon = CPDF_Rect(rcBBox.left, rcBBox.bottom, rcBBox.right,
693                                rcLabel.bottom);
694           } else {
695             fHeight = rcLabelContent.Height();
696 
697             if (rcBBox.bottom + fHeight > rcBBox.top) {
698               rcIcon = CPDF_Rect(0, 0, 0, 0);
699               rcLabel = rcBBox;
700             } else {
701               rcLabel = CPDF_Rect(rcBBox.left, rcBBox.top - fHeight,
702                                   rcBBox.right, rcBBox.top);
703               rcIcon = CPDF_Rect(rcBBox.left, rcBBox.bottom, rcBBox.right,
704                                  rcLabel.bottom);
705             }
706           }
707         } else {
708           rcLabel = rcBBox;
709           rcIcon = CPDF_Rect(0, 0, 0, 0);
710         }
711 
712         break;
713       case PPBL_ICONLEFTLABELRIGHT:
714 
715         if (pIconStream) {
716           if (IsFloatZero(fFontSize)) {
717             fWidth = rcBBox.right - rcBBox.left;
718             rcLabel = CPDF_Rect(rcBBox.right - fWidth * fAutoFontScale,
719                                 rcBBox.bottom, rcBBox.right, rcBBox.top);
720             rcIcon =
721                 CPDF_Rect(rcBBox.left, rcBBox.bottom, rcLabel.left, rcBBox.top);
722 
723             if (rcLabelContent.Width() < fWidth * fAutoFontScale) {
724             } else {
725               if (rcLabelContent.Width() < fWidth) {
726                 rcLabel = CPDF_Rect(rcBBox.right - rcLabelContent.Width(),
727                                     rcBBox.bottom, rcBBox.right, rcBBox.top);
728                 rcIcon = CPDF_Rect(rcBBox.left, rcBBox.bottom, rcLabel.left,
729                                    rcBBox.top);
730               } else {
731                 rcLabel = rcBBox;
732                 rcIcon = CPDF_Rect(0, 0, 0, 0);
733               }
734             }
735           } else {
736             fWidth = rcLabelContent.Width();
737 
738             if (rcBBox.left + fWidth > rcBBox.right) {
739               rcLabel = rcBBox;
740               rcIcon = CPDF_Rect(0, 0, 0, 0);
741             } else {
742               rcLabel = CPDF_Rect(rcBBox.right - fWidth, rcBBox.bottom,
743                                   rcBBox.right, rcBBox.top);
744               rcIcon = CPDF_Rect(rcBBox.left, rcBBox.bottom, rcLabel.left,
745                                  rcBBox.top);
746             }
747           }
748         } else {
749           rcLabel = rcBBox;
750           rcIcon = CPDF_Rect(0, 0, 0, 0);
751         }
752 
753         break;
754       case PPBL_LABELLEFTICONRIGHT:
755 
756         if (pIconStream) {
757           if (IsFloatZero(fFontSize)) {
758             fWidth = rcBBox.right - rcBBox.left;
759             rcLabel =
760                 CPDF_Rect(rcBBox.left, rcBBox.bottom,
761                           rcBBox.left + fWidth * fAutoFontScale, rcBBox.top);
762             rcIcon = CPDF_Rect(rcLabel.right, rcBBox.bottom, rcBBox.right,
763                                rcBBox.top);
764 
765             if (rcLabelContent.Width() < fWidth * fAutoFontScale) {
766             } else {
767               if (rcLabelContent.Width() < fWidth) {
768                 rcLabel =
769                     CPDF_Rect(rcBBox.left, rcBBox.bottom,
770                               rcBBox.left + rcLabelContent.Width(), rcBBox.top);
771                 rcIcon = CPDF_Rect(rcLabel.right, rcBBox.bottom, rcBBox.right,
772                                    rcBBox.top);
773               } else {
774                 rcLabel = rcBBox;
775                 rcIcon = CPDF_Rect(0, 0, 0, 0);
776               }
777             }
778           } else {
779             fWidth = rcLabelContent.Width();
780 
781             if (rcBBox.left + fWidth > rcBBox.right) {
782               rcLabel = rcBBox;
783               rcIcon = CPDF_Rect(0, 0, 0, 0);
784             } else {
785               rcLabel = CPDF_Rect(rcBBox.left, rcBBox.bottom,
786                                   rcBBox.left + fWidth, rcBBox.top);
787               rcIcon = CPDF_Rect(rcLabel.right, rcBBox.bottom, rcBBox.right,
788                                  rcBBox.top);
789             }
790           }
791         } else {
792           rcLabel = rcBBox;
793           rcIcon = CPDF_Rect(0, 0, 0, 0);
794         }
795 
796         break;
797       case PPBL_LABELOVERICON:
798         rcLabel = rcBBox;
799         rcIcon = rcBBox;
800         break;
801     }
802 
803     CFX_ByteTextBuf sAppStream, sTemp;
804 
805     if (!rcIcon.IsEmpty()) {
806       Icon.Move(rcIcon, FALSE, FALSE);
807       sTemp << Icon.GetImageAppStream();
808     }
809 
810     Icon.Destroy();
811 
812     if (!rcLabel.IsEmpty()) {
813       pEdit->SetPlateRect(rcLabel);
814       CFX_ByteString sEdit =
815           CPWL_Utils::GetEditAppStream(pEdit, CPDF_Point(0.0f, 0.0f));
816       if (sEdit.GetLength() > 0) {
817         sTemp << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit
818               << "ET\n";
819       }
820     }
821 
822     IFX_Edit::DelEdit(pEdit);
823 
824     if (sTemp.GetSize() > 0) {
825       sAppStream << "q\n" << rcBBox.left << " " << rcBBox.bottom << " "
826                  << rcBBox.right - rcBBox.left << " "
827                  << rcBBox.top - rcBBox.bottom << " re W n\n";
828       sAppStream << sTemp << "Q\n";
829     }
830 
831     return sAppStream.GetByteString();
832   }
833 
834   return "";
835 }
836 
GetColorAppStream(const CPWL_Color & color,const FX_BOOL & bFillOrStroke)837 CFX_ByteString CPWL_Utils::GetColorAppStream(const CPWL_Color& color,
838                                              const FX_BOOL& bFillOrStroke) {
839   CFX_ByteTextBuf sColorStream;
840 
841   switch (color.nColorType) {
842     case COLORTYPE_RGB:
843       sColorStream << color.fColor1 << " " << color.fColor2 << " "
844                    << color.fColor3 << " " << (bFillOrStroke ? "rg" : "RG")
845                    << "\n";
846       break;
847     case COLORTYPE_GRAY:
848       sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G")
849                    << "\n";
850       break;
851     case COLORTYPE_CMYK:
852       sColorStream << color.fColor1 << " " << color.fColor2 << " "
853                    << color.fColor3 << " " << color.fColor4 << " "
854                    << (bFillOrStroke ? "k" : "K") << "\n";
855       break;
856   }
857 
858   return sColorStream.GetByteString();
859 }
860 
GetBorderAppStream(const CPDF_Rect & rect,FX_FLOAT fWidth,const CPWL_Color & color,const CPWL_Color & crLeftTop,const CPWL_Color & crRightBottom,int32_t nStyle,const CPWL_Dash & dash)861 CFX_ByteString CPWL_Utils::GetBorderAppStream(const CPDF_Rect& rect,
862                                               FX_FLOAT fWidth,
863                                               const CPWL_Color& color,
864                                               const CPWL_Color& crLeftTop,
865                                               const CPWL_Color& crRightBottom,
866                                               int32_t nStyle,
867                                               const CPWL_Dash& dash) {
868   CFX_ByteTextBuf sAppStream;
869   CFX_ByteString sColor;
870 
871   FX_FLOAT fLeft = rect.left;
872   FX_FLOAT fRight = rect.right;
873   FX_FLOAT fTop = rect.top;
874   FX_FLOAT fBottom = rect.bottom;
875 
876   if (fWidth > 0.0f) {
877     FX_FLOAT fHalfWidth = fWidth / 2.0f;
878 
879     sAppStream << "q\n";
880 
881     switch (nStyle) {
882       default:
883       case PBS_SOLID:
884         sColor = CPWL_Utils::GetColorAppStream(color, TRUE);
885         if (sColor.GetLength() > 0) {
886           sAppStream << sColor;
887           sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " "
888                      << fTop - fBottom << " re\n";
889           sAppStream << fLeft + fWidth << " " << fBottom + fWidth << " "
890                      << fRight - fLeft - fWidth * 2 << " "
891                      << fTop - fBottom - fWidth * 2 << " re\n";
892           sAppStream << "f*\n";
893         }
894         break;
895       case PBS_DASH:
896         sColor = CPWL_Utils::GetColorAppStream(color, FALSE);
897         if (sColor.GetLength() > 0) {
898           sAppStream << sColor;
899           sAppStream << fWidth << " w"
900                      << " [" << dash.nDash << " " << dash.nGap << "] "
901                      << dash.nPhase << " d\n";
902           sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2
903                      << " m\n";
904           sAppStream << fLeft + fWidth / 2 << " " << fTop - fWidth / 2
905                      << " l\n";
906           sAppStream << fRight - fWidth / 2 << " " << fTop - fWidth / 2
907                      << " l\n";
908           sAppStream << fRight - fWidth / 2 << " " << fBottom + fWidth / 2
909                      << " l\n";
910           sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2
911                      << " l S\n";
912         }
913         break;
914       case PBS_BEVELED:
915       case PBS_INSET:
916         sColor = CPWL_Utils::GetColorAppStream(crLeftTop, TRUE);
917         if (sColor.GetLength() > 0) {
918           sAppStream << sColor;
919           sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth
920                      << " m\n";
921           sAppStream << fLeft + fHalfWidth << " " << fTop - fHalfWidth
922                      << " l\n";
923           sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidth
924                      << " l\n";
925           sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalfWidth * 2
926                      << " l\n";
927           sAppStream << fLeft + fHalfWidth * 2 << " " << fTop - fHalfWidth * 2
928                      << " l\n";
929           sAppStream << fLeft + fHalfWidth * 2 << " "
930                      << fBottom + fHalfWidth * 2 << " l f\n";
931         }
932 
933         sColor = CPWL_Utils::GetColorAppStream(crRightBottom, TRUE);
934         if (sColor.GetLength() > 0) {
935           sAppStream << sColor;
936           sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidth
937                      << " m\n";
938           sAppStream << fRight - fHalfWidth << " " << fBottom + fHalfWidth
939                      << " l\n";
940           sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth
941                      << " l\n";
942           sAppStream << fLeft + fHalfWidth * 2 << " "
943                      << fBottom + fHalfWidth * 2 << " l\n";
944           sAppStream << fRight - fHalfWidth * 2 << " "
945                      << fBottom + fHalfWidth * 2 << " l\n";
946           sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalfWidth * 2
947                      << " l f\n";
948         }
949 
950         sColor = CPWL_Utils::GetColorAppStream(color, TRUE);
951         if (sColor.GetLength() > 0) {
952           sAppStream << sColor;
953           sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " "
954                      << fTop - fBottom << " re\n";
955           sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth << " "
956                      << fRight - fLeft - fHalfWidth * 2 << " "
957                      << fTop - fBottom - fHalfWidth * 2 << " re f*\n";
958         }
959         break;
960       case PBS_UNDERLINED:
961         sColor = CPWL_Utils::GetColorAppStream(color, FALSE);
962         if (sColor.GetLength() > 0) {
963           sAppStream << sColor;
964           sAppStream << fWidth << " w\n";
965           sAppStream << fLeft << " " << fBottom + fWidth / 2 << " m\n";
966           sAppStream << fRight << " " << fBottom + fWidth / 2 << " l S\n";
967         }
968         break;
969     }
970 
971     sAppStream << "Q\n";
972   }
973 
974   return sAppStream.GetByteString();
975 }
976 
GetCircleBorderAppStream(const CPDF_Rect & rect,FX_FLOAT fWidth,const CPWL_Color & color,const CPWL_Color & crLeftTop,const CPWL_Color & crRightBottom,int32_t nStyle,const CPWL_Dash & dash)977 CFX_ByteString CPWL_Utils::GetCircleBorderAppStream(
978     const CPDF_Rect& rect,
979     FX_FLOAT fWidth,
980     const CPWL_Color& color,
981     const CPWL_Color& crLeftTop,
982     const CPWL_Color& crRightBottom,
983     int32_t nStyle,
984     const CPWL_Dash& dash) {
985   CFX_ByteTextBuf sAppStream;
986   CFX_ByteString sColor;
987 
988   if (fWidth > 0.0f) {
989     sAppStream << "q\n";
990 
991     switch (nStyle) {
992       default:
993       case PBS_SOLID:
994       case PBS_UNDERLINED: {
995         sColor = CPWL_Utils::GetColorAppStream(color, FALSE);
996         if (sColor.GetLength() > 0) {
997           sAppStream << "q\n" << fWidth << " w\n" << sColor
998                      << CPWL_Utils::GetAP_Circle(
999                             CPWL_Utils::DeflateRect(rect, fWidth / 2.0f))
1000                      << " S\nQ\n";
1001         }
1002       } break;
1003       case PBS_DASH: {
1004         sColor = CPWL_Utils::GetColorAppStream(color, FALSE);
1005         if (sColor.GetLength() > 0) {
1006           sAppStream << "q\n" << fWidth << " w\n"
1007                      << "[" << dash.nDash << " " << dash.nGap << "] "
1008                      << dash.nPhase << " d\n" << sColor
1009                      << CPWL_Utils::GetAP_Circle(
1010                             CPWL_Utils::DeflateRect(rect, fWidth / 2.0f))
1011                      << " S\nQ\n";
1012         }
1013       } break;
1014       case PBS_BEVELED: {
1015         FX_FLOAT fHalfWidth = fWidth / 2.0f;
1016 
1017         sColor = CPWL_Utils::GetColorAppStream(color, FALSE);
1018         if (sColor.GetLength() > 0) {
1019           sAppStream << "q\n" << fHalfWidth << " w\n" << sColor
1020                      << CPWL_Utils::GetAP_Circle(rect) << " S\nQ\n";
1021         }
1022 
1023         sColor = CPWL_Utils::GetColorAppStream(crLeftTop, FALSE);
1024         if (sColor.GetLength() > 0) {
1025           sAppStream << "q\n" << fHalfWidth << " w\n" << sColor
1026                      << CPWL_Utils::GetAP_HalfCircle(
1027                             CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f),
1028                             PWL_PI / 4.0f)
1029                      << " S\nQ\n";
1030         }
1031 
1032         sColor = CPWL_Utils::GetColorAppStream(crRightBottom, FALSE);
1033         if (sColor.GetLength() > 0) {
1034           sAppStream << "q\n" << fHalfWidth << " w\n" << sColor
1035                      << CPWL_Utils::GetAP_HalfCircle(
1036                             CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f),
1037                             PWL_PI * 5 / 4.0f)
1038                      << " S\nQ\n";
1039         }
1040       } break;
1041       case PBS_INSET: {
1042         FX_FLOAT fHalfWidth = fWidth / 2.0f;
1043 
1044         sColor = CPWL_Utils::GetColorAppStream(color, FALSE);
1045         if (sColor.GetLength() > 0) {
1046           sAppStream << "q\n" << fHalfWidth << " w\n" << sColor
1047                      << CPWL_Utils::GetAP_Circle(rect) << " S\nQ\n";
1048         }
1049 
1050         sColor = CPWL_Utils::GetColorAppStream(crLeftTop, FALSE);
1051         if (sColor.GetLength() > 0) {
1052           sAppStream << "q\n" << fHalfWidth << " w\n" << sColor
1053                      << CPWL_Utils::GetAP_HalfCircle(
1054                             CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f),
1055                             PWL_PI / 4.0f)
1056                      << " S\nQ\n";
1057         }
1058 
1059         sColor = CPWL_Utils::GetColorAppStream(crRightBottom, FALSE);
1060         if (sColor.GetLength() > 0) {
1061           sAppStream << "q\n" << fHalfWidth << " w\n" << sColor
1062                      << CPWL_Utils::GetAP_HalfCircle(
1063                             CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f),
1064                             PWL_PI * 5 / 4.0f)
1065                      << " S\nQ\n";
1066         }
1067       } break;
1068     }
1069 
1070     sAppStream << "Q\n";
1071   }
1072 
1073   return sAppStream.GetByteString();
1074 }
1075 
SubstractColor(const CPWL_Color & sColor,FX_FLOAT fColorSub)1076 CPWL_Color CPWL_Utils::SubstractColor(const CPWL_Color& sColor,
1077                                       FX_FLOAT fColorSub) {
1078   CPWL_Color sRet;
1079   sRet.nColorType = sColor.nColorType;
1080 
1081   switch (sColor.nColorType) {
1082     case COLORTYPE_TRANSPARENT:
1083       sRet.nColorType = COLORTYPE_RGB;
1084       sRet.fColor1 = PWL_MAX(1 - fColorSub, 0.0f);
1085       sRet.fColor2 = PWL_MAX(1 - fColorSub, 0.0f);
1086       sRet.fColor3 = PWL_MAX(1 - fColorSub, 0.0f);
1087       break;
1088     case COLORTYPE_RGB:
1089     case COLORTYPE_GRAY:
1090     case COLORTYPE_CMYK:
1091       sRet.fColor1 = PWL_MAX(sColor.fColor1 - fColorSub, 0.0f);
1092       sRet.fColor2 = PWL_MAX(sColor.fColor2 - fColorSub, 0.0f);
1093       sRet.fColor3 = PWL_MAX(sColor.fColor3 - fColorSub, 0.0f);
1094       sRet.fColor4 = PWL_MAX(sColor.fColor4 - fColorSub, 0.0f);
1095       break;
1096   }
1097 
1098   return sRet;
1099 }
1100 
DevideColor(const CPWL_Color & sColor,FX_FLOAT fColorDevide)1101 CPWL_Color CPWL_Utils::DevideColor(const CPWL_Color& sColor,
1102                                    FX_FLOAT fColorDevide) {
1103   CPWL_Color sRet;
1104   sRet.nColorType = sColor.nColorType;
1105 
1106   switch (sColor.nColorType) {
1107     case COLORTYPE_TRANSPARENT:
1108       sRet.nColorType = COLORTYPE_RGB;
1109       sRet.fColor1 = 1 / fColorDevide;
1110       sRet.fColor2 = 1 / fColorDevide;
1111       sRet.fColor3 = 1 / fColorDevide;
1112       break;
1113     case COLORTYPE_RGB:
1114     case COLORTYPE_GRAY:
1115     case COLORTYPE_CMYK:
1116       sRet = sColor;
1117       sRet.fColor1 /= fColorDevide;
1118       sRet.fColor2 /= fColorDevide;
1119       sRet.fColor3 /= fColorDevide;
1120       sRet.fColor4 /= fColorDevide;
1121       break;
1122   }
1123 
1124   return sRet;
1125 }
1126 
GetAppStream_Check(const CPDF_Rect & rcBBox,const CPWL_Color & crText)1127 CFX_ByteString CPWL_Utils::GetAppStream_Check(const CPDF_Rect& rcBBox,
1128                                               const CPWL_Color& crText) {
1129   CFX_ByteTextBuf sAP;
1130   sAP << "q\n" << CPWL_Utils::GetColorAppStream(crText, TRUE)
1131       << CPWL_Utils::GetAP_Check(rcBBox) << "f\nQ\n";
1132   return sAP.GetByteString();
1133 }
1134 
GetAppStream_Circle(const CPDF_Rect & rcBBox,const CPWL_Color & crText)1135 CFX_ByteString CPWL_Utils::GetAppStream_Circle(const CPDF_Rect& rcBBox,
1136                                                const CPWL_Color& crText) {
1137   CFX_ByteTextBuf sAP;
1138   sAP << "q\n" << CPWL_Utils::GetColorAppStream(crText, TRUE)
1139       << CPWL_Utils::GetAP_Circle(rcBBox) << "f\nQ\n";
1140   return sAP.GetByteString();
1141 }
1142 
GetAppStream_Cross(const CPDF_Rect & rcBBox,const CPWL_Color & crText)1143 CFX_ByteString CPWL_Utils::GetAppStream_Cross(const CPDF_Rect& rcBBox,
1144                                               const CPWL_Color& crText) {
1145   CFX_ByteTextBuf sAP;
1146   sAP << "q\n" << CPWL_Utils::GetColorAppStream(crText, FALSE)
1147       << CPWL_Utils::GetAP_Cross(rcBBox) << "S\nQ\n";
1148   return sAP.GetByteString();
1149 }
1150 
GetAppStream_Diamond(const CPDF_Rect & rcBBox,const CPWL_Color & crText)1151 CFX_ByteString CPWL_Utils::GetAppStream_Diamond(const CPDF_Rect& rcBBox,
1152                                                 const CPWL_Color& crText) {
1153   CFX_ByteTextBuf sAP;
1154   sAP << "q\n1 w\n" << CPWL_Utils::GetColorAppStream(crText, TRUE)
1155       << CPWL_Utils::GetAP_Diamond(rcBBox) << "f\nQ\n";
1156   return sAP.GetByteString();
1157 }
1158 
GetAppStream_Square(const CPDF_Rect & rcBBox,const CPWL_Color & crText)1159 CFX_ByteString CPWL_Utils::GetAppStream_Square(const CPDF_Rect& rcBBox,
1160                                                const CPWL_Color& crText) {
1161   CFX_ByteTextBuf sAP;
1162   sAP << "q\n" << CPWL_Utils::GetColorAppStream(crText, TRUE)
1163       << CPWL_Utils::GetAP_Square(rcBBox) << "f\nQ\n";
1164   return sAP.GetByteString();
1165 }
1166 
GetAppStream_Star(const CPDF_Rect & rcBBox,const CPWL_Color & crText)1167 CFX_ByteString CPWL_Utils::GetAppStream_Star(const CPDF_Rect& rcBBox,
1168                                              const CPWL_Color& crText) {
1169   CFX_ByteTextBuf sAP;
1170   sAP << "q\n" << CPWL_Utils::GetColorAppStream(crText, TRUE)
1171       << CPWL_Utils::GetAP_Star(rcBBox) << "f\nQ\n";
1172   return sAP.GetByteString();
1173 }
1174 
GetCheckBoxAppStream(const CPDF_Rect & rcBBox,int32_t nStyle,const CPWL_Color & crText)1175 CFX_ByteString CPWL_Utils::GetCheckBoxAppStream(const CPDF_Rect& rcBBox,
1176                                                 int32_t nStyle,
1177                                                 const CPWL_Color& crText) {
1178   CPDF_Rect rcCenter = GetCenterSquare(rcBBox);
1179   switch (nStyle) {
1180     default:
1181     case PCS_CHECK:
1182       return GetAppStream_Check(rcCenter, crText);
1183     case PCS_CIRCLE:
1184       return GetAppStream_Circle(ScaleRect(rcCenter, 2.0f / 3.0f), crText);
1185     case PCS_CROSS:
1186       return GetAppStream_Cross(rcCenter, crText);
1187     case PCS_DIAMOND:
1188       return GetAppStream_Diamond(ScaleRect(rcCenter, 2.0f / 3.0f), crText);
1189     case PCS_SQUARE:
1190       return GetAppStream_Square(ScaleRect(rcCenter, 2.0f / 3.0f), crText);
1191     case PCS_STAR:
1192       return GetAppStream_Star(ScaleRect(rcCenter, 2.0f / 3.0f), crText);
1193   }
1194 }
1195 
GetRadioButtonAppStream(const CPDF_Rect & rcBBox,int32_t nStyle,const CPWL_Color & crText)1196 CFX_ByteString CPWL_Utils::GetRadioButtonAppStream(const CPDF_Rect& rcBBox,
1197                                                    int32_t nStyle,
1198                                                    const CPWL_Color& crText) {
1199   CPDF_Rect rcCenter = GetCenterSquare(rcBBox);
1200   switch (nStyle) {
1201     default:
1202     case PCS_CHECK:
1203       return GetAppStream_Check(rcCenter, crText);
1204     case PCS_CIRCLE:
1205       return GetAppStream_Circle(ScaleRect(rcCenter, 1.0f / 2.0f), crText);
1206     case PCS_CROSS:
1207       return GetAppStream_Cross(rcCenter, crText);
1208     case PCS_DIAMOND:
1209       return GetAppStream_Diamond(ScaleRect(rcCenter, 2.0f / 3.0f), crText);
1210     case PCS_SQUARE:
1211       return GetAppStream_Square(ScaleRect(rcCenter, 2.0f / 3.0f), crText);
1212     case PCS_STAR:
1213       return GetAppStream_Star(ScaleRect(rcCenter, 2.0f / 3.0f), crText);
1214   }
1215 }
1216 
GetDropButtonAppStream(const CPDF_Rect & rcBBox)1217 CFX_ByteString CPWL_Utils::GetDropButtonAppStream(const CPDF_Rect& rcBBox) {
1218   CFX_ByteTextBuf sAppStream;
1219 
1220   if (!rcBBox.IsEmpty()) {
1221     sAppStream << "q\n" << CPWL_Utils::GetColorAppStream(
1222                                CPWL_Color(COLORTYPE_RGB, 220.0f / 255.0f,
1223                                           220.0f / 255.0f, 220.0f / 255.0f),
1224                                TRUE);
1225     sAppStream << rcBBox.left << " " << rcBBox.bottom << " "
1226                << rcBBox.right - rcBBox.left << " "
1227                << rcBBox.top - rcBBox.bottom << " re f\n";
1228     sAppStream << "Q\n";
1229 
1230     sAppStream << "q\n" << CPWL_Utils::GetBorderAppStream(
1231                                rcBBox, 2, CPWL_Color(COLORTYPE_GRAY, 0),
1232                                CPWL_Color(COLORTYPE_GRAY, 1),
1233                                CPWL_Color(COLORTYPE_GRAY, 0.5), PBS_BEVELED,
1234                                CPWL_Dash(3, 0, 0))
1235                << "Q\n";
1236 
1237     CPDF_Point ptCenter = CPDF_Point((rcBBox.left + rcBBox.right) / 2,
1238                                      (rcBBox.top + rcBBox.bottom) / 2);
1239     if (IsFloatBigger(rcBBox.right - rcBBox.left, 6) &&
1240         IsFloatBigger(rcBBox.top - rcBBox.bottom, 6)) {
1241       sAppStream << "q\n"
1242                  << " 0 g\n";
1243       sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n";
1244       sAppStream << ptCenter.x + 3 << " " << ptCenter.y + 1.5f << " l\n";
1245       sAppStream << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n";
1246       sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n";
1247       sAppStream << "Q\n";
1248     }
1249   }
1250 
1251   return sAppStream.GetByteString();
1252 }
1253 
ConvertCMYK2GRAY(FX_FLOAT dC,FX_FLOAT dM,FX_FLOAT dY,FX_FLOAT dK,FX_FLOAT & dGray)1254 void CPWL_Utils::ConvertCMYK2GRAY(FX_FLOAT dC,
1255                                   FX_FLOAT dM,
1256                                   FX_FLOAT dY,
1257                                   FX_FLOAT dK,
1258                                   FX_FLOAT& dGray) {
1259   if (dC < 0 || dC > 1 || dM < 0 || dM > 1 || dY < 0 || dY > 1 || dK < 0 ||
1260       dK > 1)
1261     return;
1262   dGray = 1.0f - std::min(1.0f, 0.3f * dC + 0.59f * dM + 0.11f * dY + dK);
1263 }
1264 
ConvertGRAY2CMYK(FX_FLOAT dGray,FX_FLOAT & dC,FX_FLOAT & dM,FX_FLOAT & dY,FX_FLOAT & dK)1265 void CPWL_Utils::ConvertGRAY2CMYK(FX_FLOAT dGray,
1266                                   FX_FLOAT& dC,
1267                                   FX_FLOAT& dM,
1268                                   FX_FLOAT& dY,
1269                                   FX_FLOAT& dK) {
1270   if (dGray < 0 || dGray > 1)
1271     return;
1272   dC = 0.0f;
1273   dM = 0.0f;
1274   dY = 0.0f;
1275   dK = 1.0f - dGray;
1276 }
1277 
ConvertGRAY2RGB(FX_FLOAT dGray,FX_FLOAT & dR,FX_FLOAT & dG,FX_FLOAT & dB)1278 void CPWL_Utils::ConvertGRAY2RGB(FX_FLOAT dGray,
1279                                  FX_FLOAT& dR,
1280                                  FX_FLOAT& dG,
1281                                  FX_FLOAT& dB) {
1282   if (dGray < 0 || dGray > 1)
1283     return;
1284   dR = dGray;
1285   dG = dGray;
1286   dB = dGray;
1287 }
1288 
ConvertRGB2GRAY(FX_FLOAT dR,FX_FLOAT dG,FX_FLOAT dB,FX_FLOAT & dGray)1289 void CPWL_Utils::ConvertRGB2GRAY(FX_FLOAT dR,
1290                                  FX_FLOAT dG,
1291                                  FX_FLOAT dB,
1292                                  FX_FLOAT& dGray) {
1293   if (dR < 0 || dR > 1 || dG < 0 || dG > 0 || dB < 0 || dB > 1)
1294     return;
1295   dGray = 0.3f * dR + 0.59f * dG + 0.11f * dB;
1296 }
1297 
ConvertCMYK2RGB(FX_FLOAT dC,FX_FLOAT dM,FX_FLOAT dY,FX_FLOAT dK,FX_FLOAT & dR,FX_FLOAT & dG,FX_FLOAT & dB)1298 void CPWL_Utils::ConvertCMYK2RGB(FX_FLOAT dC,
1299                                  FX_FLOAT dM,
1300                                  FX_FLOAT dY,
1301                                  FX_FLOAT dK,
1302                                  FX_FLOAT& dR,
1303                                  FX_FLOAT& dG,
1304                                  FX_FLOAT& dB) {
1305   if (dC < 0 || dC > 1 || dM < 0 || dM > 1 || dY < 0 || dY > 1 || dK < 0 ||
1306       dK > 1)
1307     return;
1308   dR = 1.0f - std::min(1.0f, dC + dK);
1309   dG = 1.0f - std::min(1.0f, dM + dK);
1310   dB = 1.0f - std::min(1.0f, dY + dK);
1311 }
1312 
ConvertRGB2CMYK(FX_FLOAT dR,FX_FLOAT dG,FX_FLOAT dB,FX_FLOAT & dC,FX_FLOAT & dM,FX_FLOAT & dY,FX_FLOAT & dK)1313 void CPWL_Utils::ConvertRGB2CMYK(FX_FLOAT dR,
1314                                  FX_FLOAT dG,
1315                                  FX_FLOAT dB,
1316                                  FX_FLOAT& dC,
1317                                  FX_FLOAT& dM,
1318                                  FX_FLOAT& dY,
1319                                  FX_FLOAT& dK) {
1320   if (dR < 0 || dR > 1 || dG < 0 || dG > 1 || dB < 0 || dB > 1)
1321     return;
1322 
1323   dC = 1.0f - dR;
1324   dM = 1.0f - dG;
1325   dY = 1.0f - dB;
1326   dK = std::min(dC, std::min(dM, dY));
1327 }
1328 
PWLColorToARGB(const CPWL_Color & color,int32_t & alpha,FX_FLOAT & red,FX_FLOAT & green,FX_FLOAT & blue)1329 void CPWL_Utils::PWLColorToARGB(const CPWL_Color& color,
1330                                 int32_t& alpha,
1331                                 FX_FLOAT& red,
1332                                 FX_FLOAT& green,
1333                                 FX_FLOAT& blue) {
1334   switch (color.nColorType) {
1335     case COLORTYPE_TRANSPARENT: {
1336       alpha = 0;
1337     } break;
1338     case COLORTYPE_GRAY: {
1339       ConvertGRAY2RGB(color.fColor1, red, green, blue);
1340     } break;
1341     case COLORTYPE_RGB: {
1342       red = color.fColor1;
1343       green = color.fColor2;
1344       blue = color.fColor3;
1345     } break;
1346     case COLORTYPE_CMYK: {
1347       ConvertCMYK2RGB(color.fColor1, color.fColor2, color.fColor3,
1348                       color.fColor4, red, green, blue);
1349     } break;
1350   }
1351 }
1352 
PWLColorToFXColor(const CPWL_Color & color,int32_t nTransparancy)1353 FX_COLORREF CPWL_Utils::PWLColorToFXColor(const CPWL_Color& color,
1354                                           int32_t nTransparancy) {
1355   int32_t nAlpha = nTransparancy;
1356   FX_FLOAT dRed = 0;
1357   FX_FLOAT dGreen = 0;
1358   FX_FLOAT dBlue = 0;
1359 
1360   PWLColorToARGB(color, nAlpha, dRed, dGreen, dBlue);
1361 
1362   return ArgbEncode(nAlpha, (int32_t)(dRed * 255), (int32_t)(dGreen * 255),
1363                     (int32_t)(dBlue * 255));
1364 }
1365 
DrawFillRect(CFX_RenderDevice * pDevice,CFX_Matrix * pUser2Device,const CPDF_Rect & rect,const FX_COLORREF & color)1366 void CPWL_Utils::DrawFillRect(CFX_RenderDevice* pDevice,
1367                               CFX_Matrix* pUser2Device,
1368                               const CPDF_Rect& rect,
1369                               const FX_COLORREF& color) {
1370   CFX_PathData path;
1371   CPDF_Rect rcTemp(rect);
1372   path.AppendRect(rcTemp.left, rcTemp.bottom, rcTemp.right, rcTemp.top);
1373   pDevice->DrawPath(&path, pUser2Device, NULL, color, 0, FXFILL_WINDING);
1374 }
1375 
DrawFillArea(CFX_RenderDevice * pDevice,CFX_Matrix * pUser2Device,const CPDF_Point * pPts,int32_t nCount,const FX_COLORREF & color)1376 void CPWL_Utils::DrawFillArea(CFX_RenderDevice* pDevice,
1377                               CFX_Matrix* pUser2Device,
1378                               const CPDF_Point* pPts,
1379                               int32_t nCount,
1380                               const FX_COLORREF& color) {
1381   CFX_PathData path;
1382   path.SetPointCount(nCount);
1383 
1384   path.SetPoint(0, pPts[0].x, pPts[0].y, FXPT_MOVETO);
1385   for (int32_t i = 1; i < nCount; i++)
1386     path.SetPoint(i, pPts[i].x, pPts[i].y, FXPT_LINETO);
1387 
1388   pDevice->DrawPath(&path, pUser2Device, NULL, color, 0, FXFILL_ALTERNATE);
1389 }
1390 
DrawStrokeRect(CFX_RenderDevice * pDevice,CFX_Matrix * pUser2Device,const CPDF_Rect & rect,const FX_COLORREF & color,FX_FLOAT fWidth)1391 void CPWL_Utils::DrawStrokeRect(CFX_RenderDevice* pDevice,
1392                                 CFX_Matrix* pUser2Device,
1393                                 const CPDF_Rect& rect,
1394                                 const FX_COLORREF& color,
1395                                 FX_FLOAT fWidth) {
1396   CFX_PathData path;
1397   CPDF_Rect rcTemp(rect);
1398   path.AppendRect(rcTemp.left, rcTemp.bottom, rcTemp.right, rcTemp.top);
1399 
1400   CFX_GraphStateData gsd;
1401   gsd.m_LineWidth = fWidth;
1402 
1403   pDevice->DrawPath(&path, pUser2Device, &gsd, 0, color, FXFILL_ALTERNATE);
1404 }
1405 
DrawStrokeLine(CFX_RenderDevice * pDevice,CFX_Matrix * pUser2Device,const CPDF_Point & ptMoveTo,const CPDF_Point & ptLineTo,const FX_COLORREF & color,FX_FLOAT fWidth)1406 void CPWL_Utils::DrawStrokeLine(CFX_RenderDevice* pDevice,
1407                                 CFX_Matrix* pUser2Device,
1408                                 const CPDF_Point& ptMoveTo,
1409                                 const CPDF_Point& ptLineTo,
1410                                 const FX_COLORREF& color,
1411                                 FX_FLOAT fWidth) {
1412   CFX_PathData path;
1413   path.SetPointCount(2);
1414   path.SetPoint(0, ptMoveTo.x, ptMoveTo.y, FXPT_MOVETO);
1415   path.SetPoint(1, ptLineTo.x, ptLineTo.y, FXPT_LINETO);
1416 
1417   CFX_GraphStateData gsd;
1418   gsd.m_LineWidth = fWidth;
1419 
1420   pDevice->DrawPath(&path, pUser2Device, &gsd, 0, color, FXFILL_ALTERNATE);
1421 }
1422 
DrawFillRect(CFX_RenderDevice * pDevice,CFX_Matrix * pUser2Device,const CPDF_Rect & rect,const CPWL_Color & color,int32_t nTransparancy)1423 void CPWL_Utils::DrawFillRect(CFX_RenderDevice* pDevice,
1424                               CFX_Matrix* pUser2Device,
1425                               const CPDF_Rect& rect,
1426                               const CPWL_Color& color,
1427                               int32_t nTransparancy) {
1428   CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rect,
1429                            PWLColorToFXColor(color, nTransparancy));
1430 }
1431 
DrawShadow(CFX_RenderDevice * pDevice,CFX_Matrix * pUser2Device,FX_BOOL bVertical,FX_BOOL bHorizontal,CPDF_Rect rect,int32_t nTransparancy,int32_t nStartGray,int32_t nEndGray)1432 void CPWL_Utils::DrawShadow(CFX_RenderDevice* pDevice,
1433                             CFX_Matrix* pUser2Device,
1434                             FX_BOOL bVertical,
1435                             FX_BOOL bHorizontal,
1436                             CPDF_Rect rect,
1437                             int32_t nTransparancy,
1438                             int32_t nStartGray,
1439                             int32_t nEndGray) {
1440   FX_FLOAT fStepGray = 1.0f;
1441 
1442   if (bVertical) {
1443     fStepGray = (nEndGray - nStartGray) / rect.Height();
1444 
1445     for (FX_FLOAT fy = rect.bottom + 0.5f; fy <= rect.top - 0.5f; fy += 1.0f) {
1446       int32_t nGray = nStartGray + (int32_t)(fStepGray * (fy - rect.bottom));
1447       CPWL_Utils::DrawStrokeLine(
1448           pDevice, pUser2Device, CPDF_Point(rect.left, fy),
1449           CPDF_Point(rect.right, fy),
1450           ArgbEncode(nTransparancy, nGray, nGray, nGray), 1.5f);
1451     }
1452   }
1453 
1454   if (bHorizontal) {
1455     fStepGray = (nEndGray - nStartGray) / rect.Width();
1456 
1457     for (FX_FLOAT fx = rect.left + 0.5f; fx <= rect.right - 0.5f; fx += 1.0f) {
1458       int32_t nGray = nStartGray + (int32_t)(fStepGray * (fx - rect.left));
1459       CPWL_Utils::DrawStrokeLine(
1460           pDevice, pUser2Device, CPDF_Point(fx, rect.bottom),
1461           CPDF_Point(fx, rect.top),
1462           ArgbEncode(nTransparancy, nGray, nGray, nGray), 1.5f);
1463     }
1464   }
1465 }
1466 
DrawBorder(CFX_RenderDevice * pDevice,CFX_Matrix * pUser2Device,const CPDF_Rect & rect,FX_FLOAT fWidth,const CPWL_Color & color,const CPWL_Color & crLeftTop,const CPWL_Color & crRightBottom,int32_t nStyle,int32_t nTransparancy)1467 void CPWL_Utils::DrawBorder(CFX_RenderDevice* pDevice,
1468                             CFX_Matrix* pUser2Device,
1469                             const CPDF_Rect& rect,
1470                             FX_FLOAT fWidth,
1471                             const CPWL_Color& color,
1472                             const CPWL_Color& crLeftTop,
1473                             const CPWL_Color& crRightBottom,
1474                             int32_t nStyle,
1475                             int32_t nTransparancy) {
1476   FX_FLOAT fLeft = rect.left;
1477   FX_FLOAT fRight = rect.right;
1478   FX_FLOAT fTop = rect.top;
1479   FX_FLOAT fBottom = rect.bottom;
1480 
1481   if (fWidth > 0.0f) {
1482     FX_FLOAT fHalfWidth = fWidth / 2.0f;
1483 
1484     switch (nStyle) {
1485       default:
1486       case PBS_SOLID: {
1487         CFX_PathData path;
1488         path.AppendRect(fLeft, fBottom, fRight, fTop);
1489         path.AppendRect(fLeft + fWidth, fBottom + fWidth, fRight - fWidth,
1490                         fTop - fWidth);
1491         pDevice->DrawPath(&path, pUser2Device, NULL,
1492                           PWLColorToFXColor(color, nTransparancy), 0,
1493                           FXFILL_ALTERNATE);
1494       } break;
1495       case PBS_DASH: {
1496         CFX_PathData path;
1497 
1498         path.SetPointCount(5);
1499         path.SetPoint(0, fLeft + fWidth / 2.0f, fBottom + fWidth / 2.0f,
1500                       FXPT_MOVETO);
1501         path.SetPoint(1, fLeft + fWidth / 2.0f, fTop - fWidth / 2.0f,
1502                       FXPT_LINETO);
1503         path.SetPoint(2, fRight - fWidth / 2.0f, fTop - fWidth / 2.0f,
1504                       FXPT_LINETO);
1505         path.SetPoint(3, fRight - fWidth / 2.0f, fBottom + fWidth / 2.0f,
1506                       FXPT_LINETO);
1507         path.SetPoint(4, fLeft + fWidth / 2.0f, fBottom + fWidth / 2.0f,
1508                       FXPT_LINETO);
1509 
1510         CFX_GraphStateData gsd;
1511         gsd.SetDashCount(2);
1512         gsd.m_DashArray[0] = 3.0f;
1513         gsd.m_DashArray[1] = 3.0f;
1514         gsd.m_DashPhase = 0;
1515 
1516         gsd.m_LineWidth = fWidth;
1517         pDevice->DrawPath(&path, pUser2Device, &gsd, 0,
1518                           PWLColorToFXColor(color, nTransparancy),
1519                           FXFILL_WINDING);
1520       } break;
1521       case PBS_BEVELED:
1522       case PBS_INSET: {
1523         CFX_GraphStateData gsd;
1524         gsd.m_LineWidth = fHalfWidth;
1525 
1526         CFX_PathData pathLT;
1527 
1528         pathLT.SetPointCount(7);
1529         pathLT.SetPoint(0, fLeft + fHalfWidth, fBottom + fHalfWidth,
1530                         FXPT_MOVETO);
1531         pathLT.SetPoint(1, fLeft + fHalfWidth, fTop - fHalfWidth, FXPT_LINETO);
1532         pathLT.SetPoint(2, fRight - fHalfWidth, fTop - fHalfWidth, FXPT_LINETO);
1533         pathLT.SetPoint(3, fRight - fHalfWidth * 2, fTop - fHalfWidth * 2,
1534                         FXPT_LINETO);
1535         pathLT.SetPoint(4, fLeft + fHalfWidth * 2, fTop - fHalfWidth * 2,
1536                         FXPT_LINETO);
1537         pathLT.SetPoint(5, fLeft + fHalfWidth * 2, fBottom + fHalfWidth * 2,
1538                         FXPT_LINETO);
1539         pathLT.SetPoint(6, fLeft + fHalfWidth, fBottom + fHalfWidth,
1540                         FXPT_LINETO);
1541 
1542         pDevice->DrawPath(&pathLT, pUser2Device, &gsd,
1543                           PWLColorToFXColor(crLeftTop, nTransparancy), 0,
1544                           FXFILL_ALTERNATE);
1545 
1546         CFX_PathData pathRB;
1547 
1548         pathRB.SetPointCount(7);
1549         pathRB.SetPoint(0, fRight - fHalfWidth, fTop - fHalfWidth, FXPT_MOVETO);
1550         pathRB.SetPoint(1, fRight - fHalfWidth, fBottom + fHalfWidth,
1551                         FXPT_LINETO);
1552         pathRB.SetPoint(2, fLeft + fHalfWidth, fBottom + fHalfWidth,
1553                         FXPT_LINETO);
1554         pathRB.SetPoint(3, fLeft + fHalfWidth * 2, fBottom + fHalfWidth * 2,
1555                         FXPT_LINETO);
1556         pathRB.SetPoint(4, fRight - fHalfWidth * 2, fBottom + fHalfWidth * 2,
1557                         FXPT_LINETO);
1558         pathRB.SetPoint(5, fRight - fHalfWidth * 2, fTop - fHalfWidth * 2,
1559                         FXPT_LINETO);
1560         pathRB.SetPoint(6, fRight - fHalfWidth, fTop - fHalfWidth, FXPT_LINETO);
1561 
1562         pDevice->DrawPath(&pathRB, pUser2Device, &gsd,
1563                           PWLColorToFXColor(crRightBottom, nTransparancy), 0,
1564                           FXFILL_ALTERNATE);
1565 
1566         CFX_PathData path;
1567 
1568         path.AppendRect(fLeft, fBottom, fRight, fTop);
1569         path.AppendRect(fLeft + fHalfWidth, fBottom + fHalfWidth,
1570                         fRight - fHalfWidth, fTop - fHalfWidth);
1571 
1572         pDevice->DrawPath(&path, pUser2Device, &gsd,
1573                           PWLColorToFXColor(color, nTransparancy), 0,
1574                           FXFILL_ALTERNATE);
1575       } break;
1576       case PBS_UNDERLINED: {
1577         CFX_PathData path;
1578 
1579         path.SetPointCount(2);
1580         path.SetPoint(0, fLeft, fBottom + fWidth / 2, FXPT_MOVETO);
1581         path.SetPoint(1, fRight, fBottom + fWidth / 2, FXPT_LINETO);
1582 
1583         CFX_GraphStateData gsd;
1584         gsd.m_LineWidth = fWidth;
1585 
1586         pDevice->DrawPath(&path, pUser2Device, &gsd, 0,
1587                           PWLColorToFXColor(color, nTransparancy),
1588                           FXFILL_ALTERNATE);
1589       } break;
1590       case PBS_SHADOW: {
1591         CFX_PathData path;
1592         path.AppendRect(fLeft, fBottom, fRight, fTop);
1593         path.AppendRect(fLeft + fWidth, fBottom + fWidth, fRight - fWidth,
1594                         fTop - fWidth);
1595         pDevice->DrawPath(&path, pUser2Device, NULL,
1596                           PWLColorToFXColor(color, nTransparancy / 2), 0,
1597                           FXFILL_ALTERNATE);
1598       } break;
1599     }
1600   }
1601 }
1602 
AddSquigglyPath(CFX_PathData & PathData,FX_FLOAT fStartX,FX_FLOAT fEndX,FX_FLOAT fY,FX_FLOAT fStep)1603 static void AddSquigglyPath(CFX_PathData& PathData,
1604                             FX_FLOAT fStartX,
1605                             FX_FLOAT fEndX,
1606                             FX_FLOAT fY,
1607                             FX_FLOAT fStep) {
1608   PathData.AddPointCount(1);
1609   PathData.SetPoint(PathData.GetPointCount() - 1, fStartX, fY, FXPT_MOVETO);
1610 
1611   FX_FLOAT fx;
1612   int32_t i;
1613 
1614   for (i = 1, fx = fStartX + fStep; fx < fEndX; fx += fStep, i++) {
1615     PathData.AddPointCount(1);
1616     PathData.SetPoint(PathData.GetPointCount() - 1, fx, fY + (i & 1) * fStep,
1617                       FXPT_LINETO);
1618   }
1619 }
1620 
AddSpellCheckObj(CFX_PathData & PathData,IFX_Edit * pEdit,const CPVT_WordRange & wrWord)1621 static void AddSpellCheckObj(CFX_PathData& PathData,
1622                              IFX_Edit* pEdit,
1623                              const CPVT_WordRange& wrWord) {
1624   FX_FLOAT fStartX = 0.0f;
1625   FX_FLOAT fEndX = 0.0f;
1626   FX_FLOAT fY = 0.0f;
1627   FX_FLOAT fStep = 0.0f;
1628 
1629   FX_BOOL bBreak = FALSE;
1630 
1631   if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) {
1632     pIterator->SetAt(wrWord.BeginPos);
1633 
1634     do {
1635       CPVT_WordPlace place = pIterator->GetAt();
1636 
1637       CPVT_Line line;
1638       if (pIterator->GetLine(line)) {
1639         fY = line.ptLine.y;
1640         fStep = (line.fLineAscent - line.fLineDescent) / 16.0f;
1641       }
1642 
1643       if (place.LineCmp(wrWord.BeginPos) == 0) {
1644         pIterator->SetAt(wrWord.BeginPos);
1645         CPVT_Word word;
1646         if (pIterator->GetWord(word)) {
1647           fStartX = word.ptWord.x;
1648         }
1649       } else {
1650         fStartX = line.ptLine.x;
1651       }
1652 
1653       if (place.LineCmp(wrWord.EndPos) == 0) {
1654         pIterator->SetAt(wrWord.EndPos);
1655         CPVT_Word word;
1656         if (pIterator->GetWord(word)) {
1657           fEndX = word.ptWord.x + word.fWidth;
1658         }
1659 
1660         bBreak = TRUE;
1661       } else {
1662         fEndX = line.ptLine.x + line.fLineWidth;
1663       }
1664 
1665       AddSquigglyPath(PathData, fStartX, fEndX, fY, fStep);
1666 
1667       if (bBreak)
1668         break;
1669     } while (pIterator->NextLine());
1670   }
1671 }
1672 
DrawEditSpellCheck(CFX_RenderDevice * pDevice,CFX_Matrix * pUser2Device,IFX_Edit * pEdit,const CPDF_Rect & rcClip,const CPDF_Point & ptOffset,const CPVT_WordRange * pRange,IPWL_SpellCheck * pSpellCheck)1673 void CPWL_Utils::DrawEditSpellCheck(CFX_RenderDevice* pDevice,
1674                                     CFX_Matrix* pUser2Device,
1675                                     IFX_Edit* pEdit,
1676                                     const CPDF_Rect& rcClip,
1677                                     const CPDF_Point& ptOffset,
1678                                     const CPVT_WordRange* pRange,
1679                                     IPWL_SpellCheck* pSpellCheck) {
1680   const FX_COLORREF crSpell = ArgbEncode(255, 255, 0, 0);
1681 
1682   // for spellcheck
1683   FX_BOOL bLatinWord = FALSE;
1684   CPVT_WordPlace wpWordStart;
1685   CFX_ByteString sLatinWord;
1686 
1687   CFX_PathData pathSpell;
1688 
1689   pDevice->SaveState();
1690 
1691   if (!rcClip.IsEmpty()) {
1692     CPDF_Rect rcTemp = rcClip;
1693     pUser2Device->TransformRect(rcTemp);
1694     FX_RECT rcDevClip;
1695     rcDevClip.left = (int32_t)rcTemp.left;
1696     rcDevClip.right = (int32_t)rcTemp.right;
1697     rcDevClip.top = (int32_t)rcTemp.top;
1698     rcDevClip.bottom = (int32_t)rcTemp.bottom;
1699     pDevice->SetClip_Rect(&rcDevClip);
1700   }
1701 
1702   if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) {
1703     if (pEdit->GetFontMap()) {
1704       if (pRange)
1705         pIterator->SetAt(pRange->BeginPos);
1706       else
1707         pIterator->SetAt(0);
1708 
1709       CPVT_WordPlace oldplace;
1710 
1711       while (pIterator->NextWord()) {
1712         CPVT_WordPlace place = pIterator->GetAt();
1713         if (pRange && place.WordCmp(pRange->EndPos) > 0)
1714           break;
1715 
1716         CPVT_Word word;
1717         if (pIterator->GetWord(word)) {
1718           if (FX_EDIT_ISLATINWORD(word.Word)) {
1719             if (!bLatinWord) {
1720               wpWordStart = place;
1721               bLatinWord = TRUE;
1722             }
1723 
1724             sLatinWord += (char)word.Word;
1725           } else {
1726             if (bLatinWord) {
1727               if (!sLatinWord.IsEmpty()) {
1728                 if (pSpellCheck && !pSpellCheck->CheckWord(sLatinWord)) {
1729                   AddSpellCheckObj(pathSpell, pEdit,
1730                                    CPVT_WordRange(wpWordStart, oldplace));
1731                   pIterator->SetAt(place);
1732                 }
1733               }
1734               bLatinWord = FALSE;
1735             }
1736 
1737             sLatinWord.Empty();
1738           }
1739 
1740           oldplace = place;
1741         } else {
1742           if (bLatinWord) {
1743             if (!sLatinWord.IsEmpty()) {
1744               if (pSpellCheck && !pSpellCheck->CheckWord(sLatinWord)) {
1745                 AddSpellCheckObj(pathSpell, pEdit,
1746                                  CPVT_WordRange(wpWordStart, oldplace));
1747                 pIterator->SetAt(place);
1748               }
1749             }
1750             bLatinWord = FALSE;
1751           }
1752 
1753           sLatinWord.Empty();
1754         }
1755       }
1756 
1757       if (!sLatinWord.IsEmpty()) {
1758         if (pSpellCheck && !pSpellCheck->CheckWord(sLatinWord)) {
1759           AddSpellCheckObj(pathSpell, pEdit,
1760                            CPVT_WordRange(wpWordStart, oldplace));
1761         }
1762       }
1763     }
1764   }
1765 
1766   CFX_GraphStateData gsd;
1767   gsd.m_LineWidth = 0;
1768   if (pathSpell.GetPointCount() > 0)
1769     pDevice->DrawPath(&pathSpell, pUser2Device, &gsd, 0, crSpell,
1770                       FXFILL_ALTERNATE);
1771 
1772   pDevice->RestoreState();
1773 }
1774 
IsBlackOrWhite(const CPWL_Color & color)1775 FX_BOOL CPWL_Utils::IsBlackOrWhite(const CPWL_Color& color) {
1776   switch (color.nColorType) {
1777     case COLORTYPE_TRANSPARENT:
1778       return FALSE;
1779     case COLORTYPE_GRAY:
1780       return color.fColor1 < 0.5f;
1781     case COLORTYPE_RGB:
1782       return color.fColor1 + color.fColor2 + color.fColor3 < 1.5f;
1783     case COLORTYPE_CMYK:
1784       return color.fColor1 + color.fColor2 + color.fColor3 + color.fColor4 >
1785              2.0f;
1786   }
1787 
1788   return TRUE;
1789 }
1790 
GetReverseColor(const CPWL_Color & color)1791 CPWL_Color CPWL_Utils::GetReverseColor(const CPWL_Color& color) {
1792   CPWL_Color crRet = color;
1793 
1794   switch (color.nColorType) {
1795     case COLORTYPE_GRAY:
1796       crRet.fColor1 = 1.0f - crRet.fColor1;
1797       break;
1798     case COLORTYPE_RGB:
1799       crRet.fColor1 = 1.0f - crRet.fColor1;
1800       crRet.fColor2 = 1.0f - crRet.fColor2;
1801       crRet.fColor3 = 1.0f - crRet.fColor3;
1802       break;
1803     case COLORTYPE_CMYK:
1804       crRet.fColor1 = 1.0f - crRet.fColor1;
1805       crRet.fColor2 = 1.0f - crRet.fColor2;
1806       crRet.fColor3 = 1.0f - crRet.fColor3;
1807       crRet.fColor4 = 1.0f - crRet.fColor4;
1808       break;
1809   }
1810 
1811   return crRet;
1812 }
1813 
GetIconAppStream(int32_t nType,const CPDF_Rect & rect,const CPWL_Color & crFill,const CPWL_Color & crStroke)1814 CFX_ByteString CPWL_Utils::GetIconAppStream(int32_t nType,
1815                                             const CPDF_Rect& rect,
1816                                             const CPWL_Color& crFill,
1817                                             const CPWL_Color& crStroke) {
1818   CFX_ByteString sAppStream = CPWL_Utils::GetColorAppStream(crStroke, FALSE);
1819   sAppStream += CPWL_Utils::GetColorAppStream(crFill, TRUE);
1820 
1821   CFX_ByteString sPath;
1822   CFX_PathData path;
1823 
1824   switch (nType) {
1825     case PWL_ICONTYPE_CHECKMARK:
1826       GetGraphics_Checkmark(sPath, path, rect, PWLPT_STREAM);
1827       break;
1828     case PWL_ICONTYPE_CIRCLE:
1829       GetGraphics_Circle(sPath, path, rect, PWLPT_STREAM);
1830       break;
1831     case PWL_ICONTYPE_COMMENT:
1832       GetGraphics_Comment(sPath, path, rect, PWLPT_STREAM);
1833       break;
1834     case PWL_ICONTYPE_CROSS:
1835       GetGraphics_Cross(sPath, path, rect, PWLPT_STREAM);
1836       break;
1837     case PWL_ICONTYPE_HELP:
1838       GetGraphics_Help(sPath, path, rect, PWLPT_STREAM);
1839       break;
1840     case PWL_ICONTYPE_INSERTTEXT:
1841       GetGraphics_InsertText(sPath, path, rect, PWLPT_STREAM);
1842       break;
1843     case PWL_ICONTYPE_KEY:
1844       GetGraphics_Key(sPath, path, rect, PWLPT_STREAM);
1845       break;
1846     case PWL_ICONTYPE_NEWPARAGRAPH:
1847       GetGraphics_NewParagraph(sPath, path, rect, PWLPT_STREAM);
1848       break;
1849     case PWL_ICONTYPE_TEXTNOTE:
1850       GetGraphics_TextNote(sPath, path, rect, PWLPT_STREAM);
1851       break;
1852     case PWL_ICONTYPE_PARAGRAPH:
1853       GetGraphics_Paragraph(sPath, path, rect, PWLPT_STREAM);
1854       break;
1855     case PWL_ICONTYPE_RIGHTARROW:
1856       GetGraphics_RightArrow(sPath, path, rect, PWLPT_STREAM);
1857       break;
1858     case PWL_ICONTYPE_RIGHTPOINTER:
1859       GetGraphics_RightPointer(sPath, path, rect, PWLPT_STREAM);
1860       break;
1861     case PWL_ICONTYPE_STAR:
1862       GetGraphics_Star(sPath, path, rect, PWLPT_STREAM);
1863       break;
1864     case PWL_ICONTYPE_UPARROW:
1865       GetGraphics_UpArrow(sPath, path, rect, PWLPT_STREAM);
1866       break;
1867     case PWL_ICONTYPE_UPLEFTARROW:
1868       GetGraphics_UpLeftArrow(sPath, path, rect, PWLPT_STREAM);
1869       break;
1870     case PWL_ICONTYPE_GRAPH:
1871       GetGraphics_Graph(sPath, path, rect, PWLPT_STREAM);
1872       break;
1873     case PWL_ICONTYPE_PAPERCLIP:
1874       GetGraphics_Paperclip(sPath, path, rect, PWLPT_STREAM);
1875       break;
1876     case PWL_ICONTYPE_ATTACHMENT:
1877       GetGraphics_Attachment(sPath, path, rect, PWLPT_STREAM);
1878       break;
1879     case PWL_ICONTYPE_TAG:
1880       GetGraphics_Tag(sPath, path, rect, PWLPT_STREAM);
1881       break;
1882     case PWL_ICONTYPE_FOXIT:
1883       GetGraphics_Foxit(sPath, path, rect, PWLPT_STREAM);
1884       break;
1885   }
1886 
1887   sAppStream += sPath;
1888   if (crStroke.nColorType != COLORTYPE_TRANSPARENT)
1889     sAppStream += "B*\n";
1890   else
1891     sAppStream += "f*\n";
1892 
1893   return sAppStream;
1894 }
1895 
DrawIconAppStream(CFX_RenderDevice * pDevice,CFX_Matrix * pUser2Device,int32_t nType,const CPDF_Rect & rect,const CPWL_Color & crFill,const CPWL_Color & crStroke,const int32_t nTransparancy)1896 void CPWL_Utils::DrawIconAppStream(CFX_RenderDevice* pDevice,
1897                                    CFX_Matrix* pUser2Device,
1898                                    int32_t nType,
1899                                    const CPDF_Rect& rect,
1900                                    const CPWL_Color& crFill,
1901                                    const CPWL_Color& crStroke,
1902                                    const int32_t nTransparancy) {
1903   CFX_GraphStateData gsd;
1904   gsd.m_LineWidth = 1.0f;
1905 
1906   CFX_ByteString sPath;
1907   CFX_PathData path;
1908 
1909   switch (nType) {
1910     case PWL_ICONTYPE_CHECKMARK:
1911       GetGraphics_Checkmark(sPath, path, rect, PWLPT_PATHDATA);
1912       break;
1913     case PWL_ICONTYPE_CIRCLE:
1914       GetGraphics_Circle(sPath, path, rect, PWLPT_PATHDATA);
1915       break;
1916     case PWL_ICONTYPE_COMMENT:
1917       GetGraphics_Comment(sPath, path, rect, PWLPT_PATHDATA);
1918       break;
1919     case PWL_ICONTYPE_CROSS:
1920       GetGraphics_Cross(sPath, path, rect, PWLPT_PATHDATA);
1921       break;
1922     case PWL_ICONTYPE_HELP:
1923       GetGraphics_Help(sPath, path, rect, PWLPT_PATHDATA);
1924       break;
1925     case PWL_ICONTYPE_INSERTTEXT:
1926       GetGraphics_InsertText(sPath, path, rect, PWLPT_PATHDATA);
1927       break;
1928     case PWL_ICONTYPE_KEY:
1929       GetGraphics_Key(sPath, path, rect, PWLPT_PATHDATA);
1930       break;
1931     case PWL_ICONTYPE_NEWPARAGRAPH:
1932       GetGraphics_NewParagraph(sPath, path, rect, PWLPT_PATHDATA);
1933       break;
1934     case PWL_ICONTYPE_TEXTNOTE:
1935       GetGraphics_TextNote(sPath, path, rect, PWLPT_PATHDATA);
1936       break;
1937     case PWL_ICONTYPE_PARAGRAPH:
1938       GetGraphics_Paragraph(sPath, path, rect, PWLPT_PATHDATA);
1939       break;
1940     case PWL_ICONTYPE_RIGHTARROW:
1941       GetGraphics_RightArrow(sPath, path, rect, PWLPT_PATHDATA);
1942       break;
1943     case PWL_ICONTYPE_RIGHTPOINTER:
1944       GetGraphics_RightPointer(sPath, path, rect, PWLPT_PATHDATA);
1945       break;
1946     case PWL_ICONTYPE_STAR:
1947       GetGraphics_Star(sPath, path, rect, PWLPT_PATHDATA);
1948       break;
1949     case PWL_ICONTYPE_UPARROW:
1950       GetGraphics_UpArrow(sPath, path, rect, PWLPT_PATHDATA);
1951       break;
1952     case PWL_ICONTYPE_UPLEFTARROW:
1953       GetGraphics_UpLeftArrow(sPath, path, rect, PWLPT_PATHDATA);
1954       break;
1955     case PWL_ICONTYPE_GRAPH:
1956       GetGraphics_Graph(sPath, path, rect, PWLPT_PATHDATA);
1957       break;
1958     case PWL_ICONTYPE_PAPERCLIP:
1959       GetGraphics_Paperclip(sPath, path, rect, PWLPT_PATHDATA);
1960       break;
1961     case PWL_ICONTYPE_ATTACHMENT:
1962       GetGraphics_Attachment(sPath, path, rect, PWLPT_PATHDATA);
1963       break;
1964     case PWL_ICONTYPE_TAG:
1965       GetGraphics_Tag(sPath, path, rect, PWLPT_PATHDATA);
1966       break;
1967     case PWL_ICONTYPE_FOXIT:
1968       GetGraphics_Foxit(sPath, path, rect, PWLPT_PATHDATA);
1969       break;
1970     default:
1971       return;
1972   }
1973 
1974   pDevice->DrawPath(
1975       &path, pUser2Device, &gsd, PWLColorToFXColor(crFill, nTransparancy),
1976       PWLColorToFXColor(crStroke, nTransparancy), FXFILL_ALTERNATE);
1977 }
1978 
GetGraphics_Checkmark(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)1979 void CPWL_Utils::GetGraphics_Checkmark(CFX_ByteString& sPathData,
1980                                        CFX_PathData& path,
1981                                        const CPDF_Rect& crBBox,
1982                                        const PWL_PATH_TYPE type) {
1983   FX_FLOAT fWidth = crBBox.right - crBBox.left;
1984   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
1985 
1986   CPWL_PathData PathArray[] = {
1987       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 15.0f,
1988                                crBBox.bottom + fHeight * 2 / 5.0f),
1989                     PWLPT_MOVETO),
1990       CPWL_PathData(
1991           CPWL_Point(
1992               crBBox.left + fWidth / 15.0f +
1993                   PWL_BEZIER * (fWidth / 7.0f - fWidth / 15.0f),
1994               crBBox.bottom + fHeight * 2 / 5.0f +
1995                   PWL_BEZIER * (fHeight * 2 / 7.0f - fHeight * 2 / 5.0f)),
1996           PWLPT_BEZIERTO),
1997       CPWL_PathData(
1998           CPWL_Point(crBBox.left + fWidth / 4.5f +
1999                          PWL_BEZIER * (fWidth / 5.0f - fWidth / 4.5f),
2000                      crBBox.bottom + fHeight / 16.0f +
2001                          PWL_BEZIER * (fHeight / 5.0f - fHeight / 16.0f)),
2002           PWLPT_BEZIERTO),
2003       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 4.5f,
2004                                crBBox.bottom + fHeight / 16.0f),
2005                     PWLPT_BEZIERTO),
2006       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 4.5f +
2007                                    PWL_BEZIER * (fWidth / 4.4f - fWidth / 4.5f),
2008                                crBBox.bottom + fHeight / 16.0f -
2009                                    PWL_BEZIER * fHeight / 16.0f),
2010                     PWLPT_BEZIERTO),
2011       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 3.0f +
2012                                    PWL_BEZIER * (fWidth / 4.0f - fWidth / 3.0f),
2013                                crBBox.bottom),
2014                     PWLPT_BEZIERTO),
2015       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 3.0f, crBBox.bottom),
2016                     PWLPT_BEZIERTO),
2017       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 3.0f +
2018                                    PWL_BEZIER * fWidth * (1 / 7.0f + 2 / 15.0f),
2019                                crBBox.bottom + PWL_BEZIER * fHeight * 4 / 5.0f),
2020                     PWLPT_BEZIERTO),
2021       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 14 / 15.0f +
2022                                    PWL_BEZIER * fWidth * (1 / 7.0f - 7 / 15.0f),
2023                                crBBox.bottom + fHeight * 15 / 16.0f +
2024                                    PWL_BEZIER * (fHeight * 4 / 5.0f -
2025                                                  fHeight * 15 / 16.0f)),
2026                     PWLPT_BEZIERTO),
2027       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 14 / 15.0f,
2028                                crBBox.bottom + fHeight * 15 / 16.0f),
2029                     PWLPT_BEZIERTO),
2030       CPWL_PathData(
2031           CPWL_Point(
2032               crBBox.left + fWidth * 14 / 15.0f +
2033                   PWL_BEZIER * (fWidth * 7 / 15.0f - fWidth * 14 / 15.0f),
2034               crBBox.bottom + fHeight * 15 / 16.0f +
2035                   PWL_BEZIER * (fHeight * 8 / 7.0f - fHeight * 15 / 16.0f)),
2036           PWLPT_BEZIERTO),
2037       CPWL_PathData(
2038           CPWL_Point(crBBox.left + fWidth / 3.6f +
2039                          PWL_BEZIER * (fWidth / 3.4f - fWidth / 3.6f),
2040                      crBBox.bottom + fHeight / 3.5f +
2041                          PWL_BEZIER * (fHeight / 3.5f - fHeight / 3.5f)),
2042           PWLPT_BEZIERTO),
2043       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 3.6f,
2044                                crBBox.bottom + fHeight / 3.5f),
2045                     PWLPT_BEZIERTO),
2046       CPWL_PathData(
2047           CPWL_Point(crBBox.left + fWidth / 3.6f,
2048                      crBBox.bottom + fHeight / 3.5f +
2049                          PWL_BEZIER * (fHeight / 4.0f - fHeight / 3.5f)),
2050           PWLPT_BEZIERTO),
2051       CPWL_PathData(
2052           CPWL_Point(
2053               crBBox.left + fWidth / 15.0f +
2054                   PWL_BEZIER * (fWidth / 3.5f - fWidth / 15.0f),
2055               crBBox.bottom + fHeight * 2 / 5.0f +
2056                   PWL_BEZIER * (fHeight * 3.5f / 5.0f - fHeight * 2 / 5.0f)),
2057           PWLPT_BEZIERTO),
2058       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 15.0f,
2059                                crBBox.bottom + fHeight * 2 / 5.0f),
2060                     PWLPT_BEZIERTO)};
2061 
2062   if (type == PWLPT_STREAM)
2063     sPathData = GetAppStreamFromArray(PathArray, 16);
2064   else
2065     GetPathDataFromArray(path, PathArray, 16);
2066 }
2067 
GetGraphics_Circle(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)2068 void CPWL_Utils::GetGraphics_Circle(CFX_ByteString& sPathData,
2069                                     CFX_PathData& path,
2070                                     const CPDF_Rect& crBBox,
2071                                     const PWL_PATH_TYPE type) {
2072   FX_FLOAT fWidth = crBBox.right - crBBox.left;
2073   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
2074 
2075   CPWL_PathData PathArray[] = {
2076       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 15.0f,
2077                                crBBox.bottom + fHeight / 2.0f),
2078                     PWLPT_MOVETO),
2079       CPWL_PathData(
2080           CPWL_Point(crBBox.left + fWidth / 15.0f,
2081                      crBBox.bottom + fHeight / 2.0f +
2082                          PWL_BEZIER * (fHeight * 14 / 15.0f - fHeight / 2.0f)),
2083           PWLPT_BEZIERTO),
2084       CPWL_PathData(
2085           CPWL_Point(crBBox.left + fWidth / 2.0f -
2086                          PWL_BEZIER * (fWidth / 2.0f - fWidth / 15.0f),
2087                      crBBox.top - fHeight / 15.0f),
2088           PWLPT_BEZIERTO),
2089       CPWL_PathData(
2090           CPWL_Point(crBBox.left + fWidth / 2.0f, crBBox.top - fHeight / 15.0f),
2091           PWLPT_BEZIERTO),
2092       CPWL_PathData(
2093           CPWL_Point(crBBox.left + fWidth / 2.0f +
2094                          PWL_BEZIER * (fWidth * 14 / 15.0f - fWidth / 2.0f),
2095                      crBBox.top - fHeight / 15.0f),
2096           PWLPT_BEZIERTO),
2097       CPWL_PathData(
2098           CPWL_Point(crBBox.right - fWidth / 15.0f,
2099                      crBBox.bottom + fHeight / 2.0f +
2100                          PWL_BEZIER * (fHeight * 14 / 15.0f - fHeight / 2.0f)),
2101           PWLPT_BEZIERTO),
2102       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 15.0f,
2103                                crBBox.bottom + fHeight / 2.0f),
2104                     PWLPT_BEZIERTO),
2105       CPWL_PathData(
2106           CPWL_Point(crBBox.right - fWidth / 15.0f,
2107                      crBBox.bottom + fHeight / 2.0f -
2108                          PWL_BEZIER * (fHeight / 2.0f - fHeight / 15.0f)),
2109           PWLPT_BEZIERTO),
2110       CPWL_PathData(
2111           CPWL_Point(crBBox.left + fWidth / 2.0f +
2112                          PWL_BEZIER * (fWidth * 14 / 15.0f - fWidth / 2.0f),
2113                      crBBox.bottom + fHeight / 15.0f),
2114           PWLPT_BEZIERTO),
2115       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 2.0f,
2116                                crBBox.bottom + fHeight / 15.0f),
2117                     PWLPT_BEZIERTO),
2118       CPWL_PathData(
2119           CPWL_Point(crBBox.left + fWidth / 2.0f -
2120                          PWL_BEZIER * (fWidth / 2.0f - fWidth / 15.0f),
2121                      crBBox.bottom + fHeight / 15.0f),
2122           PWLPT_BEZIERTO),
2123       CPWL_PathData(
2124           CPWL_Point(crBBox.left + fWidth / 15.0f,
2125                      crBBox.bottom + fHeight / 2.0f -
2126                          PWL_BEZIER * (fHeight / 2.0f - fHeight / 15.0f)),
2127           PWLPT_BEZIERTO),
2128       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 15.0f,
2129                                crBBox.bottom + fHeight / 2.0f),
2130                     PWLPT_BEZIERTO),
2131       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 3 / 15.0f,
2132                                crBBox.bottom + fHeight / 2.0f),
2133                     PWLPT_MOVETO),
2134       CPWL_PathData(
2135           CPWL_Point(crBBox.left + fWidth * 3 / 15.0f,
2136                      crBBox.bottom + fHeight / 2.0f +
2137                          PWL_BEZIER * (fHeight * 4 / 5.0f - fHeight / 2.0f)),
2138           PWLPT_BEZIERTO),
2139       CPWL_PathData(
2140           CPWL_Point(crBBox.left + fWidth / 2.0f -
2141                          PWL_BEZIER * (fWidth / 2.0f - fWidth * 3 / 15.0f),
2142                      crBBox.top - fHeight * 3 / 15.0f),
2143           PWLPT_BEZIERTO),
2144       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 2.0f,
2145                                crBBox.top - fHeight * 3 / 15.0f),
2146                     PWLPT_BEZIERTO),
2147       CPWL_PathData(
2148           CPWL_Point(crBBox.left + fWidth / 2.0f +
2149                          PWL_BEZIER * (fWidth * 4 / 5.0f - fWidth / 2.0f),
2150                      crBBox.top - fHeight * 3 / 15.0f),
2151           PWLPT_BEZIERTO),
2152       CPWL_PathData(
2153           CPWL_Point(crBBox.right - fWidth * 3 / 15.0f,
2154                      crBBox.bottom + fHeight / 2.0f +
2155                          PWL_BEZIER * (fHeight * 4 / 5.0f - fHeight / 2.0f)),
2156           PWLPT_BEZIERTO),
2157       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 3 / 15.0f,
2158                                crBBox.bottom + fHeight / 2.0f),
2159                     PWLPT_BEZIERTO),
2160       CPWL_PathData(
2161           CPWL_Point(crBBox.right - fWidth * 3 / 15.0f,
2162                      crBBox.bottom + fHeight / 2.0f -
2163                          PWL_BEZIER * (fHeight * 4 / 5.0f - fHeight / 2.0f)),
2164           PWLPT_BEZIERTO),
2165       CPWL_PathData(
2166           CPWL_Point(crBBox.left + fWidth / 2.0f +
2167                          PWL_BEZIER * (fWidth * 4 / 5.0f - fWidth / 2.0f),
2168                      crBBox.bottom + fHeight * 3 / 15.0f),
2169           PWLPT_BEZIERTO),
2170       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 2.0f,
2171                                crBBox.bottom + fHeight * 3 / 15.0f),
2172                     PWLPT_BEZIERTO),
2173       CPWL_PathData(
2174           CPWL_Point(crBBox.left + fWidth / 2.0f -
2175                          PWL_BEZIER * (fWidth * 4 / 5.0f - fWidth / 2.0f),
2176                      crBBox.bottom + fHeight * 3 / 15.0f),
2177           PWLPT_BEZIERTO),
2178       CPWL_PathData(
2179           CPWL_Point(crBBox.left + fWidth * 3 / 15.0f,
2180                      crBBox.bottom + fHeight / 2.0f -
2181                          PWL_BEZIER * (fHeight * 4 / 5.0f - fHeight / 2.0f)),
2182           PWLPT_BEZIERTO),
2183       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 3 / 15.0f,
2184                                crBBox.bottom + fHeight / 2.0f),
2185                     PWLPT_BEZIERTO)};
2186 
2187   if (type == PWLPT_STREAM)
2188     sPathData = GetAppStreamFromArray(PathArray, 26);
2189   else
2190     GetPathDataFromArray(path, PathArray, 26);
2191 }
2192 
GetGraphics_Comment(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)2193 void CPWL_Utils::GetGraphics_Comment(CFX_ByteString& sPathData,
2194                                      CFX_PathData& path,
2195                                      const CPDF_Rect& crBBox,
2196                                      const PWL_PATH_TYPE type) {
2197   FX_FLOAT fWidth = crBBox.right - crBBox.left;
2198   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
2199 
2200   CPWL_PathData PathArray[] = {
2201       CPWL_PathData(
2202           CPWL_Point(crBBox.left + fWidth / 15.0f, crBBox.top - fHeight / 6.0f),
2203           PWLPT_MOVETO),
2204       CPWL_PathData(
2205           CPWL_Point(crBBox.left + fWidth / 15.0f,
2206                      crBBox.top - fHeight / 6.0f +
2207                          PWL_BEZIER * (fHeight / 6.0f - fHeight / 10.0f)),
2208           PWLPT_BEZIERTO),
2209       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 2 / 15.0f -
2210                                    PWL_BEZIER * fWidth / 15.0f,
2211                                crBBox.top - fHeight / 10.0f),
2212                     PWLPT_BEZIERTO),
2213       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 2 / 15.0f,
2214                                crBBox.top - fHeight / 10.0f),
2215                     PWLPT_BEZIERTO),
2216       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 2 / 15.0f,
2217                                crBBox.top - fHeight / 10.0f),
2218                     PWLPT_LINETO),
2219       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 2 / 15.0f +
2220                                    PWL_BEZIER * fWidth / 15.0f,
2221                                crBBox.top - fHeight / 10.0f),
2222                     PWLPT_BEZIERTO),
2223       CPWL_PathData(
2224           CPWL_Point(crBBox.right - fWidth / 15.0f,
2225                      crBBox.top - fHeight / 6 +
2226                          PWL_BEZIER * (fHeight / 6.0f - fHeight / 10.0f)),
2227           PWLPT_BEZIERTO),
2228       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 15.0f,
2229                                crBBox.top - fHeight / 6.0f),
2230                     PWLPT_BEZIERTO),
2231       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 15.0f,
2232                                crBBox.bottom + fHeight / 3.0f),
2233                     PWLPT_LINETO),
2234       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 15.0f,
2235                                crBBox.bottom + fHeight * 4 / 15.0f +
2236                                    PWL_BEZIER * fHeight / 15.0f),
2237                     PWLPT_BEZIERTO),
2238       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 2 / 15.0f +
2239                                    PWL_BEZIER * fWidth / 15.0f,
2240                                crBBox.bottom + fHeight * 4 / 15.0f),
2241                     PWLPT_BEZIERTO),
2242       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 2 / 15.0f,
2243                                crBBox.bottom + fHeight * 4 / 15.0f),
2244                     PWLPT_BEZIERTO),
2245       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 5 / 15.0f,
2246                                crBBox.bottom + fHeight * 4 / 15.0f),
2247                     PWLPT_LINETO),
2248       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 5 / 15.0f,
2249                                crBBox.bottom + fHeight * 2 / 15 +
2250                                    PWL_BEZIER * fHeight * 2 / 15.0f),
2251                     PWLPT_BEZIERTO),
2252       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 5 / 15.0f -
2253                                    PWL_BEZIER * fWidth * 2 / 15.0f,
2254                                crBBox.bottom + fHeight * 2 / 15.0f),
2255                     PWLPT_BEZIERTO),
2256       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 6 / 30.0f,
2257                                crBBox.bottom + fHeight * 2 / 15.0f),
2258                     PWLPT_BEZIERTO),
2259       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 7 / 30.0f +
2260                                    PWL_BEZIER * fWidth / 30.0f,
2261                                crBBox.bottom + fHeight * 2 / 15.0f),
2262                     PWLPT_BEZIERTO),
2263       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 7 / 30.0f,
2264                                crBBox.bottom + fHeight * 2 / 15.0f +
2265                                    PWL_BEZIER * fHeight * 2 / 15.0f),
2266                     PWLPT_BEZIERTO),
2267       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 7 / 30.0f,
2268                                crBBox.bottom + fHeight * 4 / 15.0f),
2269                     PWLPT_BEZIERTO),
2270       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 2 / 15.0f,
2271                                crBBox.bottom + fHeight * 4 / 15.0f),
2272                     PWLPT_LINETO),
2273       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 2 / 15.0f -
2274                                    PWL_BEZIER * fWidth / 15.0f,
2275                                crBBox.bottom + fHeight * 4 / 15.0f),
2276                     PWLPT_BEZIERTO),
2277       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 15.0f,
2278                                crBBox.bottom + fHeight / 3.0f -
2279                                    PWL_BEZIER * fHeight / 15.0f),
2280                     PWLPT_BEZIERTO),
2281       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 15.0f,
2282                                crBBox.bottom + fHeight / 3.0f),
2283                     PWLPT_BEZIERTO),
2284       CPWL_PathData(
2285           CPWL_Point(crBBox.left + fWidth / 15.0f, crBBox.top - fHeight / 6.0f),
2286           PWLPT_LINETO),
2287       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 2 / 15.0f,
2288                                crBBox.top - fHeight * 8 / 30.0f),
2289                     PWLPT_MOVETO),
2290       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 2 / 15.0f,
2291                                crBBox.top - fHeight * 8 / 30.0f),
2292                     PWLPT_LINETO),
2293       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 2 / 15,
2294                                crBBox.top - fHeight * 25 / 60.0f),
2295                     PWLPT_MOVETO),
2296       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 2 / 15.0f,
2297                                crBBox.top - fHeight * 25 / 60.0f),
2298                     PWLPT_LINETO),
2299       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 2 / 15.0f,
2300                                crBBox.top - fHeight * 17 / 30.0f),
2301                     PWLPT_MOVETO),
2302       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 4 / 15.0f,
2303                                crBBox.top - fHeight * 17 / 30.0f),
2304                     PWLPT_LINETO)};
2305 
2306   if (type == PWLPT_STREAM)
2307     sPathData = GetAppStreamFromArray(PathArray, 30);
2308   else
2309     GetPathDataFromArray(path, PathArray, 30);
2310 }
2311 
GetGraphics_Cross(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)2312 void CPWL_Utils::GetGraphics_Cross(CFX_ByteString& sPathData,
2313                                    CFX_PathData& path,
2314                                    const CPDF_Rect& crBBox,
2315                                    const PWL_PATH_TYPE type) {
2316   FX_FLOAT fWidth = crBBox.right - crBBox.left;
2317   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
2318   CPWL_Point center_point(crBBox.left + fWidth / 2,
2319                           crBBox.bottom + fHeight / 2);
2320 
2321   CPWL_PathData PathArray[] = {
2322       CPWL_PathData(
2323           CPWL_Point(center_point.x, center_point.y + fHeight / 10.0f),
2324           PWLPT_MOVETO),
2325       CPWL_PathData(
2326           CPWL_Point(center_point.x + fWidth * 0.3f,
2327                      center_point.y + fHeight / 10.0f + fWidth * 0.3f),
2328           PWLPT_LINETO),
2329       CPWL_PathData(CPWL_Point(center_point.x + fWidth / 10.0f + fWidth * 0.3f,
2330                                center_point.y + fHeight * 0.3f),
2331                     PWLPT_LINETO),
2332       CPWL_PathData(CPWL_Point(center_point.x + fWidth / 10.0f, center_point.y),
2333                     PWLPT_LINETO),
2334       CPWL_PathData(CPWL_Point(center_point.x + fWidth / 10.0f + fWidth * 0.3f,
2335                                center_point.y - fHeight * 0.3f),
2336                     PWLPT_LINETO),
2337       CPWL_PathData(
2338           CPWL_Point(center_point.x + fWidth * 0.3f,
2339                      center_point.y - fHeight / 10.0f - fHeight * 0.3f),
2340           PWLPT_LINETO),
2341       CPWL_PathData(
2342           CPWL_Point(center_point.x, center_point.y - fHeight / 10.0f),
2343           PWLPT_LINETO),
2344       CPWL_PathData(CPWL_Point(center_point.x - fWidth * 0.3f,
2345                                center_point.y - fHeight / 10 - fHeight * 0.3f),
2346                     PWLPT_LINETO),
2347       CPWL_PathData(CPWL_Point(center_point.x - fWidth / 10.0f - fWidth * 0.3f,
2348                                center_point.y - fHeight * 0.3f),
2349                     PWLPT_LINETO),
2350       CPWL_PathData(CPWL_Point(center_point.x - fWidth / 10, center_point.y),
2351                     PWLPT_LINETO),
2352       CPWL_PathData(CPWL_Point(center_point.x - fWidth / 10 - fWidth * 0.3f,
2353                                center_point.y + fHeight * 0.3f),
2354                     PWLPT_LINETO),
2355       CPWL_PathData(
2356           CPWL_Point(center_point.x - fWidth * 0.3f,
2357                      center_point.y + fHeight / 10.0f + fHeight * 0.3f),
2358           PWLPT_LINETO),
2359       CPWL_PathData(
2360           CPWL_Point(center_point.x, center_point.y + fHeight / 10.0f),
2361           PWLPT_LINETO)};
2362 
2363   if (type == PWLPT_STREAM)
2364     sPathData = GetAppStreamFromArray(PathArray, 13);
2365   else
2366     GetPathDataFromArray(path, PathArray, 13);
2367 }
2368 
GetGraphics_Help(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)2369 void CPWL_Utils::GetGraphics_Help(CFX_ByteString& sPathData,
2370                                   CFX_PathData& path,
2371                                   const CPDF_Rect& crBBox,
2372                                   const PWL_PATH_TYPE type) {
2373   FX_FLOAT fWidth = crBBox.right - crBBox.left;
2374   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
2375 
2376   CPWL_PathData PathArray[] = {
2377       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 60.0f,
2378                                crBBox.bottom + fHeight / 2.0f),
2379                     PWLPT_MOVETO),
2380       CPWL_PathData(
2381           CPWL_Point(crBBox.left + fWidth / 60.0f,
2382                      crBBox.bottom + fHeight / 2.0f +
2383                          PWL_BEZIER * (fHeight / 60.0f - fHeight / 2.0f)),
2384           PWLPT_BEZIERTO),
2385       CPWL_PathData(
2386           CPWL_Point(crBBox.left + fWidth / 2.0f -
2387                          PWL_BEZIER * (fWidth / 2.0f - fWidth / 60.0f),
2388                      crBBox.bottom + fHeight / 60.0f),
2389           PWLPT_BEZIERTO),
2390       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 2.0f,
2391                                crBBox.bottom + fHeight / 60.0f),
2392                     PWLPT_BEZIERTO),
2393       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 2.0f +
2394                                    PWL_BEZIER * fWidth * 29 / 60.0f,
2395                                crBBox.bottom + fHeight / 60.0f),
2396                     PWLPT_BEZIERTO),
2397       CPWL_PathData(
2398           CPWL_Point(crBBox.right - fWidth / 60.0f,
2399                      crBBox.bottom + fHeight / 2.0f +
2400                          PWL_BEZIER * (fHeight / 60.0f - fHeight / 2.0f)),
2401           PWLPT_BEZIERTO),
2402       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 60.0f,
2403                                crBBox.bottom + fHeight / 2.0f),
2404                     PWLPT_BEZIERTO),
2405       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 60.0f,
2406                                crBBox.bottom + fHeight / 2.0f +
2407                                    PWL_BEZIER * fHeight * 29 / 60.0f),
2408                     PWLPT_BEZIERTO),
2409       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 2.0f +
2410                                    PWL_BEZIER * fWidth * 29 / 60.0f,
2411                                crBBox.top - fHeight / 60.0f),
2412                     PWLPT_BEZIERTO),
2413       CPWL_PathData(
2414           CPWL_Point(crBBox.left + fWidth / 2.0f, crBBox.top - fHeight / 60.0f),
2415           PWLPT_BEZIERTO),
2416       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 2.0f -
2417                                    PWL_BEZIER * fWidth * 29 / 60.0f,
2418                                crBBox.top - fHeight / 60.0f),
2419                     PWLPT_BEZIERTO),
2420       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 60.0f,
2421                                crBBox.bottom + fHeight / 2.0f +
2422                                    PWL_BEZIER * fHeight * 29 / 60.0f),
2423                     PWLPT_BEZIERTO),
2424       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 60.0f,
2425                                crBBox.bottom + fHeight / 2.0f),
2426                     PWLPT_BEZIERTO),
2427       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.27f,
2428                                crBBox.top - fHeight * 0.36f),
2429                     PWLPT_MOVETO),
2430       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.27f,
2431                                crBBox.top - fHeight * 0.36f +
2432                                    PWL_BEZIER * fHeight * 0.23f),
2433                     PWLPT_BEZIERTO),
2434       CPWL_PathData(
2435           CPWL_Point(crBBox.left + fWidth * 0.5f - PWL_BEZIER * fWidth * 0.23f,
2436                      crBBox.bottom + fHeight * 0.87f),
2437           PWLPT_BEZIERTO),
2438       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.5f,
2439                                crBBox.bottom + fHeight * 0.87f),
2440                     PWLPT_BEZIERTO),
2441       CPWL_PathData(
2442           CPWL_Point(crBBox.left + fWidth * 0.5f + PWL_BEZIER * fWidth * 0.23f,
2443                      crBBox.bottom + fHeight * 0.87f),
2444           PWLPT_BEZIERTO),
2445       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.27f,
2446                                crBBox.top - fHeight * 0.36f +
2447                                    PWL_BEZIER * fHeight * 0.23f),
2448                     PWLPT_BEZIERTO),
2449       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.27f,
2450                                crBBox.top - fHeight * 0.36f),
2451                     PWLPT_BEZIERTO),
2452       CPWL_PathData(
2453           CPWL_Point(crBBox.right - fWidth * 0.27f - fWidth * 0.08f * 0.2f,
2454                      crBBox.top - fHeight * 0.36f - fHeight * 0.15f * 0.7f),
2455           PWLPT_BEZIERTO),
2456       CPWL_PathData(
2457           CPWL_Point(crBBox.right - fWidth * 0.35f + fWidth * 0.08f * 0.2f,
2458                      crBBox.top - fHeight * 0.51f + fHeight * 0.15f * 0.2f),
2459           PWLPT_BEZIERTO),
2460       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.35f,
2461                                crBBox.top - fHeight * 0.51f),
2462                     PWLPT_BEZIERTO),
2463       CPWL_PathData(
2464           CPWL_Point(crBBox.right - fWidth * 0.35f - fWidth * 0.1f * 0.5f,
2465                      crBBox.top - fHeight * 0.51f - fHeight * 0.15f * 0.3f),
2466           PWLPT_BEZIERTO),
2467       CPWL_PathData(
2468           CPWL_Point(crBBox.right - fWidth * 0.45f - fWidth * 0.1f * 0.5f,
2469                      crBBox.top - fHeight * 0.68f + fHeight * 0.15f * 0.5f),
2470           PWLPT_BEZIERTO),
2471       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.45f,
2472                                crBBox.top - fHeight * 0.68f),
2473                     PWLPT_BEZIERTO),
2474       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.45f,
2475                                crBBox.bottom + fHeight * 0.30f),
2476                     PWLPT_LINETO),
2477       CPWL_PathData(
2478           CPWL_Point(crBBox.right - fWidth * 0.45f,
2479                      crBBox.bottom + fHeight * 0.30f - fWidth * 0.1f * 0.7f),
2480           PWLPT_BEZIERTO),
2481       CPWL_PathData(
2482           CPWL_Point(crBBox.right - fWidth * 0.55f,
2483                      crBBox.bottom + fHeight * 0.30f - fWidth * 0.1f * 0.7f),
2484           PWLPT_BEZIERTO),
2485       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.55f,
2486                                crBBox.bottom + fHeight * 0.30f),
2487                     PWLPT_BEZIERTO),
2488       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.55f,
2489                                crBBox.top - fHeight * 0.66f),
2490                     PWLPT_LINETO),
2491       CPWL_PathData(
2492           CPWL_Point(crBBox.right - fWidth * 0.55f - fWidth * 0.1f * 0.05f,
2493                      crBBox.top - fHeight * 0.66f + fHeight * 0.18f * 0.5f),
2494           PWLPT_BEZIERTO),
2495       CPWL_PathData(
2496           CPWL_Point(crBBox.right - fWidth * 0.45f - fWidth * 0.1f * 0.05f,
2497                      crBBox.top - fHeight * 0.48f - fHeight * 0.18f * 0.3f),
2498           PWLPT_BEZIERTO),
2499       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.45f,
2500                                crBBox.top - fHeight * 0.48f),
2501                     PWLPT_BEZIERTO),
2502       CPWL_PathData(
2503           CPWL_Point(crBBox.right - fWidth * 0.45f + fWidth * 0.08f * 0.2f,
2504                      crBBox.top - fHeight * 0.48f + fHeight * 0.18f * 0.2f),
2505           PWLPT_BEZIERTO),
2506       CPWL_PathData(
2507           CPWL_Point(crBBox.right - fWidth * 0.37f - fWidth * 0.08f * 0.2f,
2508                      crBBox.top - fHeight * 0.36f - fHeight * 0.18f * 0.7f),
2509           PWLPT_BEZIERTO),
2510       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.37f,
2511                                crBBox.top - fHeight * 0.36f),
2512                     PWLPT_BEZIERTO),
2513       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.37f,
2514                                crBBox.top - fHeight * 0.36f +
2515                                    PWL_BEZIER * fHeight * 0.13f),
2516                     PWLPT_BEZIERTO),
2517       CPWL_PathData(
2518           CPWL_Point(crBBox.left + fWidth * 0.5f + PWL_BEZIER * fWidth * 0.13f,
2519                      crBBox.bottom + fHeight * 0.77f),
2520           PWLPT_BEZIERTO),
2521       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.5f,
2522                                crBBox.bottom + fHeight * 0.77f),
2523                     PWLPT_BEZIERTO),
2524       CPWL_PathData(
2525           CPWL_Point(crBBox.left + fWidth * 0.5f - PWL_BEZIER * fWidth * 0.13f,
2526                      crBBox.bottom + fHeight * 0.77f),
2527           PWLPT_BEZIERTO),
2528       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.37f,
2529                                crBBox.top - fHeight * 0.36f +
2530                                    PWL_BEZIER * fHeight * 0.13f),
2531                     PWLPT_BEZIERTO),
2532       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.37f,
2533                                crBBox.top - fHeight * 0.36f),
2534                     PWLPT_BEZIERTO),
2535       CPWL_PathData(
2536           CPWL_Point(crBBox.left + fWidth * 0.37f,
2537                      crBBox.top - fHeight * 0.36f - fWidth * 0.1f * 0.6f),
2538           PWLPT_BEZIERTO),
2539       CPWL_PathData(
2540           CPWL_Point(crBBox.left + fWidth * 0.27f,
2541                      crBBox.top - fHeight * 0.36f - fWidth * 0.1f * 0.6f),
2542           PWLPT_BEZIERTO),
2543       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.27f,
2544                                crBBox.top - fHeight * 0.36f),
2545                     PWLPT_BEZIERTO),
2546       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.56f,
2547                                crBBox.bottom + fHeight * 0.13f),
2548                     PWLPT_MOVETO),
2549       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.56f,
2550                                crBBox.bottom + fHeight * 0.13f +
2551                                    PWL_BEZIER * fHeight * 0.055f),
2552                     PWLPT_BEZIERTO),
2553       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.505f -
2554                                    PWL_BEZIER * fWidth * 0.095f,
2555                                crBBox.bottom + fHeight * 0.185f),
2556                     PWLPT_BEZIERTO),
2557       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.505f,
2558                                crBBox.bottom + fHeight * 0.185f),
2559                     PWLPT_BEZIERTO),
2560       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.505f +
2561                                    PWL_BEZIER * fWidth * 0.065f,
2562                                crBBox.bottom + fHeight * 0.185f),
2563                     PWLPT_BEZIERTO),
2564       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.44f,
2565                                crBBox.bottom + fHeight * 0.13f +
2566                                    PWL_BEZIER * fHeight * 0.055f),
2567                     PWLPT_BEZIERTO),
2568       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.44f,
2569                                crBBox.bottom + fHeight * 0.13f),
2570                     PWLPT_BEZIERTO),
2571       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.44f,
2572                                crBBox.bottom + fHeight * 0.13f -
2573                                    PWL_BEZIER * fHeight * 0.055f),
2574                     PWLPT_BEZIERTO),
2575       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.505f +
2576                                    PWL_BEZIER * fWidth * 0.065f,
2577                                crBBox.bottom + fHeight * 0.075f),
2578                     PWLPT_BEZIERTO),
2579       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.505f,
2580                                crBBox.bottom + fHeight * 0.075f),
2581                     PWLPT_BEZIERTO),
2582       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.505f -
2583                                    PWL_BEZIER * fWidth * 0.065f,
2584                                crBBox.bottom + fHeight * 0.075f),
2585                     PWLPT_BEZIERTO),
2586       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.56f,
2587                                crBBox.bottom + fHeight * 0.13f -
2588                                    PWL_BEZIER * fHeight * 0.055f),
2589                     PWLPT_BEZIERTO),
2590       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.56f,
2591                                crBBox.bottom + fHeight * 0.13f),
2592                     PWLPT_BEZIERTO)};
2593 
2594   if (type == PWLPT_STREAM)
2595     sPathData = GetAppStreamFromArray(PathArray, 59);
2596   else
2597     GetPathDataFromArray(path, PathArray, 59);
2598 }
2599 
GetGraphics_InsertText(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)2600 void CPWL_Utils::GetGraphics_InsertText(CFX_ByteString& sPathData,
2601                                         CFX_PathData& path,
2602                                         const CPDF_Rect& crBBox,
2603                                         const PWL_PATH_TYPE type) {
2604   FX_FLOAT fWidth = crBBox.right - crBBox.left;
2605   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
2606 
2607   CPWL_PathData PathArray[] = {
2608       CPWL_PathData(
2609           CPWL_Point(crBBox.left + fWidth / 10, crBBox.bottom + fHeight / 10),
2610           PWLPT_MOVETO),
2611       CPWL_PathData(
2612           CPWL_Point(crBBox.left + fWidth / 2, crBBox.top - fHeight * 2 / 15),
2613           PWLPT_LINETO),
2614       CPWL_PathData(
2615           CPWL_Point(crBBox.right - fWidth / 10, crBBox.bottom + fHeight / 10),
2616           PWLPT_LINETO),
2617       CPWL_PathData(
2618           CPWL_Point(crBBox.left + fWidth / 10, crBBox.bottom + fHeight / 10),
2619           PWLPT_LINETO)};
2620 
2621   if (type == PWLPT_STREAM)
2622     sPathData = GetAppStreamFromArray(PathArray, 4);
2623   else
2624     GetPathDataFromArray(path, PathArray, 4);
2625 }
2626 
GetGraphics_Key(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)2627 void CPWL_Utils::GetGraphics_Key(CFX_ByteString& sPathData,
2628                                  CFX_PathData& path,
2629                                  const CPDF_Rect& crBBox,
2630                                  const PWL_PATH_TYPE type) {
2631   FX_FLOAT fWidth = crBBox.right - crBBox.left;
2632   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
2633   FX_FLOAT k = -fHeight / fWidth;
2634   CPWL_Point tail;
2635   CPWL_Point CicleCenter;
2636   tail.x = crBBox.left + fWidth * 0.9f;
2637   tail.y = k * (tail.x - crBBox.right) + crBBox.bottom;
2638   CicleCenter.x = crBBox.left + fWidth * 0.15f;
2639   CicleCenter.y = k * (CicleCenter.x - crBBox.right) + crBBox.bottom;
2640 
2641   CPWL_PathData PathArray[] = {
2642       CPWL_PathData(
2643           CPWL_Point(tail.x + fWidth / 30.0f, -fWidth / 30.0f / k + tail.y),
2644           PWLPT_MOVETO),
2645       CPWL_PathData(CPWL_Point(tail.x + fWidth / 30.0f - fWidth * 0.18f,
2646                                -k * fWidth * 0.18f - fWidth / 30 / k + tail.y),
2647                     PWLPT_LINETO),
2648       CPWL_PathData(
2649           CPWL_Point(tail.x + fWidth / 30 - fWidth * 0.18f + fWidth * 0.07f,
2650                      -fWidth * 0.07f / k - k * fWidth * 0.18f -
2651                          fWidth / 30 / k + tail.y),
2652           PWLPT_LINETO),
2653       CPWL_PathData(
2654           CPWL_Point(tail.x + fWidth / 30 - fWidth * 0.18f - fWidth / 20 +
2655                          fWidth * 0.07f,
2656                      -fWidth * 0.07f / k - k * fWidth / 20 -
2657                          k * fWidth * 0.18f - fWidth / 30 / k + tail.y),
2658           PWLPT_LINETO),
2659       CPWL_PathData(
2660           CPWL_Point(
2661               tail.x + fWidth / 30 - fWidth * 0.18f - fWidth / 20,
2662               -k * fWidth / 20 - k * fWidth * 0.18f - fWidth / 30 / k + tail.y),
2663           PWLPT_LINETO),
2664       CPWL_PathData(
2665           CPWL_Point(
2666               tail.x + fWidth / 30 - fWidth * 0.18f - fWidth / 20 - fWidth / 15,
2667               -k * fWidth / 15 - k * fWidth / 20 - k * fWidth * 0.18f -
2668                   fWidth / 30 / k + tail.y),
2669           PWLPT_LINETO),
2670       CPWL_PathData(
2671           CPWL_Point(tail.x + fWidth / 30 - fWidth * 0.18f - fWidth / 20 -
2672                          fWidth / 15 + fWidth * 0.07f,
2673                      -fWidth * 0.07f / k - k * fWidth / 15 - k * fWidth / 20 -
2674                          k * fWidth * 0.18f - fWidth / 30 / k + tail.y),
2675           PWLPT_LINETO),
2676       CPWL_PathData(
2677           CPWL_Point(tail.x + fWidth / 30 - fWidth * 0.18f - fWidth / 20 -
2678                          fWidth / 15 - fWidth / 20 + fWidth * 0.07f,
2679                      -fWidth * 0.07f / k + -k * fWidth / 20 + -k * fWidth / 15 -
2680                          k * fWidth / 20 - k * fWidth * 0.18f -
2681                          fWidth / 30 / k + tail.y),
2682           PWLPT_LINETO),
2683       CPWL_PathData(
2684           CPWL_Point(tail.x + fWidth / 30 - fWidth * 0.18f - fWidth / 20 -
2685                          fWidth / 15 - fWidth / 20,
2686                      -k * fWidth / 20 + -k * fWidth / 15 - k * fWidth / 20 -
2687                          k * fWidth * 0.18f - fWidth / 30 / k + tail.y),
2688           PWLPT_LINETO),
2689       CPWL_PathData(CPWL_Point(tail.x + fWidth / 30 - fWidth * 0.45f,
2690                                -k * fWidth * 0.45f - fWidth / 30 / k + tail.y),
2691                     PWLPT_LINETO),
2692       CPWL_PathData(
2693           CPWL_Point(tail.x + fWidth / 30 - fWidth * 0.45f + fWidth * 0.2f,
2694                      -fWidth * 0.4f / k - k * fWidth * 0.45f - fWidth / 30 / k +
2695                          tail.y),
2696           PWLPT_BEZIERTO),
2697       CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth * 0.2f,
2698                                -fWidth * 0.1f / k + CicleCenter.y),
2699                     PWLPT_BEZIERTO),
2700       CPWL_PathData(CPWL_Point(CicleCenter.x, CicleCenter.y), PWLPT_BEZIERTO),
2701       CPWL_PathData(CPWL_Point(CicleCenter.x - fWidth / 60.0f,
2702                                -k * fWidth / 60 + CicleCenter.y),
2703                     PWLPT_BEZIERTO),
2704       CPWL_PathData(CPWL_Point(CicleCenter.x - fWidth / 60,
2705                                -k * fWidth / 60 + CicleCenter.y),
2706                     PWLPT_BEZIERTO),
2707       CPWL_PathData(CPWL_Point(CicleCenter.x, CicleCenter.y), PWLPT_BEZIERTO),
2708       CPWL_PathData(
2709           CPWL_Point(CicleCenter.x - fWidth * 0.22f,
2710                      fWidth * 0.35f / k + CicleCenter.y - fHeight * 0.05f),
2711           PWLPT_BEZIERTO),
2712       CPWL_PathData(
2713           CPWL_Point(tail.x - fWidth / 30 - fWidth * 0.45f - fWidth * 0.18f,
2714                      fWidth * 0.05f / k - k * fWidth * 0.45f + fWidth / 30 / k +
2715                          tail.y - fHeight * 0.05f),
2716           PWLPT_BEZIERTO),
2717       CPWL_PathData(
2718           CPWL_Point(tail.x - fWidth / 30.0f - fWidth * 0.45f,
2719                      -k * fWidth * 0.45f + fWidth / 30.0f / k + tail.y),
2720           PWLPT_BEZIERTO),
2721       CPWL_PathData(
2722           CPWL_Point(tail.x - fWidth / 30.0f, fWidth / 30.0f / k + tail.y),
2723           PWLPT_LINETO),
2724       CPWL_PathData(CPWL_Point(tail.x + fWidth / 30, -fWidth / 30 / k + tail.y),
2725                     PWLPT_LINETO),
2726       CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth * 0.08f,
2727                                k * fWidth * 0.08f + CicleCenter.y),
2728                     PWLPT_MOVETO),
2729       CPWL_PathData(
2730           CPWL_Point(CicleCenter.x + fWidth * 0.08f + fWidth * 0.1f,
2731                      -fWidth * 0.1f / k + k * fWidth * 0.08f + CicleCenter.y),
2732           PWLPT_BEZIERTO),
2733       CPWL_PathData(
2734           CPWL_Point(CicleCenter.x + fWidth * 0.22f + fWidth * 0.1f,
2735                      k * fWidth * 0.22f + CicleCenter.y - fWidth * 0.1f / k),
2736           PWLPT_BEZIERTO),
2737       CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth * 0.22f,
2738                                k * fWidth * 0.22f + CicleCenter.y),
2739                     PWLPT_BEZIERTO),
2740       CPWL_PathData(
2741           CPWL_Point(CicleCenter.x + fWidth * 0.22f - fWidth * 0.1f,
2742                      fWidth * 0.1f / k + k * fWidth * 0.22f + CicleCenter.y),
2743           PWLPT_BEZIERTO),
2744       CPWL_PathData(
2745           CPWL_Point(CicleCenter.x + fWidth * 0.08f - fWidth * 0.1f,
2746                      fWidth * 0.1f / k + k * fWidth * 0.08f + CicleCenter.y),
2747           PWLPT_BEZIERTO),
2748       CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth * 0.08f,
2749                                k * fWidth * 0.08f + CicleCenter.y),
2750                     PWLPT_BEZIERTO)};
2751 
2752   if (type == PWLPT_STREAM)
2753     sPathData = GetAppStreamFromArray(PathArray, 28);
2754   else
2755     GetPathDataFromArray(path, PathArray, 28);
2756 }
2757 
GetGraphics_NewParagraph(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)2758 void CPWL_Utils::GetGraphics_NewParagraph(CFX_ByteString& sPathData,
2759                                           CFX_PathData& path,
2760                                           const CPDF_Rect& crBBox,
2761                                           const PWL_PATH_TYPE type) {
2762   FX_FLOAT fWidth = crBBox.right - crBBox.left;
2763   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
2764 
2765   CPWL_PathData PathArray[] = {
2766       CPWL_PathData(
2767           CPWL_Point(crBBox.left + fWidth / 2.0f, crBBox.top - fHeight / 20.0f),
2768           PWLPT_MOVETO),
2769       CPWL_PathData(
2770           CPWL_Point(crBBox.left + fWidth / 10.0f, crBBox.top - fHeight / 2.0f),
2771           PWLPT_LINETO),
2772       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 10.0f,
2773                                crBBox.top - fHeight / 2.0f),
2774                     PWLPT_LINETO),
2775       CPWL_PathData(
2776           CPWL_Point(crBBox.left + fWidth / 2.0f, crBBox.top - fHeight / 20.0f),
2777           PWLPT_LINETO),
2778       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.12f,
2779                                crBBox.top - fHeight * 17 / 30.0f),
2780                     PWLPT_MOVETO),
2781       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.12f,
2782                                crBBox.bottom + fHeight / 10.0f),
2783                     PWLPT_LINETO),
2784       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.22f,
2785                                crBBox.bottom + fHeight / 10.0f),
2786                     PWLPT_LINETO),
2787       CPWL_PathData(
2788           CPWL_Point(crBBox.left + fWidth * 0.22f,
2789                      crBBox.top - fHeight * 17 / 30.0f - fWidth * 0.14f),
2790           PWLPT_LINETO),
2791       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.38f,
2792                                crBBox.bottom + fHeight / 10.0f),
2793                     PWLPT_LINETO),
2794       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.48f,
2795                                crBBox.bottom + fHeight / 10.0f),
2796                     PWLPT_LINETO),
2797       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.48f,
2798                                crBBox.top - fHeight * 17 / 30.0f),
2799                     PWLPT_LINETO),
2800       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.38f,
2801                                crBBox.top - fHeight * 17 / 30.0f),
2802                     PWLPT_LINETO),
2803       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.38f,
2804                                crBBox.bottom + fWidth * 0.24f),
2805                     PWLPT_LINETO),
2806       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.22f,
2807                                crBBox.top - fHeight * 17 / 30.0f),
2808                     PWLPT_LINETO),
2809       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.12f,
2810                                crBBox.top - fHeight * 17 / 30.0f),
2811                     PWLPT_LINETO),
2812       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.6f,
2813                                crBBox.bottom + fHeight / 10.0f),
2814                     PWLPT_MOVETO),
2815       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.7f,
2816                                crBBox.bottom + fHeight / 10.0f),
2817                     PWLPT_LINETO),
2818       CPWL_PathData(
2819           CPWL_Point(crBBox.left + fWidth * 0.7f,
2820                      crBBox.bottom + fHeight / 10.0f + fHeight / 7.0f),
2821           PWLPT_LINETO),
2822       CPWL_PathData(
2823           CPWL_Point(crBBox.left + fWidth * 0.97f,
2824                      crBBox.bottom + fHeight / 10.0f + fHeight / 7.0f),
2825           PWLPT_BEZIERTO),
2826       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.97f,
2827                                crBBox.top - fHeight * 17 / 30.0f),
2828                     PWLPT_BEZIERTO),
2829       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.7f,
2830                                crBBox.top - fHeight * 17 / 30.0f),
2831                     PWLPT_BEZIERTO),
2832       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.6f,
2833                                crBBox.top - fHeight * 17 / 30.0f),
2834                     PWLPT_LINETO),
2835       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.6f,
2836                                crBBox.bottom + fHeight / 10.0f),
2837                     PWLPT_LINETO),
2838       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.7f,
2839                                crBBox.bottom + fHeight / 7 + fHeight * 0.18f),
2840                     PWLPT_MOVETO),
2841       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.85f,
2842                                crBBox.bottom + fHeight / 7 + fHeight * 0.18f),
2843                     PWLPT_BEZIERTO),
2844       CPWL_PathData(
2845           CPWL_Point(crBBox.left + fWidth * 0.85f,
2846                      crBBox.top - fHeight * 17 / 30.0f - fHeight * 0.08f),
2847           PWLPT_BEZIERTO),
2848       CPWL_PathData(
2849           CPWL_Point(crBBox.left + fWidth * 0.7f,
2850                      crBBox.top - fHeight * 17 / 30.0f - fHeight * 0.08f),
2851           PWLPT_BEZIERTO),
2852       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.7f,
2853                                crBBox.bottom + fHeight / 7 + fHeight * 0.18f),
2854                     PWLPT_LINETO)};
2855 
2856   if (type == PWLPT_STREAM)
2857     sPathData = GetAppStreamFromArray(PathArray, 28);
2858   else
2859     GetPathDataFromArray(path, PathArray, 28);
2860 }
2861 
GetGraphics_TextNote(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)2862 void CPWL_Utils::GetGraphics_TextNote(CFX_ByteString& sPathData,
2863                                       CFX_PathData& path,
2864                                       const CPDF_Rect& crBBox,
2865                                       const PWL_PATH_TYPE type) {
2866   FX_FLOAT fWidth = crBBox.right - crBBox.left;
2867   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
2868 
2869   CPWL_PathData PathArray[] = {
2870       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 3 / 10.0f,
2871                                crBBox.bottom + fHeight / 15.0f),
2872                     PWLPT_MOVETO),
2873       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 7 / 10.0f,
2874                                crBBox.bottom + fHeight * 4 / 15.0f),
2875                     PWLPT_LINETO),
2876       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 10.0f,
2877                                crBBox.bottom + fHeight * 4 / 15.0f),
2878                     PWLPT_LINETO),
2879       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 10.0f,
2880                                crBBox.top - fHeight / 15.0f),
2881                     PWLPT_LINETO),
2882       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 10.0f,
2883                                crBBox.top - fHeight / 15.0f),
2884                     PWLPT_LINETO),
2885       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 10.0f,
2886                                crBBox.bottom + fHeight / 15.0f),
2887                     PWLPT_LINETO),
2888       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 3 / 10.0f,
2889                                crBBox.bottom + fHeight / 15.0f),
2890                     PWLPT_LINETO),
2891       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 10.0f,
2892                                crBBox.bottom + fHeight * 4 / 15.0f),
2893                     PWLPT_LINETO),
2894       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 3 / 10.0f,
2895                                crBBox.bottom + fHeight / 15.0f),
2896                     PWLPT_LINETO),
2897       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 3 / 10.0f,
2898                                crBBox.bottom + fHeight * 4 / 15.0f),
2899                     PWLPT_LINETO),
2900       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 10.0f,
2901                                crBBox.bottom + fHeight * 4 / 15.0f),
2902                     PWLPT_LINETO),
2903       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 5.0f,
2904                                crBBox.top - fHeight * 4 / 15.0f),
2905                     PWLPT_MOVETO),
2906       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 5.0f,
2907                                crBBox.top - fHeight * 4 / 15.0f),
2908                     PWLPT_LINETO),
2909       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 5.0f,
2910                                crBBox.top - fHeight * 7 / 15.0f),
2911                     PWLPT_MOVETO),
2912       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 5.0f,
2913                                crBBox.top - fHeight * 7 / 15.0f),
2914                     PWLPT_LINETO),
2915       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 5.0f,
2916                                crBBox.top - fHeight * 10 / 15.0f),
2917                     PWLPT_MOVETO),
2918       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 3 / 10.0f,
2919                                crBBox.top - fHeight * 10 / 15.0f),
2920                     PWLPT_LINETO)};
2921 
2922   if (type == PWLPT_STREAM)
2923     sPathData = GetAppStreamFromArray(PathArray, 17);
2924   else
2925     GetPathDataFromArray(path, PathArray, 17);
2926 }
2927 
GetGraphics_Paragraph(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)2928 void CPWL_Utils::GetGraphics_Paragraph(CFX_ByteString& sPathData,
2929                                        CFX_PathData& path,
2930                                        const CPDF_Rect& crBBox,
2931                                        const PWL_PATH_TYPE type) {
2932   FX_FLOAT fWidth = crBBox.right - crBBox.left;
2933   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
2934 
2935   CPWL_PathData PathArray[] = {
2936       CPWL_PathData(
2937           CPWL_Point(crBBox.left + fWidth / 2.0f, crBBox.top - fHeight / 15.0f),
2938           PWLPT_MOVETO),
2939       CPWL_PathData(
2940           CPWL_Point(crBBox.left + fWidth * 0.7f, crBBox.top - fHeight / 15.0f),
2941           PWLPT_LINETO),
2942       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.7f,
2943                                crBBox.bottom + fHeight / 15.0f),
2944                     PWLPT_LINETO),
2945       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.634f,
2946                                crBBox.bottom + fHeight / 15.0f),
2947                     PWLPT_LINETO),
2948       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.634f,
2949                                crBBox.top - fHeight * 2 / 15.0f),
2950                     PWLPT_LINETO),
2951       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.566f,
2952                                crBBox.top - fHeight * 2 / 15.0f),
2953                     PWLPT_LINETO),
2954       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.566f,
2955                                crBBox.bottom + fHeight / 15.0f),
2956                     PWLPT_LINETO),
2957       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 2.0f,
2958                                crBBox.bottom + fHeight / 15.0f),
2959                     PWLPT_LINETO),
2960       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 2.0f,
2961                                crBBox.top - fHeight / 15.0f - fHeight * 0.4f),
2962                     PWLPT_LINETO),
2963       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.2f,
2964                                crBBox.top - fHeight / 15.0f - fHeight * 0.4f),
2965                     PWLPT_BEZIERTO),
2966       CPWL_PathData(
2967           CPWL_Point(crBBox.left + fWidth * 0.2f, crBBox.top - fHeight / 15.0f),
2968           PWLPT_BEZIERTO),
2969       CPWL_PathData(
2970           CPWL_Point(crBBox.left + fWidth / 2.0f, crBBox.top - fHeight / 15.0f),
2971           PWLPT_BEZIERTO)};
2972 
2973   if (type == PWLPT_STREAM)
2974     sPathData = GetAppStreamFromArray(PathArray, 12);
2975   else
2976     GetPathDataFromArray(path, PathArray, 12);
2977 }
2978 
GetGraphics_RightArrow(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)2979 void CPWL_Utils::GetGraphics_RightArrow(CFX_ByteString& sPathData,
2980                                         CFX_PathData& path,
2981                                         const CPDF_Rect& crBBox,
2982                                         const PWL_PATH_TYPE type) {
2983   FX_FLOAT fWidth = crBBox.right - crBBox.left;
2984   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
2985 
2986   CPWL_PathData PathArray[] = {
2987       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 15.0f,
2988                                crBBox.top - fHeight / 2.0f),
2989                     PWLPT_MOVETO),
2990       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 2.0f + fWidth / 8.0f,
2991                                crBBox.bottom + fHeight / 5.0f),
2992                     PWLPT_LINETO),
2993       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 2.0f,
2994                                crBBox.bottom + fHeight / 5.0f),
2995                     PWLPT_LINETO),
2996       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 15.0f - fWidth * 0.15f,
2997                                crBBox.top - fHeight / 2.0f - fWidth / 25.0f),
2998                     PWLPT_LINETO),
2999       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.1f,
3000                                crBBox.top - fHeight / 2.0f - fWidth / 25.0f),
3001                     PWLPT_LINETO),
3002       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.1f,
3003                                crBBox.top - fHeight / 2.0f + fWidth / 25.0f),
3004                     PWLPT_LINETO),
3005       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 15.0f - fWidth * 0.15f,
3006                                crBBox.top - fHeight / 2.0f + fWidth / 25.0f),
3007                     PWLPT_LINETO),
3008       CPWL_PathData(
3009           CPWL_Point(crBBox.left + fWidth / 2.0f, crBBox.top - fHeight / 5.0f),
3010           PWLPT_LINETO),
3011       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 2.0f + fWidth / 8.0f,
3012                                crBBox.top - fHeight / 5.0f),
3013                     PWLPT_LINETO),
3014       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 15.0f,
3015                                crBBox.top - fHeight / 2.0f),
3016                     PWLPT_LINETO)};
3017 
3018   if (type == PWLPT_STREAM)
3019     sPathData = GetAppStreamFromArray(PathArray, 10);
3020   else
3021     GetPathDataFromArray(path, PathArray, 10);
3022 }
3023 
GetGraphics_RightPointer(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)3024 void CPWL_Utils::GetGraphics_RightPointer(CFX_ByteString& sPathData,
3025                                           CFX_PathData& path,
3026                                           const CPDF_Rect& crBBox,
3027                                           const PWL_PATH_TYPE type) {
3028   FX_FLOAT fWidth = crBBox.right - crBBox.left;
3029   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
3030 
3031   CPWL_PathData PathArray[] = {
3032       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 30.0f,
3033                                crBBox.top - fHeight / 2.0f),
3034                     PWLPT_MOVETO),
3035       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 30.0f,
3036                                crBBox.bottom + fHeight / 6.0f),
3037                     PWLPT_LINETO),
3038       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 4 / 15.0f,
3039                                crBBox.top - fHeight / 2.0f),
3040                     PWLPT_LINETO),
3041       CPWL_PathData(
3042           CPWL_Point(crBBox.left + fWidth / 30.0f, crBBox.top - fHeight / 6.0f),
3043           PWLPT_LINETO),
3044       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 30.0f,
3045                                crBBox.top - fHeight / 2.0f),
3046                     PWLPT_LINETO)};
3047 
3048   if (type == PWLPT_STREAM)
3049     sPathData = GetAppStreamFromArray(PathArray, 5);
3050   else
3051     GetPathDataFromArray(path, PathArray, 5);
3052 }
3053 
GetGraphics_Star(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)3054 void CPWL_Utils::GetGraphics_Star(CFX_ByteString& sPathData,
3055                                   CFX_PathData& path,
3056                                   const CPDF_Rect& crBBox,
3057                                   const PWL_PATH_TYPE type) {
3058   FX_FLOAT fLongRadius =
3059       (crBBox.top - crBBox.bottom) / (1 + (FX_FLOAT)cos(PWL_PI / 5.0f));
3060   fLongRadius = fLongRadius * 0.7f;
3061   FX_FLOAT fShortRadius = fLongRadius * 0.55f;
3062   CPDF_Point ptCenter = CPDF_Point((crBBox.left + crBBox.right) / 2.0f,
3063                                    (crBBox.top + crBBox.bottom) / 2.0f);
3064 
3065   FX_FLOAT px1[5], py1[5];
3066   FX_FLOAT px2[5], py2[5];
3067 
3068   FX_FLOAT fAngel = PWL_PI / 10.0f;
3069 
3070   for (int32_t i = 0; i < 5; i++) {
3071     px1[i] = ptCenter.x + fLongRadius * (FX_FLOAT)cos(fAngel);
3072     py1[i] = ptCenter.y + fLongRadius * (FX_FLOAT)sin(fAngel);
3073 
3074     fAngel += PWL_PI * 2 / 5.0f;
3075   }
3076 
3077   fAngel = PWL_PI / 5.0f + PWL_PI / 10.0f;
3078 
3079   for (int32_t j = 0; j < 5; j++) {
3080     px2[j] = ptCenter.x + fShortRadius * (FX_FLOAT)cos(fAngel);
3081     py2[j] = ptCenter.y + fShortRadius * (FX_FLOAT)sin(fAngel);
3082 
3083     fAngel += PWL_PI * 2 / 5.0f;
3084   }
3085 
3086   CPWL_PathData PathArray[11];
3087   PathArray[0] = CPWL_PathData(CPWL_Point(px1[0], py1[0]), PWLPT_MOVETO);
3088   PathArray[1] = CPWL_PathData(CPWL_Point(px2[0], py2[0]), PWLPT_LINETO);
3089 
3090   for (int32_t k = 0; k < 4; k++) {
3091     PathArray[(k + 1) * 2] =
3092         CPWL_PathData(CPWL_Point(px1[k + 1], py1[k + 1]), PWLPT_LINETO);
3093     PathArray[(k + 1) * 2 + 1] =
3094         CPWL_PathData(CPWL_Point(px2[k + 1], py2[k + 1]), PWLPT_LINETO);
3095   }
3096 
3097   PathArray[10] = CPWL_PathData(CPWL_Point(px1[0], py1[0]), PWLPT_LINETO);
3098 
3099   if (type == PWLPT_STREAM)
3100     sPathData = GetAppStreamFromArray(PathArray, 11);
3101   else
3102     GetPathDataFromArray(path, PathArray, 11);
3103 }
3104 
GetGraphics_UpArrow(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)3105 void CPWL_Utils::GetGraphics_UpArrow(CFX_ByteString& sPathData,
3106                                      CFX_PathData& path,
3107                                      const CPDF_Rect& crBBox,
3108                                      const PWL_PATH_TYPE type) {
3109   FX_FLOAT fWidth = crBBox.right - crBBox.left;
3110   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
3111 
3112   CPWL_PathData PathArray[] = {
3113       CPWL_PathData(
3114           CPWL_Point(crBBox.left + fWidth / 2.0f, crBBox.top - fHeight / 15.0f),
3115           PWLPT_MOVETO),
3116       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 10.0f,
3117                                crBBox.top - fWidth * 3 / 5.0f),
3118                     PWLPT_LINETO),
3119       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.6f,
3120                                crBBox.top - fWidth * 3 / 5.0f),
3121                     PWLPT_LINETO),
3122       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.6f,
3123                                crBBox.bottom + fHeight / 15.0f),
3124                     PWLPT_LINETO),
3125       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.4f,
3126                                crBBox.bottom + fHeight / 15.0f),
3127                     PWLPT_LINETO),
3128       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.4f,
3129                                crBBox.top - fWidth * 3 / 5.0f),
3130                     PWLPT_LINETO),
3131       CPWL_PathData(
3132           CPWL_Point(crBBox.left + fWidth / 10, crBBox.top - fWidth * 3 / 5.0f),
3133           PWLPT_LINETO),
3134       CPWL_PathData(
3135           CPWL_Point(crBBox.left + fWidth / 2.0f, crBBox.top - fHeight / 15.0f),
3136           PWLPT_LINETO)};
3137 
3138   if (type == PWLPT_STREAM)
3139     sPathData = GetAppStreamFromArray(PathArray, 8);
3140   else
3141     GetPathDataFromArray(path, PathArray, 8);
3142 }
3143 
GetGraphics_UpLeftArrow(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)3144 void CPWL_Utils::GetGraphics_UpLeftArrow(CFX_ByteString& sPathData,
3145                                          CFX_PathData& path,
3146                                          const CPDF_Rect& crBBox,
3147                                          const PWL_PATH_TYPE type) {
3148   FX_FLOAT fWidth = crBBox.right - crBBox.left;
3149   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
3150   CPWL_Point leftup(crBBox.left, crBBox.top);
3151   CPWL_Point rightdown(crBBox.right, crBBox.bottom);
3152   FX_FLOAT k = -fHeight / fWidth;
3153   CPWL_Point tail;
3154   tail.x = crBBox.left + fWidth * 4 / 5.0f;
3155   tail.y = k * (tail.x - crBBox.right) + rightdown.y;
3156 
3157   CPWL_PathData PathArray[] = {
3158       CPWL_PathData(
3159           CPWL_Point(
3160               crBBox.left + fWidth / 20.0f,
3161               k * (crBBox.left + fWidth / 20.0f - rightdown.x) + rightdown.y),
3162           PWLPT_MOVETO),
3163       CPWL_PathData(CPWL_Point(fHeight * 17 / 60.0f / k + tail.x +
3164                                    fWidth / 10.0f + fWidth / 5.0f,
3165                                -fWidth / 5.0f / k + tail.y -
3166                                    fWidth / 10.0f / k + fHeight * 17 / 60.0f),
3167                     PWLPT_LINETO),
3168       CPWL_PathData(
3169           CPWL_Point(fHeight * 17 / 60.0f / k + tail.x + fWidth / 10.0f,
3170                      tail.y - fWidth / 10.0f / k + fHeight * 17 / 60.0f),
3171           PWLPT_LINETO),
3172       CPWL_PathData(
3173           CPWL_Point(tail.x + fWidth / 10.0f, tail.y - fWidth / 10.0f / k),
3174           PWLPT_LINETO),
3175       CPWL_PathData(
3176           CPWL_Point(tail.x - fWidth / 10.0f, tail.y + fWidth / 10.0f / k),
3177           PWLPT_LINETO),
3178       CPWL_PathData(
3179           CPWL_Point(fHeight * 17 / 60.0f / k + tail.x - fWidth / 10.0f,
3180                      tail.y + fWidth / 10.0f / k + fHeight * 17 / 60.0f),
3181           PWLPT_LINETO),
3182       CPWL_PathData(CPWL_Point(fHeight * 17 / 60.0f / k + tail.x -
3183                                    fWidth / 10.0f - fWidth / 5.0f,
3184                                fWidth / 5.0f / k + tail.y + fWidth / 10.0f / k +
3185                                    fHeight * 17 / 60.0f),
3186                     PWLPT_LINETO),
3187       CPWL_PathData(
3188           CPWL_Point(
3189               crBBox.left + fWidth / 20.0f,
3190               k * (crBBox.left + fWidth / 20.0f - rightdown.x) + rightdown.y),
3191           PWLPT_LINETO)};
3192 
3193   if (type == PWLPT_STREAM)
3194     sPathData = GetAppStreamFromArray(PathArray, 8);
3195   else
3196     GetPathDataFromArray(path, PathArray, 8);
3197 }
3198 
GetGraphics_Graph(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)3199 void CPWL_Utils::GetGraphics_Graph(CFX_ByteString& sPathData,
3200                                    CFX_PathData& path,
3201                                    const CPDF_Rect& crBBox,
3202                                    const PWL_PATH_TYPE type) {
3203   FX_FLOAT fWidth = crBBox.right - crBBox.left;
3204   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
3205 
3206   CPWL_PathData PathArray[] = {
3207       CPWL_PathData(
3208           CPWL_Point(crBBox.left + fWidth * 0.05f, crBBox.top - fWidth * 0.15f),
3209           PWLPT_MOVETO),
3210       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.25f,
3211                                crBBox.top - fHeight * 0.15f),
3212                     PWLPT_LINETO),
3213       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.275f,
3214                                crBBox.bottom + fHeight * 0.08f),
3215                     PWLPT_LINETO),
3216       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.05f,
3217                                crBBox.bottom + fHeight * 0.08f),
3218                     PWLPT_LINETO),
3219       CPWL_PathData(
3220           CPWL_Point(crBBox.left + fWidth * 0.05f, crBBox.top - fWidth * 0.15f),
3221           PWLPT_LINETO),
3222 
3223       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.275f,
3224                                crBBox.top - fWidth * 0.45f),
3225                     PWLPT_MOVETO),
3226       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.475f,
3227                                crBBox.top - fWidth * 0.45f),
3228                     PWLPT_LINETO),
3229       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.475f,
3230                                crBBox.bottom + fHeight * 0.08f),
3231                     PWLPT_LINETO),
3232       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.275f,
3233                                crBBox.bottom + fHeight * 0.08f),
3234                     PWLPT_LINETO),
3235       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.275f,
3236                                crBBox.top - fWidth * 0.45f),
3237                     PWLPT_LINETO),
3238 
3239       CPWL_PathData(
3240           CPWL_Point(crBBox.left + fWidth * 0.5f, crBBox.top - fHeight * 0.05f),
3241           PWLPT_MOVETO),
3242       CPWL_PathData(
3243           CPWL_Point(crBBox.left + fWidth * 0.7f, crBBox.top - fHeight * 0.05f),
3244           PWLPT_LINETO),
3245       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.7f,
3246                                crBBox.bottom + fHeight * 0.08f),
3247                     PWLPT_LINETO),
3248       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.5f,
3249                                crBBox.bottom + fHeight * 0.08f),
3250                     PWLPT_LINETO),
3251       CPWL_PathData(
3252           CPWL_Point(crBBox.left + fWidth * 0.5f, crBBox.top - fHeight * 0.05f),
3253           PWLPT_LINETO),
3254 
3255       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.725f,
3256                                crBBox.top - fWidth * 0.35f),
3257                     PWLPT_MOVETO),
3258       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.925f,
3259                                crBBox.top - fWidth * 0.35f),
3260                     PWLPT_LINETO),
3261       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.925f,
3262                                crBBox.bottom + fHeight * 0.08f),
3263                     PWLPT_LINETO),
3264       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.725f,
3265                                crBBox.bottom + fHeight * 0.08f),
3266                     PWLPT_LINETO),
3267       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.725f,
3268                                crBBox.top - fWidth * 0.35f),
3269                     PWLPT_LINETO)};
3270 
3271   if (type == PWLPT_STREAM)
3272     sPathData = GetAppStreamFromArray(PathArray, 20);
3273   else
3274     GetPathDataFromArray(path, PathArray, 20);
3275 }
3276 
GetGraphics_Paperclip(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)3277 void CPWL_Utils::GetGraphics_Paperclip(CFX_ByteString& sPathData,
3278                                        CFX_PathData& path,
3279                                        const CPDF_Rect& crBBox,
3280                                        const PWL_PATH_TYPE type) {
3281   FX_FLOAT fWidth = crBBox.right - crBBox.left;
3282   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
3283 
3284   CPWL_PathData PathArray[] = {
3285       CPWL_PathData(
3286           CPWL_Point(crBBox.left + fWidth / 60, crBBox.top - fHeight * 0.25f),
3287           PWLPT_MOVETO),
3288       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 60,
3289                                crBBox.bottom + fHeight * 0.25f),
3290                     PWLPT_LINETO),
3291       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 60,
3292                                crBBox.bottom + fHeight * 0.25f -
3293                                    fWidth * 57 / 60.0f * 0.35f),
3294                     PWLPT_BEZIERTO),
3295       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 30,
3296                                crBBox.bottom + fHeight * 0.25f -
3297                                    fWidth * 57 / 60.0f * 0.35f),
3298                     PWLPT_BEZIERTO),
3299       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 30,
3300                                crBBox.bottom + fHeight * 0.25f),
3301                     PWLPT_BEZIERTO),
3302 
3303       CPWL_PathData(
3304           CPWL_Point(crBBox.right - fWidth / 30, crBBox.top - fHeight * 0.33f),
3305           PWLPT_LINETO),
3306       CPWL_PathData(
3307           CPWL_Point(crBBox.right - fWidth / 30,
3308                      crBBox.top - fHeight * 0.33f + fHeight / 15 * 0.5f),
3309           PWLPT_BEZIERTO),
3310       CPWL_PathData(
3311           CPWL_Point(crBBox.right - fWidth / 30 - fWidth * 0.12f,
3312                      crBBox.top - fHeight * 0.33f + fHeight / 15 * 0.5f),
3313           PWLPT_BEZIERTO),
3314       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 30 - fWidth * 0.12f,
3315                                crBBox.top - fHeight * 0.33f),
3316                     PWLPT_BEZIERTO),
3317 
3318       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 30 - fWidth * 0.12f,
3319                                crBBox.bottom + fHeight * 0.2f),
3320                     PWLPT_LINETO),
3321       CPWL_PathData(
3322           CPWL_Point(crBBox.right - fWidth / 30 - fWidth * 0.12f,
3323                      crBBox.bottom + fHeight * 0.2f -
3324                          (fWidth * 57 / 60.0f - fWidth * 0.24f) * 0.25f),
3325           PWLPT_BEZIERTO),
3326       CPWL_PathData(
3327           CPWL_Point(crBBox.left + fWidth / 60 + fWidth * 0.12f,
3328                      crBBox.bottom + fHeight * 0.2f -
3329                          (fWidth * 57 / 60.0f - fWidth * 0.24f) * 0.25f),
3330           PWLPT_BEZIERTO),
3331       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 60 + fWidth * 0.12f,
3332                                crBBox.bottom + fHeight * 0.2f),
3333                     PWLPT_BEZIERTO),
3334 
3335       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 60 + fWidth * 0.12f,
3336                                crBBox.top - fHeight * 0.2f),
3337                     PWLPT_LINETO),
3338       CPWL_PathData(
3339           CPWL_Point(crBBox.left + fWidth / 60 + fWidth * 0.12f,
3340                      crBBox.top - fHeight * 0.2f +
3341                          (fWidth * 11 / 12.0f - fWidth * 0.36f) * 0.25f),
3342           PWLPT_BEZIERTO),
3343       CPWL_PathData(
3344           CPWL_Point(crBBox.right - fWidth / 15 - fWidth * 0.24f,
3345                      crBBox.top - fHeight * 0.2f +
3346                          (fWidth * 11 / 12.0f - fWidth * 0.36f) * 0.25f),
3347           PWLPT_BEZIERTO),
3348       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 15 - fWidth * 0.24f,
3349                                crBBox.top - fHeight * 0.2f),
3350                     PWLPT_BEZIERTO),
3351 
3352       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 15 - fWidth * 0.24f,
3353                                crBBox.bottom + fHeight * 0.25f),
3354                     PWLPT_LINETO),
3355       CPWL_PathData(
3356           CPWL_Point(crBBox.right - fWidth / 15 - fWidth * 0.24f,
3357                      crBBox.bottom + fHeight * 0.25f -
3358                          (fWidth * 14 / 15.0f - fWidth * 0.53f) * 0.25f),
3359           PWLPT_BEZIERTO),
3360       CPWL_PathData(
3361           CPWL_Point(crBBox.left + fWidth * 0.29f,
3362                      crBBox.bottom + fHeight * 0.25f -
3363                          (fWidth * 14 / 15.0f - fWidth * 0.53f) * 0.25f),
3364           PWLPT_BEZIERTO),
3365       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.29f,
3366                                crBBox.bottom + fHeight * 0.25f),
3367                     PWLPT_BEZIERTO),
3368 
3369       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.29f,
3370                                crBBox.top - fHeight * 0.33f),
3371                     PWLPT_LINETO),
3372       CPWL_PathData(
3373           CPWL_Point(crBBox.left + fWidth * 0.29f,
3374                      crBBox.top - fHeight * 0.33f + fWidth * 0.12f * 0.35f),
3375           PWLPT_BEZIERTO),
3376       CPWL_PathData(
3377           CPWL_Point(crBBox.left + fWidth * 0.17f,
3378                      crBBox.top - fHeight * 0.33f + fWidth * 0.12f * 0.35f),
3379           PWLPT_BEZIERTO),
3380       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.17f,
3381                                crBBox.top - fHeight * 0.33f),
3382                     PWLPT_BEZIERTO),
3383 
3384       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.17f,
3385                                crBBox.bottom + fHeight * 0.3f),
3386                     PWLPT_LINETO),
3387       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.17f,
3388                                crBBox.bottom + fHeight * 0.3f -
3389                                    fWidth * (14 / 15.0f - 0.29f) * 0.35f),
3390                     PWLPT_BEZIERTO),
3391       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 15 - fWidth * 0.12f,
3392                                crBBox.bottom + fHeight * 0.3f -
3393                                    fWidth * (14 / 15.0f - 0.29f) * 0.35f),
3394                     PWLPT_BEZIERTO),
3395       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 15 - fWidth * 0.12f,
3396                                crBBox.bottom + fHeight * 0.3f),
3397                     PWLPT_BEZIERTO),
3398 
3399       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 15 - fWidth * 0.12f,
3400                                crBBox.top - fHeight * 0.25f),
3401                     PWLPT_LINETO),
3402       CPWL_PathData(CPWL_Point(crBBox.right - fWidth / 15 - fWidth * 0.12f,
3403                                crBBox.top - fHeight * 0.25f +
3404                                    fWidth * 0.35f * (11 / 12.0f - 0.12f)),
3405                     PWLPT_BEZIERTO),
3406       CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 60,
3407                                crBBox.top - fHeight * 0.25f +
3408                                    fWidth * 0.35f * (11 / 12.0f - 0.12f)),
3409                     PWLPT_BEZIERTO),
3410       CPWL_PathData(
3411           CPWL_Point(crBBox.left + fWidth / 60, crBBox.top - fHeight * 0.25f),
3412           PWLPT_BEZIERTO)};
3413 
3414   if (type == PWLPT_STREAM)
3415     sPathData = GetAppStreamFromArray(PathArray, 33);
3416   else
3417     GetPathDataFromArray(path, PathArray, 33);
3418 }
3419 
GetGraphics_Attachment(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)3420 void CPWL_Utils::GetGraphics_Attachment(CFX_ByteString& sPathData,
3421                                         CFX_PathData& path,
3422                                         const CPDF_Rect& crBBox,
3423                                         const PWL_PATH_TYPE type) {
3424   FX_FLOAT fWidth = crBBox.right - crBBox.left;
3425   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
3426 
3427   CPWL_PathData PathArray[] = {
3428       CPWL_PathData(
3429           CPWL_Point(crBBox.left + fWidth * 0.25f, crBBox.top - fHeight * 0.1f),
3430           PWLPT_MOVETO),
3431       CPWL_PathData(
3432           CPWL_Point(crBBox.left + fWidth * 0.4f, crBBox.top - fHeight * 0.23f),
3433           PWLPT_LINETO),
3434       CPWL_PathData(
3435           CPWL_Point(crBBox.left + fWidth * 0.4f, crBBox.top - fHeight * 0.5f),
3436           PWLPT_LINETO),
3437       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.4f,
3438                                crBBox.top - fHeight * 0.5f + fWidth * 0.04f),
3439                     PWLPT_BEZIERTO),
3440       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.6f,
3441                                crBBox.top - fHeight * 0.5f + fWidth * 0.04f),
3442                     PWLPT_BEZIERTO),
3443       CPWL_PathData(
3444           CPWL_Point(crBBox.left + fWidth * 0.6f, crBBox.top - fHeight * 0.5f),
3445           PWLPT_BEZIERTO),
3446 
3447       CPWL_PathData(
3448           CPWL_Point(crBBox.left + fWidth * 0.6f, crBBox.top - fHeight * 0.23f),
3449           PWLPT_LINETO),
3450       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.25f,
3451                                crBBox.top - fHeight * 0.1f),
3452                     PWLPT_LINETO),
3453       CPWL_PathData(
3454           CPWL_Point(crBBox.left + fWidth * 0.25f, crBBox.top - fHeight * 0.1f),
3455           PWLPT_LINETO),
3456       CPWL_PathData(
3457           CPWL_Point(crBBox.left + fWidth * 0.4f, crBBox.top - fHeight * 0.23f),
3458           PWLPT_LINETO),
3459       CPWL_PathData(
3460           CPWL_Point(crBBox.left + fWidth * 0.6f, crBBox.top - fHeight * 0.23f),
3461           PWLPT_LINETO),
3462 
3463       CPWL_PathData(
3464           CPWL_Point(crBBox.left + fWidth * 0.4f, crBBox.top - fHeight * 0.5f),
3465           PWLPT_MOVETO),
3466       CPWL_PathData(
3467           CPWL_Point(crBBox.left + fWidth * 0.4f - fWidth * 0.25f * 0.4f,
3468                      crBBox.top - fHeight * 0.5f),
3469           PWLPT_BEZIERTO),
3470       CPWL_PathData(
3471           CPWL_Point(crBBox.left + fWidth * 0.15f,
3472                      crBBox.top - fHeight * 0.65f + fHeight * 0.15f * 0.4f),
3473           PWLPT_BEZIERTO),
3474       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.15f,
3475                                crBBox.top - fHeight * 0.65f),
3476                     PWLPT_BEZIERTO),
3477 
3478       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.15f,
3479                                crBBox.top - fHeight * 0.65f),
3480                     PWLPT_LINETO),
3481       CPWL_PathData(
3482           CPWL_Point(crBBox.right - fWidth * 0.15f,
3483                      crBBox.top - fHeight * 0.65f + fHeight * 0.15f * 0.4f),
3484           PWLPT_BEZIERTO),
3485       CPWL_PathData(
3486           CPWL_Point(crBBox.left + fWidth * 0.6f + fWidth * 0.25f * 0.4f,
3487                      crBBox.top - fHeight * 0.5f),
3488           PWLPT_BEZIERTO),
3489       CPWL_PathData(
3490           CPWL_Point(crBBox.left + fWidth * 0.6f, crBBox.top - fHeight * 0.5f),
3491           PWLPT_BEZIERTO),
3492 
3493       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.6f,
3494                                crBBox.top - fHeight * 0.5f + fWidth * 0.04f),
3495                     PWLPT_BEZIERTO),
3496       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.4f,
3497                                crBBox.top - fHeight * 0.5f + fWidth * 0.04f),
3498                     PWLPT_BEZIERTO),
3499       CPWL_PathData(
3500           CPWL_Point(crBBox.left + fWidth * 0.4f, crBBox.top - fHeight * 0.5f),
3501           PWLPT_BEZIERTO),
3502 
3503       CPWL_PathData(
3504           CPWL_Point(crBBox.left + fWidth * 0.5f, crBBox.top - fHeight * 0.65f),
3505           PWLPT_MOVETO),
3506       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.5f,
3507                                crBBox.bottom + fHeight * 0.1f),
3508                     PWLPT_LINETO)};
3509 
3510   if (type == PWLPT_STREAM)
3511     sPathData = GetAppStreamFromArray(PathArray, 24);
3512   else
3513     GetPathDataFromArray(path, PathArray, 24);
3514 }
3515 
GetGraphics_Tag(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)3516 void CPWL_Utils::GetGraphics_Tag(CFX_ByteString& sPathData,
3517                                  CFX_PathData& path,
3518                                  const CPDF_Rect& crBBox,
3519                                  const PWL_PATH_TYPE type) {
3520   FX_FLOAT fWidth = crBBox.right - crBBox.left;
3521   FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
3522 
3523   CPWL_PathData PathArray[] = {
3524       CPWL_PathData(
3525           CPWL_Point(crBBox.left + fWidth * 0.4f, crBBox.top - fHeight * 0.1f),
3526           PWLPT_MOVETO),
3527       CPWL_PathData(
3528           CPWL_Point(crBBox.left + fWidth * 0.1f, crBBox.top - fHeight * 0.5f),
3529           PWLPT_LINETO),
3530       CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 0.3f,
3531                                crBBox.bottom + fHeight * 0.1f),
3532                     PWLPT_LINETO),
3533       CPWL_PathData(CPWL_Point(crBBox.right - fWidth * 0.1f,
3534                                crBBox.bottom + fHeight * 0.1f),
3535                     PWLPT_LINETO),
3536       CPWL_PathData(
3537           CPWL_Point(crBBox.right - fWidth * 0.1f, crBBox.top - fHeight * 0.1f),
3538           PWLPT_LINETO),
3539       CPWL_PathData(
3540           CPWL_Point(crBBox.left + fWidth * 0.4f, crBBox.top - fHeight * 0.1f),
3541           PWLPT_LINETO),
3542       CPWL_PathData(
3543           CPWL_Point(crBBox.left + fWidth * 0.4f, crBBox.top - fHeight * 0.3f),
3544           PWLPT_MOVETO),
3545       CPWL_PathData(
3546           CPWL_Point(crBBox.right - fWidth * 0.2f, crBBox.top - fHeight * 0.3f),
3547           PWLPT_LINETO),
3548       CPWL_PathData(
3549           CPWL_Point(crBBox.left + fWidth * 0.4f, crBBox.top - fHeight * 0.5f),
3550           PWLPT_MOVETO),
3551       CPWL_PathData(
3552           CPWL_Point(crBBox.right - fWidth * 0.2f, crBBox.top - fHeight * 0.5f),
3553           PWLPT_LINETO),
3554       CPWL_PathData(
3555           CPWL_Point(crBBox.left + fWidth * 0.4f, crBBox.top - fHeight * 0.7f),
3556           PWLPT_MOVETO),
3557       CPWL_PathData(
3558           CPWL_Point(crBBox.right - fWidth * 0.2f, crBBox.top - fHeight * 0.7f),
3559           PWLPT_LINETO)};
3560 
3561   if (type == PWLPT_STREAM)
3562     sPathData = GetAppStreamFromArray(PathArray, 12);
3563   else
3564     GetPathDataFromArray(path, PathArray, 12);
3565 }
3566 
GetGraphics_Foxit(CFX_ByteString & sPathData,CFX_PathData & path,const CPDF_Rect & crBBox,const PWL_PATH_TYPE type)3567 void CPWL_Utils::GetGraphics_Foxit(CFX_ByteString& sPathData,
3568                                    CFX_PathData& path,
3569                                    const CPDF_Rect& crBBox,
3570                                    const PWL_PATH_TYPE type) {
3571   FX_FLOAT fOutWidth = crBBox.right - crBBox.left;
3572   FX_FLOAT fOutHeight = crBBox.top - crBBox.bottom;
3573 
3574   CPDF_Rect crInBox = crBBox;
3575   crInBox.left = crBBox.left + fOutWidth * 0.08f;
3576   crInBox.right = crBBox.right - fOutWidth * 0.08f;
3577   crInBox.top = crBBox.top - fOutHeight * 0.08f;
3578   crInBox.bottom = crBBox.bottom + fOutHeight * 0.08f;
3579 
3580   FX_FLOAT fWidth = crInBox.right - crInBox.left;
3581   FX_FLOAT fHeight = crInBox.top - crInBox.bottom;
3582 
3583   CPWL_PathData PathArray[] = {
3584       CPWL_PathData(CPWL_Point(crInBox.left, crInBox.top), PWLPT_MOVETO),
3585       CPWL_PathData(CPWL_Point(crInBox.left + fWidth * 0.45f, crInBox.top),
3586                     PWLPT_LINETO),
3587       CPWL_PathData(CPWL_Point(crInBox.left + fWidth * 0.45f,
3588                                crInBox.top - PWL_BEZIER * fHeight * 0.4f),
3589                     PWLPT_BEZIERTO),
3590       CPWL_PathData(CPWL_Point(crInBox.left + fWidth * 0.45f -
3591                                    PWL_BEZIER * fWidth * 0.45f,
3592                                crInBox.top - fHeight * 0.4f),
3593                     PWLPT_BEZIERTO),
3594       CPWL_PathData(CPWL_Point(crInBox.left, crInBox.top - fHeight * 0.4f),
3595                     PWLPT_BEZIERTO),
3596       CPWL_PathData(CPWL_Point(crInBox.left, crInBox.top), PWLPT_LINETO),
3597 
3598       CPWL_PathData(CPWL_Point(crInBox.left + fWidth * 0.60f, crInBox.top),
3599                     PWLPT_MOVETO),
3600       CPWL_PathData(CPWL_Point(crInBox.left + fWidth * 0.75f, crInBox.top),
3601                     PWLPT_LINETO),
3602       CPWL_PathData(CPWL_Point(crInBox.left + fWidth * 0.75f,
3603                                crInBox.top - PWL_BEZIER * fHeight * 0.7f),
3604                     PWLPT_BEZIERTO),
3605       CPWL_PathData(CPWL_Point(crInBox.left + fWidth * 0.75f -
3606                                    PWL_BEZIER * fWidth * 0.75f,
3607                                crInBox.top - fHeight * 0.7f),
3608                     PWLPT_BEZIERTO),
3609       CPWL_PathData(CPWL_Point(crInBox.left, crInBox.top - fHeight * 0.7f),
3610                     PWLPT_BEZIERTO),
3611       CPWL_PathData(CPWL_Point(crInBox.left, crInBox.top - fHeight * 0.55f),
3612                     PWLPT_LINETO),
3613       CPWL_PathData(CPWL_Point(crInBox.left + PWL_BEZIER * fWidth * 0.60f,
3614                                crInBox.top - fHeight * 0.55f),
3615                     PWLPT_BEZIERTO),
3616       CPWL_PathData(CPWL_Point(crInBox.left + fWidth * 0.60f,
3617                                crInBox.top - PWL_BEZIER * fHeight * 0.55f),
3618                     PWLPT_BEZIERTO),
3619       CPWL_PathData(CPWL_Point(crInBox.left + fWidth * 0.60f, crInBox.top),
3620                     PWLPT_BEZIERTO),
3621 
3622       CPWL_PathData(CPWL_Point(crInBox.left + fWidth * 0.90f, crInBox.top),
3623                     PWLPT_MOVETO),
3624       CPWL_PathData(CPWL_Point(crInBox.left + fWidth * 0.90f,
3625                                crInBox.top - PWL_BEZIER * fHeight * 0.85f),
3626                     PWLPT_BEZIERTO),
3627       CPWL_PathData(CPWL_Point(crInBox.left + fWidth * 0.90f -
3628                                    PWL_BEZIER * fWidth * 0.90f,
3629                                crInBox.top - fHeight * 0.85f),
3630                     PWLPT_BEZIERTO),
3631       CPWL_PathData(CPWL_Point(crInBox.left, crInBox.top - fHeight * 0.85f),
3632                     PWLPT_BEZIERTO),
3633       CPWL_PathData(CPWL_Point(crInBox.left, crInBox.bottom), PWLPT_LINETO),
3634       CPWL_PathData(CPWL_Point(crInBox.right, crInBox.bottom), PWLPT_LINETO),
3635       CPWL_PathData(CPWL_Point(crInBox.right, crInBox.top), PWLPT_LINETO),
3636       CPWL_PathData(CPWL_Point(crInBox.left + fWidth * 0.90f, crInBox.top),
3637                     PWLPT_LINETO),
3638   };
3639 
3640   if (type == PWLPT_STREAM)
3641     sPathData = GetAppStreamFromArray(PathArray, 23);
3642   else
3643     GetPathDataFromArray(path, PathArray, 23);
3644 }
3645 
ConvertColorType(int32_t other_nColorType)3646 void CPWL_Color::ConvertColorType(int32_t other_nColorType) {
3647   switch (other_nColorType) {
3648     case COLORTYPE_TRANSPARENT:
3649       break;
3650     case COLORTYPE_GRAY:
3651       switch (other_nColorType) {
3652         case COLORTYPE_RGB:
3653           CPWL_Utils::ConvertGRAY2RGB(fColor1, fColor1, fColor2, fColor3);
3654           break;
3655         case COLORTYPE_CMYK:
3656           CPWL_Utils::ConvertGRAY2CMYK(fColor1, fColor1, fColor2, fColor3,
3657                                        fColor4);
3658           break;
3659       }
3660       break;
3661     case COLORTYPE_RGB:
3662       switch (other_nColorType) {
3663         case COLORTYPE_GRAY:
3664           CPWL_Utils::ConvertRGB2GRAY(fColor1, fColor2, fColor3, fColor1);
3665           break;
3666         case COLORTYPE_CMYK:
3667           CPWL_Utils::ConvertRGB2CMYK(fColor1, fColor2, fColor3, fColor1,
3668                                       fColor2, fColor3, fColor4);
3669           break;
3670       }
3671       break;
3672     case COLORTYPE_CMYK:
3673       switch (other_nColorType) {
3674         case COLORTYPE_GRAY:
3675           CPWL_Utils::ConvertCMYK2GRAY(fColor1, fColor2, fColor3, fColor4,
3676                                        fColor1);
3677           break;
3678         case COLORTYPE_RGB:
3679           CPWL_Utils::ConvertCMYK2RGB(fColor1, fColor2, fColor3, fColor4,
3680                                       fColor1, fColor2, fColor3);
3681           break;
3682       }
3683       break;
3684   }
3685   nColorType = other_nColorType;
3686 }
3687