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/fxge/cfx_graphstate.h" 8 9 #include "core/fpdfapi/parser/cpdf_array.h" 10 CFX_GraphState()11CFX_GraphState::CFX_GraphState() {} 12 CFX_GraphState(const CFX_GraphState & that)13CFX_GraphState::CFX_GraphState(const CFX_GraphState& that) 14 : m_Ref(that.m_Ref) {} 15 ~CFX_GraphState()16CFX_GraphState::~CFX_GraphState() {} 17 Emplace()18void CFX_GraphState::Emplace() { 19 m_Ref.Emplace(); 20 } 21 SetLineDash(CPDF_Array * pArray,float phase,float scale)22void CFX_GraphState::SetLineDash(CPDF_Array* pArray, float phase, float scale) { 23 CFX_GraphStateData* pData = m_Ref.GetPrivateCopy(); 24 pData->m_DashPhase = phase * scale; 25 pData->SetDashCount(static_cast<int>(pArray->GetCount())); 26 for (size_t i = 0; i < pArray->GetCount(); i++) 27 pData->m_DashArray[i] = pArray->GetNumberAt(i) * scale; 28 } 29 GetLineWidth() const30float CFX_GraphState::GetLineWidth() const { 31 return m_Ref.GetObject() ? m_Ref.GetObject()->m_LineWidth : 1.f; 32 } 33 SetLineWidth(float width)34void CFX_GraphState::SetLineWidth(float width) { 35 m_Ref.GetPrivateCopy()->m_LineWidth = width; 36 } 37 GetLineCap() const38CFX_GraphStateData::LineCap CFX_GraphState::GetLineCap() const { 39 return m_Ref.GetObject() ? m_Ref.GetObject()->m_LineCap 40 : CFX_GraphStateData::LineCapButt; 41 } SetLineCap(CFX_GraphStateData::LineCap cap)42void CFX_GraphState::SetLineCap(CFX_GraphStateData::LineCap cap) { 43 m_Ref.GetPrivateCopy()->m_LineCap = cap; 44 } 45 GetLineJoin() const46CFX_GraphStateData::LineJoin CFX_GraphState::GetLineJoin() const { 47 return m_Ref.GetObject() ? m_Ref.GetObject()->m_LineJoin 48 : CFX_GraphStateData::LineJoinMiter; 49 } 50 SetLineJoin(CFX_GraphStateData::LineJoin join)51void CFX_GraphState::SetLineJoin(CFX_GraphStateData::LineJoin join) { 52 m_Ref.GetPrivateCopy()->m_LineJoin = join; 53 } 54 GetMiterLimit() const55float CFX_GraphState::GetMiterLimit() const { 56 return m_Ref.GetObject() ? m_Ref.GetObject()->m_MiterLimit : 10.f; 57 } 58 SetMiterLimit(float limit)59void CFX_GraphState::SetMiterLimit(float limit) { 60 m_Ref.GetPrivateCopy()->m_MiterLimit = limit; 61 } 62