OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fxfa/app/xfa_textlayout.h" | 7 #include "xfa/fxfa/app/xfa_textlayout.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "core/fxcrt/include/fx_ext.h" | 11 #include "core/fxcrt/include/fx_ext.h" |
12 #include "xfa/fde/cfde_path.h" | 12 #include "xfa/fde/cfde_path.h" |
13 #include "xfa/fde/css/fde_csscache.h" | 13 #include "xfa/fde/css/fde_csscache.h" |
14 #include "xfa/fde/css/fde_cssstyleselector.h" | 14 #include "xfa/fde/css/fde_cssstyleselector.h" |
15 #include "xfa/fde/fde_gedevice.h" | 15 #include "xfa/fde/fde_gedevice.h" |
16 #include "xfa/fde/fde_object.h" | 16 #include "xfa/fde/fde_object.h" |
17 #include "xfa/fde/xml/fde_xml_imp.h" | 17 #include "xfa/fde/xml/fde_xml_imp.h" |
18 #include "xfa/fgas/crt/fgas_codepage.h" | 18 #include "xfa/fgas/crt/fgas_codepage.h" |
19 #include "xfa/fxfa/app/xfa_ffwidgetacc.h" | 19 #include "xfa/fxfa/app/xfa_ffwidgetacc.h" |
20 #include "xfa/fxfa/include/xfa_ffapp.h" | 20 #include "xfa/fxfa/include/xfa_ffapp.h" |
21 #include "xfa/fxfa/include/xfa_ffdoc.h" | 21 #include "xfa/fxfa/include/xfa_ffdoc.h" |
22 #include "xfa/fxfa/include/xfa_fontmgr.h" | 22 #include "xfa/fxfa/include/xfa_fontmgr.h" |
23 | 23 |
| 24 CXFA_CSSTagProvider::CXFA_CSSTagProvider() |
| 25 : m_bTagAvailable(FALSE), m_bContent(FALSE) {} |
| 26 |
| 27 CXFA_CSSTagProvider::~CXFA_CSSTagProvider() {} |
| 28 |
| 29 XFA_TextPiece::XFA_TextPiece() |
| 30 : pszText(nullptr), pFont(nullptr), pLinkData(nullptr) {} |
| 31 |
| 32 XFA_TextPiece::~XFA_TextPiece() { |
| 33 if (pLinkData) |
| 34 pLinkData->Release(); |
| 35 } |
| 36 |
| 37 CXFA_TextParseContext::CXFA_TextParseContext() |
| 38 : m_pParentStyle(nullptr), |
| 39 m_ppMatchedDecls(nullptr), |
| 40 m_dwMatchedDecls(0), |
| 41 m_eDisplay(FDE_CSSDISPLAY_None) {} |
| 42 |
| 43 CXFA_TextParseContext::~CXFA_TextParseContext() { |
| 44 if (m_pParentStyle) |
| 45 m_pParentStyle->Release(); |
| 46 FX_Free(m_ppMatchedDecls); |
| 47 } |
| 48 |
24 void CXFA_TextParseContext::SetDecls(const CFDE_CSSDeclaration** ppDeclArray, | 49 void CXFA_TextParseContext::SetDecls(const CFDE_CSSDeclaration** ppDeclArray, |
25 int32_t iDeclCount) { | 50 int32_t iDeclCount) { |
26 if (iDeclCount <= 0 || !ppDeclArray) | 51 if (iDeclCount <= 0 || !ppDeclArray) |
27 return; | 52 return; |
28 | 53 |
29 m_dwMatchedDecls = iDeclCount; | 54 m_dwMatchedDecls = iDeclCount; |
30 m_ppMatchedDecls = FX_Alloc(CFDE_CSSDeclaration*, iDeclCount); | 55 m_ppMatchedDecls = FX_Alloc(CFDE_CSSDeclaration*, iDeclCount); |
31 FXSYS_memcpy(m_ppMatchedDecls, ppDeclArray, | 56 FXSYS_memcpy(m_ppMatchedDecls, ppDeclArray, |
32 iDeclCount * sizeof(CFDE_CSSDeclaration*)); | 57 iDeclCount * sizeof(CFDE_CSSDeclaration*)); |
33 } | 58 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 fFontSize = font.GetFontSize(); | 103 fFontSize = font.GetFontSize(); |
79 } | 104 } |
80 m_pSelector->SetDefFontSize(fFontSize); | 105 m_pSelector->SetDefFontSize(fFontSize); |
81 } | 106 } |
82 if (!m_pUASheet) { | 107 if (!m_pUASheet) { |
83 m_pUASheet = LoadDefaultSheetStyle(); | 108 m_pUASheet = LoadDefaultSheetStyle(); |
84 m_pSelector->SetStyleSheet(FDE_CSSSTYLESHEETGROUP_UserAgent, m_pUASheet); | 109 m_pSelector->SetStyleSheet(FDE_CSSSTYLESHEETGROUP_UserAgent, m_pUASheet); |
85 m_pSelector->UpdateStyleIndex(FDE_CSSMEDIATYPE_ALL); | 110 m_pSelector->UpdateStyleIndex(FDE_CSSMEDIATYPE_ALL); |
86 } | 111 } |
87 } | 112 } |
| 113 |
| 114 CXFA_LoaderContext::CXFA_LoaderContext() |
| 115 : m_bSaveLineHeight(FALSE), |
| 116 m_fWidth(0), |
| 117 m_fHeight(0), |
| 118 m_fLastPos(0), |
| 119 m_fStartLineOffset(0), |
| 120 m_iChar(0), |
| 121 m_iTotalLines(-1), |
| 122 m_pXMLNode(NULL), |
| 123 m_pNode(NULL), |
| 124 m_pParentStyle(NULL), |
| 125 m_dwFlags(0) {} |
| 126 |
| 127 CXFA_LoaderContext::~CXFA_LoaderContext() {} |
| 128 |
88 IFDE_CSSStyleSheet* CXFA_TextParser::LoadDefaultSheetStyle() { | 129 IFDE_CSSStyleSheet* CXFA_TextParser::LoadDefaultSheetStyle() { |
89 static const FX_WCHAR s_pStyle[] = | 130 static const FX_WCHAR s_pStyle[] = |
90 L"html,body,ol,p,ul{display:block}" | 131 L"html,body,ol,p,ul{display:block}" |
91 L"li{display:list-item}" | 132 L"li{display:list-item}" |
92 L"ol,ul{padding-left:33px}ol{list-style-type:decimal}ol,ul{margin-top:0;" | 133 L"ol,ul{padding-left:33px}ol{list-style-type:decimal}ol,ul{margin-top:0;" |
93 L"margin-bottom:0}ul,ol{margin:1.12em 0}" | 134 L"margin-bottom:0}ul,ol{margin:1.12em 0}" |
94 L"a{color:#0000ff;text-decoration:underline}b{font-weight:bolder}i{font-" | 135 L"a{color:#0000ff;text-decoration:underline}b{font-weight:bolder}i{font-" |
95 L"style:italic}" | 136 L"style:italic}" |
96 L"sup{vertical-align:+15em;font-size:.66em}sub{vertical-align:-15em;font-" | 137 L"sup{vertical-align:+15em;font-size:.66em}sub{vertical-align:-15em;font-" |
97 L"size:.66em}"; | 138 L"size:.66em}"; |
(...skipping 1840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1938 tr.iLength = iLength; | 1979 tr.iLength = iLength; |
1939 tr.fFontSize = pPiece->fFontSize; | 1980 tr.fFontSize = pPiece->fFontSize; |
1940 tr.iBidiLevel = pPiece->iBidiLevel; | 1981 tr.iBidiLevel = pPiece->iBidiLevel; |
1941 tr.iCharRotation = 0; | 1982 tr.iCharRotation = 0; |
1942 tr.wLineBreakChar = L'\n'; | 1983 tr.wLineBreakChar = L'\n'; |
1943 tr.iVerticalScale = pPiece->iVerScale; | 1984 tr.iVerticalScale = pPiece->iVerScale; |
1944 tr.dwLayoutStyles = FX_RTFLAYOUTSTYLE_ExpandTab; | 1985 tr.dwLayoutStyles = FX_RTFLAYOUTSTYLE_ExpandTab; |
1945 tr.iHorizontalScale = pPiece->iHorScale; | 1986 tr.iHorizontalScale = pPiece->iHorScale; |
1946 return TRUE; | 1987 return TRUE; |
1947 } | 1988 } |
| 1989 |
| 1990 CXFA_LinkUserData::CXFA_LinkUserData(IFX_MemoryAllocator* pAllocator, |
| 1991 FX_WCHAR* pszText) |
| 1992 : m_pAllocator(pAllocator), m_dwRefCount(1), m_wsURLContent(pszText) {} |
| 1993 |
| 1994 CXFA_LinkUserData::~CXFA_LinkUserData() {} |
| 1995 |
| 1996 uint32_t CXFA_LinkUserData::Retain() { |
| 1997 return ++m_dwRefCount; |
| 1998 } |
| 1999 |
| 2000 uint32_t CXFA_LinkUserData::Release() { |
| 2001 uint32_t dwRefCount = --m_dwRefCount; |
| 2002 if (dwRefCount <= 0) |
| 2003 FXTARGET_DeleteWith(CXFA_LinkUserData, m_pAllocator, this); |
| 2004 return dwRefCount; |
| 2005 } |
| 2006 |
| 2007 const FX_WCHAR* CXFA_LinkUserData::GetLinkURL() { |
| 2008 return m_wsURLContent.c_str(); |
| 2009 } |
| 2010 |
| 2011 CXFA_TextUserData::CXFA_TextUserData(IFX_MemoryAllocator* pAllocator, |
| 2012 IFDE_CSSComputedStyle* pStyle) |
| 2013 : m_pStyle(pStyle), |
| 2014 m_pLinkData(nullptr), |
| 2015 m_pAllocator(pAllocator), |
| 2016 m_dwRefCount(0) { |
| 2017 ASSERT(m_pAllocator); |
| 2018 if (m_pStyle) |
| 2019 m_pStyle->Retain(); |
| 2020 } |
| 2021 |
| 2022 CXFA_TextUserData::CXFA_TextUserData(IFX_MemoryAllocator* pAllocator, |
| 2023 IFDE_CSSComputedStyle* pStyle, |
| 2024 CXFA_LinkUserData* pLinkData) |
| 2025 : m_pStyle(pStyle), |
| 2026 m_pLinkData(pLinkData), |
| 2027 m_pAllocator(pAllocator), |
| 2028 m_dwRefCount(0) { |
| 2029 ASSERT(m_pAllocator); |
| 2030 if (m_pStyle) |
| 2031 m_pStyle->Retain(); |
| 2032 } |
| 2033 |
| 2034 CXFA_TextUserData::~CXFA_TextUserData() { |
| 2035 if (m_pStyle) |
| 2036 m_pStyle->Release(); |
| 2037 if (m_pLinkData) |
| 2038 m_pLinkData->Release(); |
| 2039 } |
| 2040 |
| 2041 uint32_t CXFA_TextUserData::Retain() { |
| 2042 return ++m_dwRefCount; |
| 2043 } |
| 2044 |
| 2045 uint32_t CXFA_TextUserData::Release() { |
| 2046 uint32_t dwRefCount = --m_dwRefCount; |
| 2047 if (dwRefCount == 0) |
| 2048 FXTARGET_DeleteWith(CXFA_TextUserData, m_pAllocator, this); |
| 2049 return dwRefCount; |
| 2050 } |
| 2051 |
| 2052 CXFA_PieceLine::CXFA_PieceLine() {} |
| 2053 |
| 2054 CXFA_PieceLine::~CXFA_PieceLine() {} |
| 2055 |
| 2056 CXFA_TextTabstopsContext::CXFA_TextTabstopsContext() |
| 2057 : m_iTabCount(0), |
| 2058 m_iTabIndex(-1), |
| 2059 m_bTabstops(FALSE), |
| 2060 m_fTabWidth(0), |
| 2061 m_fLeft(0) {} |
| 2062 |
| 2063 CXFA_TextTabstopsContext::~CXFA_TextTabstopsContext() {} |
| 2064 |
| 2065 void CXFA_TextTabstopsContext::Append(uint32_t dwAlign, FX_FLOAT fTabstops) { |
| 2066 int32_t i = 0; |
| 2067 for (i = 0; i < m_iTabCount; i++) { |
| 2068 XFA_TABSTOPS* pTabstop = m_tabstops.GetDataPtr(i); |
| 2069 if (fTabstops < pTabstop->fTabstops) { |
| 2070 break; |
| 2071 } |
| 2072 } |
| 2073 m_tabstops.InsertSpaceAt(i, 1); |
| 2074 XFA_TABSTOPS tabstop; |
| 2075 tabstop.dwAlign = dwAlign; |
| 2076 tabstop.fTabstops = fTabstops; |
| 2077 m_tabstops.SetAt(i, tabstop); |
| 2078 m_iTabCount++; |
| 2079 } |
| 2080 |
| 2081 void CXFA_TextTabstopsContext::RemoveAll() { |
| 2082 m_tabstops.RemoveAll(); |
| 2083 m_iTabCount = 0; |
| 2084 } |
| 2085 |
| 2086 void CXFA_TextTabstopsContext::Reset() { |
| 2087 m_iTabIndex = -1; |
| 2088 m_bTabstops = FALSE; |
| 2089 m_fTabWidth = 0; |
| 2090 m_fLeft = 0; |
| 2091 } |
OLD | NEW |