• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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 "xfa/fxfa/parser/cxfa_font.h"
8 
9 #include "core/fxge/fx_dib.h"
10 #include "xfa/fxfa/parser/cxfa_fill.h"
11 #include "xfa/fxfa/parser/cxfa_measurement.h"
12 #include "xfa/fxfa/parser/xfa_object.h"
13 
CXFA_Font(CXFA_Node * pNode)14 CXFA_Font::CXFA_Font(CXFA_Node* pNode) : CXFA_Data(pNode) {}
15 
GetBaselineShift()16 FX_FLOAT CXFA_Font::GetBaselineShift() {
17   return m_pNode->GetMeasure(XFA_ATTRIBUTE_BaselineShift).ToUnit(XFA_UNIT_Pt);
18 }
19 
GetHorizontalScale()20 FX_FLOAT CXFA_Font::GetHorizontalScale() {
21   CFX_WideString wsValue;
22   m_pNode->TryCData(XFA_ATTRIBUTE_FontHorizontalScale, wsValue);
23   int32_t iScale = FXSYS_wtoi(wsValue.c_str());
24   return iScale > 0 ? (FX_FLOAT)iScale : 100.0f;
25 }
26 
GetVerticalScale()27 FX_FLOAT CXFA_Font::GetVerticalScale() {
28   CFX_WideString wsValue;
29   m_pNode->TryCData(XFA_ATTRIBUTE_FontVerticalScale, wsValue);
30   int32_t iScale = FXSYS_wtoi(wsValue.c_str());
31   return iScale > 0 ? (FX_FLOAT)iScale : 100.0f;
32 }
33 
GetLetterSpacing()34 FX_FLOAT CXFA_Font::GetLetterSpacing() {
35   CFX_WideStringC wsValue;
36   if (!m_pNode->TryCData(XFA_ATTRIBUTE_LetterSpacing, wsValue))
37     return 0;
38 
39   CXFA_Measurement ms(wsValue);
40   if (ms.GetUnit() == XFA_UNIT_Em)
41     return ms.GetValue() * GetFontSize();
42   return ms.ToUnit(XFA_UNIT_Pt);
43 }
44 
GetLineThrough()45 int32_t CXFA_Font::GetLineThrough() {
46   int32_t iValue = 0;
47   m_pNode->TryInteger(XFA_ATTRIBUTE_LineThrough, iValue);
48   return iValue;
49 }
50 
GetUnderline()51 int32_t CXFA_Font::GetUnderline() {
52   int32_t iValue = 0;
53   m_pNode->TryInteger(XFA_ATTRIBUTE_Underline, iValue);
54   return iValue;
55 }
56 
GetUnderlinePeriod()57 int32_t CXFA_Font::GetUnderlinePeriod() {
58   XFA_ATTRIBUTEENUM eAttr = XFA_ATTRIBUTEENUM_All;
59   m_pNode->TryEnum(XFA_ATTRIBUTE_UnderlinePeriod, eAttr);
60   return eAttr;
61 }
62 
GetFontSize()63 FX_FLOAT CXFA_Font::GetFontSize() {
64   CXFA_Measurement ms;
65   m_pNode->TryMeasure(XFA_ATTRIBUTE_Size, ms);
66   return ms.ToUnit(XFA_UNIT_Pt);
67 }
68 
GetTypeface(CFX_WideStringC & wsTypeFace)69 void CXFA_Font::GetTypeface(CFX_WideStringC& wsTypeFace) {
70   m_pNode->TryCData(XFA_ATTRIBUTE_Typeface, wsTypeFace);
71 }
72 
IsBold()73 bool CXFA_Font::IsBold() {
74   XFA_ATTRIBUTEENUM eAttr = XFA_ATTRIBUTEENUM_Normal;
75   m_pNode->TryEnum(XFA_ATTRIBUTE_Weight, eAttr);
76   return eAttr == XFA_ATTRIBUTEENUM_Bold;
77 }
78 
IsItalic()79 bool CXFA_Font::IsItalic() {
80   XFA_ATTRIBUTEENUM eAttr = XFA_ATTRIBUTEENUM_Normal;
81   m_pNode->TryEnum(XFA_ATTRIBUTE_Posture, eAttr);
82   return eAttr == XFA_ATTRIBUTEENUM_Italic;
83 }
84 
SetColor(FX_ARGB color)85 void CXFA_Font::SetColor(FX_ARGB color) {
86   CXFA_Fill fill(m_pNode->GetProperty(0, XFA_Element::Fill));
87   fill.SetColor(color);
88 }
89 
GetColor()90 FX_ARGB CXFA_Font::GetColor() {
91   CXFA_Fill fill(m_pNode->GetChild(0, XFA_Element::Fill));
92   return fill ? fill.GetColor(true) : 0xFF000000;
93 }
94