dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 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 | |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 9 | #include "core/fxge/fx_dib.h" |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 10 | #include "xfa/fxfa/parser/cxfa_fill.h" |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 11 | #include "xfa/fxfa/parser/cxfa_measurement.h" |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 12 | #include "xfa/fxfa/parser/xfa_object.h" |
| 13 | |
| 14 | CXFA_Font::CXFA_Font(CXFA_Node* pNode) : CXFA_Data(pNode) {} |
| 15 | |
| 16 | FX_FLOAT CXFA_Font::GetBaselineShift() { |
| 17 | return m_pNode->GetMeasure(XFA_ATTRIBUTE_BaselineShift).ToUnit(XFA_UNIT_Pt); |
| 18 | } |
| 19 | |
| 20 | FX_FLOAT CXFA_Font::GetHorizontalScale() { |
| 21 | CFX_WideString wsValue; |
| 22 | m_pNode->TryCData(XFA_ATTRIBUTE_FontHorizontalScale, wsValue); |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 23 | int32_t iScale = FXSYS_wtoi(wsValue.c_str()); |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 24 | return iScale > 0 ? (FX_FLOAT)iScale : 100.0f; |
| 25 | } |
| 26 | |
| 27 | FX_FLOAT CXFA_Font::GetVerticalScale() { |
| 28 | CFX_WideString wsValue; |
| 29 | m_pNode->TryCData(XFA_ATTRIBUTE_FontVerticalScale, wsValue); |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 30 | int32_t iScale = FXSYS_wtoi(wsValue.c_str()); |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 31 | return iScale > 0 ? (FX_FLOAT)iScale : 100.0f; |
| 32 | } |
| 33 | |
| 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 | |
| 45 | int32_t CXFA_Font::GetLineThrough() { |
| 46 | int32_t iValue = 0; |
| 47 | m_pNode->TryInteger(XFA_ATTRIBUTE_LineThrough, iValue); |
| 48 | return iValue; |
| 49 | } |
| 50 | |
| 51 | int32_t CXFA_Font::GetUnderline() { |
| 52 | int32_t iValue = 0; |
| 53 | m_pNode->TryInteger(XFA_ATTRIBUTE_Underline, iValue); |
| 54 | return iValue; |
| 55 | } |
| 56 | |
| 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 | |
| 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 | |
| 69 | void CXFA_Font::GetTypeface(CFX_WideStringC& wsTypeFace) { |
| 70 | m_pNode->TryCData(XFA_ATTRIBUTE_Typeface, wsTypeFace); |
| 71 | } |
| 72 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 73 | bool CXFA_Font::IsBold() { |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 74 | XFA_ATTRIBUTEENUM eAttr = XFA_ATTRIBUTEENUM_Normal; |
| 75 | m_pNode->TryEnum(XFA_ATTRIBUTE_Weight, eAttr); |
| 76 | return eAttr == XFA_ATTRIBUTEENUM_Bold; |
| 77 | } |
| 78 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 79 | bool CXFA_Font::IsItalic() { |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 80 | XFA_ATTRIBUTEENUM eAttr = XFA_ATTRIBUTEENUM_Normal; |
| 81 | m_pNode->TryEnum(XFA_ATTRIBUTE_Posture, eAttr); |
| 82 | return eAttr == XFA_ATTRIBUTEENUM_Italic; |
| 83 | } |
| 84 | |
| 85 | void CXFA_Font::SetColor(FX_ARGB color) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 86 | CXFA_Fill fill(m_pNode->GetProperty(0, XFA_Element::Fill)); |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 87 | fill.SetColor(color); |
| 88 | } |
| 89 | |
| 90 | FX_ARGB CXFA_Font::GetColor() { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 91 | CXFA_Fill fill(m_pNode->GetChild(0, XFA_Element::Fill)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 92 | return fill ? fill.GetColor(true) : 0xFF000000; |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 93 | } |