| OLD | NEW |
| (Empty) |
| 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 "core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h" | |
| 8 | |
| 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | |
| 10 #include "core/fpdfapi/fpdf_page/pageint.h" | |
| 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | |
| 12 | |
| 13 bool SetTextRenderingModeFromInt(int iMode, TextRenderingMode* mode) { | |
| 14 if (iMode < 0 || iMode > 7) | |
| 15 return false; | |
| 16 *mode = static_cast<TextRenderingMode>(iMode); | |
| 17 return true; | |
| 18 } | |
| 19 | |
| 20 bool TextRenderingModeIsClipMode(const TextRenderingMode& mode) { | |
| 21 switch (mode) { | |
| 22 case TextRenderingMode::MODE_FILL_CLIP: | |
| 23 case TextRenderingMode::MODE_STROKE_CLIP: | |
| 24 case TextRenderingMode::MODE_FILL_STROKE_CLIP: | |
| 25 case TextRenderingMode::MODE_CLIP: | |
| 26 return true; | |
| 27 default: | |
| 28 return false; | |
| 29 } | |
| 30 } | |
| 31 | |
| 32 bool TextRenderingModeIsStrokeMode(const TextRenderingMode& mode) { | |
| 33 switch (mode) { | |
| 34 case TextRenderingMode::MODE_STROKE: | |
| 35 case TextRenderingMode::MODE_FILL_STROKE: | |
| 36 case TextRenderingMode::MODE_STROKE_CLIP: | |
| 37 case TextRenderingMode::MODE_FILL_STROKE_CLIP: | |
| 38 return true; | |
| 39 default: | |
| 40 return false; | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 CPDF_TextStateData::CPDF_TextStateData() | |
| 45 : m_pFont(nullptr), | |
| 46 m_pDocument(nullptr), | |
| 47 m_FontSize(1.0f), | |
| 48 m_CharSpace(0), | |
| 49 m_WordSpace(0), | |
| 50 m_TextMode(TextRenderingMode::MODE_FILL) { | |
| 51 m_Matrix[0] = m_Matrix[3] = 1.0f; | |
| 52 m_Matrix[1] = m_Matrix[2] = 0; | |
| 53 m_CTM[0] = m_CTM[3] = 1.0f; | |
| 54 m_CTM[1] = m_CTM[2] = 0; | |
| 55 } | |
| 56 | |
| 57 CPDF_TextStateData::CPDF_TextStateData(const CPDF_TextStateData& src) { | |
| 58 if (this == &src) | |
| 59 return; | |
| 60 | |
| 61 FXSYS_memcpy(this, &src, sizeof(CPDF_TextStateData)); | |
| 62 if (m_pDocument && m_pFont) { | |
| 63 m_pFont = | |
| 64 m_pDocument->GetPageData()->GetFont(m_pFont->GetFontDict(), FALSE); | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 CPDF_TextStateData::~CPDF_TextStateData() { | |
| 69 if (m_pDocument && m_pFont) { | |
| 70 CPDF_DocPageData* pPageData = m_pDocument->GetPageData(); | |
| 71 if (pPageData && !pPageData->IsForceClear()) | |
| 72 pPageData->ReleaseFont(m_pFont->GetFontDict()); | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 void CPDF_TextStateData::SetFont(CPDF_Font* pFont) { | |
| 77 CPDF_Document* pDoc = m_pDocument; | |
| 78 CPDF_DocPageData* pPageData = pDoc ? pDoc->GetPageData() : nullptr; | |
| 79 if (pPageData && m_pFont && !pPageData->IsForceClear()) | |
| 80 pPageData->ReleaseFont(m_pFont->GetFontDict()); | |
| 81 | |
| 82 m_pDocument = pFont ? pFont->m_pDocument : nullptr; | |
| 83 m_pFont = pFont; | |
| 84 } | |
| 85 | |
| 86 FX_FLOAT CPDF_TextStateData::GetFontSizeV() const { | |
| 87 return FXSYS_fabs(FXSYS_sqrt2(m_Matrix[1], m_Matrix[3]) * m_FontSize); | |
| 88 } | |
| 89 | |
| 90 FX_FLOAT CPDF_TextStateData::GetFontSizeH() const { | |
| 91 return FXSYS_fabs(FXSYS_sqrt2(m_Matrix[0], m_Matrix[2]) * m_FontSize); | |
| 92 } | |
| 93 | |
| 94 FX_FLOAT CPDF_TextStateData::GetBaselineAngle() const { | |
| 95 return FXSYS_atan2(m_Matrix[2], m_Matrix[0]); | |
| 96 } | |
| 97 | |
| 98 FX_FLOAT CPDF_TextStateData::GetShearAngle() const { | |
| 99 return GetBaselineAngle() + FXSYS_atan2(m_Matrix[1], m_Matrix[3]); | |
| 100 } | |
| OLD | NEW |