Home | History | Annotate | Download | only in fpdfdoc
      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/fpdfdoc/fpdf_doc.h"
      8 CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild(CPDF_Bookmark Parent)
      9 {
     10     if (Parent.m_pDict == NULL) {
     11         CPDF_Dictionary* pRoot = m_pDocument->GetRoot()->GetDict("Outlines");
     12         if (pRoot == NULL) {
     13             return NULL;
     14         }
     15         return pRoot->GetDict("First");
     16     }
     17     return Parent.m_pDict->GetDict("First");
     18 }
     19 CPDF_Bookmark CPDF_BookmarkTree::GetNextSibling(CPDF_Bookmark This)
     20 {
     21     if (This.m_pDict == NULL) {
     22         return NULL;
     23     }
     24     CPDF_Dictionary *pNext = This.m_pDict->GetDict("Next");
     25     return pNext == This.m_pDict ? NULL : pNext;
     26 }
     27 FX_DWORD CPDF_Bookmark::GetColorRef()
     28 {
     29     if (!m_pDict) {
     30         return 0;
     31     }
     32     CPDF_Array* pColor = m_pDict->GetArray("C");
     33     if (pColor == NULL) {
     34         return FXSYS_RGB(0, 0, 0);
     35     }
     36     int r = FXSYS_round(pColor->GetNumber(0) * 255);
     37     int g = FXSYS_round(pColor->GetNumber(1) * 255);
     38     int b = FXSYS_round(pColor->GetNumber(2) * 255);
     39     return FXSYS_RGB(r, g, b);
     40 }
     41 FX_DWORD CPDF_Bookmark::GetFontStyle()
     42 {
     43     if (!m_pDict) {
     44         return 0;
     45     }
     46     return m_pDict->GetInteger("F");
     47 }
     48 CFX_WideString CPDF_Bookmark::GetTitle()
     49 {
     50     if (!m_pDict) {
     51         return CFX_WideString();
     52     }
     53     CPDF_String* pString = (CPDF_String*)m_pDict->GetElementValue("Title");
     54     if (pString == NULL || pString->GetType() != PDFOBJ_STRING) {
     55         return CFX_WideString();
     56     }
     57     CFX_WideString title = pString->GetUnicodeText();
     58     FX_LPWSTR buf = title.LockBuffer();
     59     int len = title.GetLength(), i;
     60     for (i = 0; i < len; i ++)
     61         if (buf[i] < 0x20) {
     62             buf[i] = 0x20;
     63         }
     64     title.ReleaseBuffer(len);
     65     return title;
     66 }
     67 CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument)
     68 {
     69     if (!m_pDict) {
     70         return NULL;
     71     }
     72     CPDF_Object* pDest = m_pDict->GetElementValue("Dest");
     73     if (pDest == NULL) {
     74         return NULL;
     75     }
     76     if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) {
     77         CPDF_NameTree name_tree(pDocument, FX_BSTRC("Dests"));
     78         CFX_ByteStringC name = pDest->GetString();
     79         return name_tree.LookupNamedDest(pDocument, name);
     80     } else if (pDest->GetType() == PDFOBJ_ARRAY) {
     81         return (CPDF_Array*)pDest;
     82     }
     83     return NULL;
     84 }
     85 CPDF_Action CPDF_Bookmark::GetAction()
     86 {
     87     if (!m_pDict) {
     88         return NULL;
     89     }
     90     return m_pDict->GetDict("A");
     91 }
     92