1 // Copyright 2016 The PDFium Authors 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 <utility> 10 11 CFX_GraphState::CFX_GraphState() = default; 12 CFX_GraphState(const CFX_GraphState & that)13CFX_GraphState::CFX_GraphState(const CFX_GraphState& that) 14 : m_Ref(that.m_Ref) {} 15 16 CFX_GraphState::~CFX_GraphState() = default; 17 Emplace()18void CFX_GraphState::Emplace() { 19 m_Ref.Emplace(); 20 } 21 SetLineDash(std::vector<float> dashes,float phase,float scale)22void CFX_GraphState::SetLineDash(std::vector<float> dashes, 23 float phase, 24 float scale) { 25 CFX_GraphStateData* pData = m_Ref.GetPrivateCopy(); 26 pData->m_DashPhase = phase * scale; 27 for (float& val : dashes) 28 val *= scale; 29 pData->m_DashArray = std::move(dashes); 30 } 31 SetLineDashPhase(float phase)32void CFX_GraphState::SetLineDashPhase(float phase) { 33 CFX_GraphStateData* pData = m_Ref.GetPrivateCopy(); 34 pData->m_DashPhase = phase; 35 } 36 GetLineDashArray() const37std::vector<float> CFX_GraphState::GetLineDashArray() const { 38 std::vector<float> ret; 39 40 if (m_Ref.GetObject()) 41 ret = m_Ref.GetObject()->m_DashArray; 42 43 return ret; 44 } 45 GetLineDashSize() const46size_t CFX_GraphState::GetLineDashSize() const { 47 return m_Ref.GetObject() ? m_Ref.GetObject()->m_DashArray.size() : 0; 48 } 49 GetLineDashPhase() const50float CFX_GraphState::GetLineDashPhase() const { 51 return m_Ref.GetObject() ? m_Ref.GetObject()->m_DashPhase : 1.0f; 52 } 53 GetLineWidth() const54float CFX_GraphState::GetLineWidth() const { 55 return m_Ref.GetObject() ? m_Ref.GetObject()->m_LineWidth : 1.0f; 56 } 57 SetLineWidth(float width)58void CFX_GraphState::SetLineWidth(float width) { 59 m_Ref.GetPrivateCopy()->m_LineWidth = width; 60 } 61 GetLineCap() const62CFX_GraphStateData::LineCap CFX_GraphState::GetLineCap() const { 63 return m_Ref.GetObject() ? m_Ref.GetObject()->m_LineCap 64 : CFX_GraphStateData::LineCap::kButt; 65 } SetLineCap(CFX_GraphStateData::LineCap cap)66void CFX_GraphState::SetLineCap(CFX_GraphStateData::LineCap cap) { 67 m_Ref.GetPrivateCopy()->m_LineCap = cap; 68 } 69 GetLineJoin() const70CFX_GraphStateData::LineJoin CFX_GraphState::GetLineJoin() const { 71 return m_Ref.GetObject() ? m_Ref.GetObject()->m_LineJoin 72 : CFX_GraphStateData::LineJoin::kMiter; 73 } 74 SetLineJoin(CFX_GraphStateData::LineJoin join)75void CFX_GraphState::SetLineJoin(CFX_GraphStateData::LineJoin join) { 76 m_Ref.GetPrivateCopy()->m_LineJoin = join; 77 } 78 GetMiterLimit() const79float CFX_GraphState::GetMiterLimit() const { 80 return m_Ref.GetObject() ? m_Ref.GetObject()->m_MiterLimit : 10.f; 81 } 82 SetMiterLimit(float limit)83void CFX_GraphState::SetMiterLimit(float limit) { 84 m_Ref.GetPrivateCopy()->m_MiterLimit = limit; 85 } 86