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