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 <algorithm>
8
9#include "../../include/formfiller/FormFiller.h"
10#include "../../include/formfiller/FFL_Utils.h"
11
12CPDF_Rect CFFL_Utils::MaxRect(const CPDF_Rect & rect1,const CPDF_Rect & rect2)
13{
14	CPDF_Rect rcRet;
15
16	rcRet.left = std::min(rect1.left, rect2.left);
17	rcRet.bottom = std::min(rect1.bottom, rect2.bottom);
18	rcRet.right = std::max(rect1.right, rect2.right);
19	rcRet.top = std::max(rect1.top, rect2.top);
20
21	return rcRet;
22}
23
24CPDF_Rect CFFL_Utils::InflateRect(const CPDF_Rect & crRect,const FX_FLOAT & fSize)
25{
26	CPDF_Rect crNew(crRect.left - fSize,
27					crRect.bottom - fSize,
28					crRect.right + fSize,
29					crRect.top + fSize);
30	crNew.Normalize();
31	return crNew;
32}
33
34CPDF_Rect CFFL_Utils::DeflateRect(const CPDF_Rect & crRect,const FX_FLOAT & fSize)
35{
36	CPDF_Rect crNew(crRect.left + fSize,
37					crRect.bottom + fSize,
38					crRect.right - fSize,
39					crRect.top - fSize);
40	crNew.Normalize();
41	return crNew;
42}
43
44FX_BOOL CFFL_Utils::TraceObject(CPDF_Object* pObj)
45{
46	if (!pObj) return FALSE;
47
48	FX_DWORD	dwObjNum = pObj->GetObjNum();
49	switch (pObj->GetType())
50	{
51	case PDFOBJ_ARRAY:
52		{
53			CPDF_Array* pArray = (CPDF_Array*)pObj;
54			for (FX_DWORD i = 0; i < pArray->GetCount(); i ++)
55			{
56				CPDF_Object* pElement = pArray->GetElementValue(i);
57				TraceObject(pElement);
58			}
59		}
60		break;
61
62	case PDFOBJ_DICTIONARY:
63		{
64			CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
65
66			FX_POSITION fPos = pDict->GetStartPos();
67			CFX_ByteString csKey;
68			do
69			{
70				CPDF_Object* pElement = pDict->GetNextElement(fPos, csKey);
71 				//TRACE(csKey + "\n");
72				if (!pElement) break;
73				TraceObject(pElement);
74			}while (TRUE);
75		}
76		break;
77
78	case PDFOBJ_STREAM:
79		{
80			CPDF_Stream* pStream = (CPDF_Stream*)pObj;
81			CPDF_Dictionary* pDict = pStream->GetDict();
82			TraceObject(pDict);
83		}
84		break;
85
86	case PDFOBJ_REFERENCE:
87		{
88			CPDF_Object* pDirectObj = pObj->GetDirect();
89			TraceObject(pDirectObj);
90		}
91		break;
92
93	case PDFOBJ_BOOLEAN:
94		break;
95	case PDFOBJ_NUMBER:
96		//TRACE("%d\n",(FX_INT32)pObj);
97		break;
98	case PDFOBJ_STRING:
99		//TRACE(((CPDF_String*)pObj)->GetString() + "\n");
100		break;
101	case PDFOBJ_NAME:
102		//TRACE(((CPDF_Name*)pObj)->GetString() + "\n");
103		break;
104	case PDFOBJ_NULL:
105//	case PDFOBJ_KEYWORD:
106//	case PDFOBJ_EOF:
107	default:
108		break;
109	}
110	if (dwObjNum == 0) return FALSE;
111
112	return TRUE;
113}
114
115