Kaydet (Commit) f9af0abc authored tarafından Bartosz Kosiorek's avatar Bartosz Kosiorek

EMF+ Add initial support for EmfPlusStringFormat Object

The EmfPlusStringFormat object specifies text layout, display manipulations,
and language identification. With this commit the support for font language
and country was added. Also Bold style is applied,
for strings which needs that.

Change-Id: Id9735a9ddb959aebd20d6d4d1bb5da0fa9c1fb85
Reviewed-on: https://gerrit.libreoffice.org/36555Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarBartosz Kosiorek <gang65@poczta.onet.pl>
üst bf286d12
......@@ -62,6 +62,7 @@ $(eval $(call gb_Library_add_exception_objects,cppcanvas,\
cppcanvas/source/mtfrenderer/mtftools \
cppcanvas/source/mtfrenderer/pointaction \
cppcanvas/source/mtfrenderer/polypolyaction \
cppcanvas/source/mtfrenderer/emfpstringformat \
cppcanvas/source/mtfrenderer/textaction \
cppcanvas/source/mtfrenderer/transparencygroupaction \
cppcanvas/source/tools/canvasgraphichelper \
......
......@@ -28,6 +28,9 @@
#include <action.hxx>
#include <outdevstate.hxx>
#include <com/sun/star/rendering/FontRequest.hpp>
#include <com/sun/star/rendering/StrokeAttributes.hpp>
#include <osl/endian.h>
#include <vector>
......@@ -274,7 +277,7 @@ static float GetSwapFloat( SvStream& rSt )
/* EMF+ */
void processEMFPlus( MetaCommentAction* pAct, const ActionFactoryParameters& rFactoryParms, OutDevState& rState, const CanvasSharedPtr& rCanvas );
double setFont( sal_uInt8 objectId, const ActionFactoryParameters& rParms, OutDevState& rState );
double setFont(css::rendering::FontRequest& aFontRequest, sal_uInt8 fontObjectId, const ActionFactoryParameters& rParms, OutDevState& rState );
/// Render LineCap, like the start or end arrow of a polygon.
/// @return how much we should shorten the original polygon.
......
......@@ -36,9 +36,9 @@
#include <basegfx/polygon/b2dpolypolygontools.hxx>
#include <vcl/canvastools.hxx>
#include <rtl/ustring.hxx>
#include <i18nlangtag/languagetag.hxx>
#include <com/sun/star/rendering/PathCapType.hpp>
#include <com/sun/star/rendering/PathJoinType.hpp>
#include <com/sun/star/rendering/PanoseWeight.hpp>
#include <com/sun/star/rendering/TexturingMode.hpp>
#include <com/sun/star/rendering/XCanvas.hpp>
......@@ -55,6 +55,7 @@
#include <emfppath.hxx>
#include <emfppen.hxx>
#include <emfpregion.hxx>
#include <emfpstringformat.hxx>
namespace
{
......@@ -139,6 +140,15 @@ enum EmfPlusCombineMode
EmfPlusCombineModeComplement = 0x00000005
};
enum EmfPlusFontStyle
{
FontStyleBold = 0x00000001,
FontStyleItalic = 0x00000002,
FontStyleUnderline = 0x00000004,
FontStyleStrikeout = 0x00000008
};
const char* emfTypeToName(sal_uInt16 type)
{
switch(type)
......@@ -747,6 +757,10 @@ namespace cppcanvas
}
case EmfPlusObjectTypeStringFormat:
{
EMFPStringFormat *stringFormat;
aObjects [index] = stringFormat = new EMFPStringFormat();
stringFormat->Read (rObjectStream);
SAL_INFO("cppcanvas.emf", "EMF+\t Object type 'string format' not yet implemented");
break;
}
......@@ -766,13 +780,16 @@ namespace cppcanvas
}
}
double ImplRenderer::setFont (sal_uInt8 objectId, const ActionFactoryParameters& rParms, OutDevState& rState)
double ImplRenderer::setFont (css::rendering::FontRequest& aFontRequest, sal_uInt8 fontObjectId, const ActionFactoryParameters& rParms, OutDevState& rState)
{
EMFPFont *font = static_cast<EMFPFont*>( aObjects[ objectId ] );
EMFPFont *font = static_cast< EMFPFont* >( aObjects[ fontObjectId ] );
rendering::FontRequest aFontRequest;
aFontRequest.FontDescription.FamilyName = font->family;
double cellSize = font->emSize;
if( font->fontFlags & FontStyleBold )
{
aFontRequest.FontDescription.FontDescription.Weight = rendering::PanoseWeight::BOLD;
}
aFontRequest.CellSize = (rState.mapModeTransform*MapSize( cellSize, 0 )).getX();
rState.xFont = rParms.mrCanvas->getUNOCanvas()->createFont( aFontRequest,
uno::Sequence< beans::PropertyValue >(),
......@@ -1252,7 +1269,13 @@ namespace cppcanvas
OUString text = read_uInt16s_ToOUString(rMF, stringLength);
double cellSize = setFont (flags & 0xff, rFactoryParms, rState);
EMFPStringFormat *stringFormat = static_cast< EMFPStringFormat* >( aObjects[ formatId ] );
css::rendering::FontRequest aFontRequest;
LanguageTag aLanguageTag( static_cast< LanguageType >( stringFormat->language ) );
aFontRequest.Locale = aLanguageTag.getLocale( false );
SAL_INFO("cppcanvas.emf", "EMF+\t\t Font locale, Country:" << aLanguageTag.getCountry() <<" Language:" << aLanguageTag.getLanguage() );
double cellSize = setFont (aFontRequest, flags & 0xff, rFactoryParms, rState);
rState.textColor = COLOR( brushId );
::basegfx::B2DPoint point( Map( lx + 0.15*cellSize, ly + cellSize ) );
......@@ -1555,8 +1578,9 @@ namespace cppcanvas
SAL_INFO("cppcanvas.emf", "EMF+\tmatrix: " << transform.eM11 << ", " << transform.eM12 << ", " << transform.eM21 << ", " << transform.eM22 << ", " << transform.eDx << ", " << transform.eDy);
}
rendering::FontRequest aFontRequest;
// add the text action
setFont (flags & 0xff, rFactoryParms, rState);
setFont (aFontRequest, flags & 0xff, rFactoryParms, rState);
if( flags & 0x8000 )
rState.textColor = COLOR( brushIndexOrColor );
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <com/sun/star/rendering/XCanvas.hpp>
#include <vcl/canvastools.hxx>
#include <implrenderer.hxx>
#include <emfpstringformat.hxx>
namespace cppcanvas
{
namespace internal
{
EMFPStringFormat::EMFPStringFormat()
: header(0)
, stringFormatFlags(0)
, language(0)
, stringAlignment(0)
, lineAlign(0)
, digitSubstitution(0)
, digitLanguage(0)
, firstTabOffset(0.0)
, hotkeyPrefix(0)
, leadingMargin(0.0)
, trailingMargin(0.0)
, tracking(0.0)
, trimming(0)
, tabStopCount(0)
, rangeCount(0)
{
}
void EMFPStringFormat::Read(SvMemoryStream &s)
{
s.ReadUInt32(header).ReadUInt32(stringFormatFlags).ReadUInt32(language);
s.ReadUInt32(stringAlignment).ReadUInt32(lineAlign).ReadUInt32(digitSubstitution).ReadUInt32(digitLanguage);
s.ReadFloat(firstTabOffset).ReadInt32(hotkeyPrefix).ReadFloat(leadingMargin).ReadFloat(trailingMargin).ReadFloat(tracking);
s.ReadInt32(trimming).ReadInt32(tabStopCount).ReadInt32(rangeCount);
OSL_ASSERT((header >> 12) == 0xdbc01);
SAL_INFO("cppcanvas.emf", "EMF+\t string format\nEMF+\theader: 0x" << std::hex << (header >> 12) << " version: 0x" << (header & 0x1fff) << " StringFormatFlags: " << std::dec << stringFormatFlags << " Language: " << language);
SAL_INFO("cppcanvas.emf", "EMF+\t StringAlignment: " << stringAlignment << " LineAlign: " << lineAlign << " DigitSubstitution: " << digitSubstitution << " DigitLanguage: " << digitLanguage);
SAL_INFO("cppcanvas.emf", "EMF+\t FirstTabOffset: " << firstTabOffset << " HotkeyPrefix: " << hotkeyPrefix << " LeadingMargin: " << leadingMargin << " TrailingMargin: " << trailingMargin << " Tracking: " << tracking);
SAL_INFO("cppcanvas.emf", "EMF+\t Trimming: " << trimming << " TabStopCount: " << tabStopCount << " RangeCount: " << rangeCount);
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_CPPCANVAS_SOURCE_MTFRENDERER_EMFPSTRINGFORMAT_HXX
#define INCLUDED_CPPCANVAS_SOURCE_MTFRENDERER_EMFPSTRINGFORMAT_HXX
namespace cppcanvas
{
namespace internal
{
struct EMFPStringFormat : public EMFPObject
{
sal_uInt32 header;
sal_uInt32 stringFormatFlags;
sal_uInt32 language;
sal_uInt32 stringAlignment;
sal_uInt32 lineAlign;
sal_uInt32 digitSubstitution;
sal_uInt32 digitLanguage;
float firstTabOffset;
sal_Int32 hotkeyPrefix;
float leadingMargin;
float trailingMargin;
float tracking;
sal_Int32 trimming;
sal_Int32 tabStopCount;
sal_Int32 rangeCount;
EMFPStringFormat();
void Read(SvMemoryStream &s);
};
}
}
#endif // INCLUDED_CPPCANVAS_SOURCE_MTFRENDERER_EMFPSTRINGFORMAT_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment