1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #include <sal/log.hxx> 21 #include "emfpcustomlinecap.hxx" 22 #include "emfppath.hxx" 23 #include "emfppen.hxx" 24 25 using namespace ::com::sun::star; 26 using namespace ::basegfx; 27 28 namespace emfplushelper 29 { 30 const sal_uInt32 EmfPlusCustomLineCapDataTypeDefault = 0x00000000; 31 const sal_uInt32 EmfPlusCustomLineCapDataTypeAdjustableArrow = 0x00000001; 32 const sal_uInt32 EmfPlusCustomLineCapDataFillPath = 0x00000001; 33 const sal_uInt32 EmfPlusCustomLineCapDataLinePath = 0x00000002; 34 EMFPCustomLineCap()35 EMFPCustomLineCap::EMFPCustomLineCap() 36 : EMFPObject() 37 , type(0) 38 , strokeStartCap(0) 39 , strokeEndCap(0) 40 , strokeJoin(0) 41 , miterLimit(0.0) 42 , mbIsFilled(false) 43 { 44 } 45 SetAttributes(rendering::StrokeAttributes & aAttributes)46 void EMFPCustomLineCap::SetAttributes(rendering::StrokeAttributes& aAttributes) 47 { 48 aAttributes.StartCapType = EMFPPen::lcl_convertStrokeCap(strokeStartCap); 49 aAttributes.EndCapType = EMFPPen::lcl_convertStrokeCap(strokeEndCap); 50 aAttributes.JoinType = EMFPPen::lcl_convertLineJoinType(strokeJoin); 51 52 aAttributes.MiterLimit = miterLimit; 53 } 54 ReadPath(SvStream & s,EmfPlusHelperData const & rR,bool bFill)55 void EMFPCustomLineCap::ReadPath(SvStream& s, EmfPlusHelperData const & rR, bool bFill) 56 { 57 sal_Int32 pathLength; 58 s.ReadInt32(pathLength); 59 SAL_INFO("drawinglayer", "EMF+\t\tpath length: " << pathLength); 60 sal_uInt32 pathHeader; 61 sal_Int32 pathPoints, pathFlags; 62 s.ReadUInt32(pathHeader).ReadInt32(pathPoints).ReadInt32(pathFlags); 63 SAL_INFO("drawinglayer", "EMF+\t\tpath (custom cap line path)"); 64 SAL_INFO("drawinglayer", "EMF+\t\theader: 0x" << std::hex << pathHeader << " points: " << std::dec << pathPoints << " additional flags: 0x" << std::hex << pathFlags << std::dec); 65 66 EMFPPath path(pathPoints); 67 path.Read(s, pathFlags); 68 polygon = path.GetPolygon(rR, false); 69 mbIsFilled = bFill; 70 } 71 Read(SvStream & s,EmfPlusHelperData const & rR)72 void EMFPCustomLineCap::Read(SvStream& s, EmfPlusHelperData const & rR) 73 { 74 sal_uInt32 header; 75 s.ReadUInt32(header).ReadUInt32(type); 76 SAL_INFO("drawinglayer", "EMF+\t\tcustom cap"); 77 SAL_INFO("drawinglayer", "EMF+\t\theader: 0x" << std::hex << header << " type: " << type << std::dec); 78 79 if (type == EmfPlusCustomLineCapDataTypeDefault) 80 { 81 sal_uInt32 customLineCapDataFlags, baseCap; 82 float baseInset; 83 float widthScale; 84 float fillHotSpotX, fillHotSpotY, strokeHotSpotX, strokeHotSpotY; 85 86 s.ReadUInt32(customLineCapDataFlags).ReadUInt32(baseCap).ReadFloat(baseInset) 87 .ReadUInt32(strokeStartCap).ReadUInt32(strokeEndCap).ReadUInt32(strokeJoin) 88 .ReadFloat(miterLimit).ReadFloat(widthScale) 89 .ReadFloat(fillHotSpotX).ReadFloat(fillHotSpotY).ReadFloat(strokeHotSpotX).ReadFloat(strokeHotSpotY); 90 91 SAL_INFO("drawinglayer", "EMF+\t\tcustomLineCapDataFlags: 0x" << std::hex << customLineCapDataFlags); 92 SAL_INFO("drawinglayer", "EMF+\t\tbaseCap: 0x" << std::hex << baseCap); 93 SAL_INFO("drawinglayer", "EMF+\t\tbaseInset: " << baseInset); 94 SAL_INFO("drawinglayer", "EMF+\t\tstrokeStartCap: 0x" << std::hex << strokeStartCap); 95 SAL_INFO("drawinglayer", "EMF+\t\tstrokeEndCap: 0x" << std::hex << strokeEndCap); 96 SAL_INFO("drawinglayer", "EMF+\t\tstrokeJoin: 0x" << std::hex << strokeJoin); 97 SAL_INFO("drawinglayer", "EMF+\t\tmiterLimit: " << miterLimit); 98 SAL_INFO("drawinglayer", "EMF+\t\twidthScale: " << widthScale); 99 100 if (customLineCapDataFlags & EmfPlusCustomLineCapDataFillPath) 101 { 102 ReadPath(s, rR, true); 103 } 104 105 if (customLineCapDataFlags & EmfPlusCustomLineCapDataLinePath) 106 { 107 ReadPath(s, rR, false); 108 } 109 } 110 else if (type == EmfPlusCustomLineCapDataTypeAdjustableArrow) 111 { 112 // TODO only reads the data, does not use them [I've had 113 // no test document to be able to implement it] 114 115 sal_Int32 width, height, middleInset, fillState, lineStartCap; 116 sal_Int32 lineEndCap, lineJoin, widthScale; 117 float fillHotSpotX, fillHotSpotY, lineHotSpotX, lineHotSpotY; 118 119 s.ReadInt32(width).ReadInt32(height).ReadInt32(middleInset).ReadInt32(fillState).ReadInt32(lineStartCap) 120 .ReadInt32(lineEndCap).ReadInt32(lineJoin).ReadFloat(miterLimit).ReadInt32(widthScale) 121 .ReadFloat(fillHotSpotX).ReadFloat(fillHotSpotY).ReadFloat(lineHotSpotX).ReadFloat(lineHotSpotY); 122 123 SAL_INFO("drawinglayer", "EMF+\t\tTODO - actually read EmfPlusCustomLineCapArrowData object (section 2.2.2.12)"); 124 } 125 } 126 } 127 128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 129