Kaydet (Commit) 7bf1e66a authored tarafından Noel Grandin's avatar Noel Grandin

convert AX_FONTDATA to o3tl::typed_flags

Change-Id: If51119fbdde4b1d923b794d126fdae99ca238f81
Reviewed-on: https://gerrit.libreoffice.org/36463Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 93d58279
...@@ -23,22 +23,29 @@ ...@@ -23,22 +23,29 @@
#include <oox/dllapi.h> #include <oox/dllapi.h>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <sal/types.h> #include <sal/types.h>
#include <o3tl/typed_flags_set.hxx>
namespace oox { namespace oox {
class BinaryInputStream; class BinaryInputStream;
class BinaryOutputStream; class BinaryOutputStream;
} }
enum class AxFontFlags {
NONE = 0x00000000,
Bold = 0x00000001,
Italic = 0x00000002,
Underline = 0x00000004,
Strikeout = 0x00000008,
Disabled = 0x00002000,
AutoColor = 0x40000000,
};
namespace o3tl {
template<> struct typed_flags<AxFontFlags> : is_typed_flags<AxFontFlags, 0x4000200f> {};
}
namespace oox { namespace oox {
namespace ole { namespace ole {
const sal_uInt32 AX_FONTDATA_BOLD = 0x00000001;
const sal_uInt32 AX_FONTDATA_ITALIC = 0x00000002;
const sal_uInt32 AX_FONTDATA_UNDERLINE = 0x00000004;
const sal_uInt32 AX_FONTDATA_STRIKEOUT = 0x00000008;
const sal_uInt32 AX_FONTDATA_DISABLED = 0x00002000;
const sal_uInt32 AX_FONTDATA_AUTOCOLOR = 0x40000000;
enum class AxHorizontalAlign { enum class AxHorizontalAlign {
Left = 1, Right = 2, Center = 3 Left = 1, Right = 2, Center = 3
}; };
...@@ -46,8 +53,8 @@ enum class AxHorizontalAlign { ...@@ -46,8 +53,8 @@ enum class AxHorizontalAlign {
/** All entries of a font property. */ /** All entries of a font property. */
struct OOX_DLLPUBLIC AxFontData struct OOX_DLLPUBLIC AxFontData
{ {
OUString maFontName; ///< Name of the used font. OUString maFontName; ///< Name of the used font.
sal_uInt32 mnFontEffects; ///< Font effect flags. AxFontFlags mnFontEffects; ///< Font effect flags.
sal_Int32 mnFontHeight; ///< Height of the font (not really twips, see code). sal_Int32 mnFontHeight; ///< Height of the font (not really twips, see code).
sal_Int32 mnFontCharSet; ///< Windows character set of the font. sal_Int32 mnFontCharSet; ///< Windows character set of the font.
AxHorizontalAlign mnHorAlign; ///< Horizontal text alignment. AxHorizontalAlign mnHorAlign; ///< Horizontal text alignment.
......
...@@ -851,10 +851,14 @@ void AxFontDataModel::importProperty( sal_Int32 nPropId, const OUString& rValue ...@@ -851,10 +851,14 @@ void AxFontDataModel::importProperty( sal_Int32 nPropId, const OUString& rValue
switch( nPropId ) switch( nPropId )
{ {
case XML_FontName: maFontData.maFontName = rValue; break; case XML_FontName: maFontData.maFontName = rValue; break;
case XML_FontEffects: maFontData.mnFontEffects = AttributeConversion::decodeUnsigned( rValue ); break; case XML_FontEffects:
maFontData.mnFontEffects = static_cast<AxFontFlags>(AttributeConversion::decodeUnsigned( rValue ));
break;
case XML_FontHeight: maFontData.mnFontHeight = AttributeConversion::decodeInteger( rValue ); break; case XML_FontHeight: maFontData.mnFontHeight = AttributeConversion::decodeInteger( rValue ); break;
case XML_FontCharSet: maFontData.mnFontCharSet = AttributeConversion::decodeInteger( rValue ); break; case XML_FontCharSet: maFontData.mnFontCharSet = AttributeConversion::decodeInteger( rValue ); break;
case XML_ParagraphAlign: maFontData.mnHorAlign = static_cast<AxHorizontalAlign>(AttributeConversion::decodeInteger( rValue )); break; case XML_ParagraphAlign:
maFontData.mnHorAlign = static_cast<AxHorizontalAlign>(AttributeConversion::decodeInteger( rValue ));
break;
default: AxControlModelBase::importProperty( nPropId, rValue ); default: AxControlModelBase::importProperty( nPropId, rValue );
} }
} }
...@@ -875,10 +879,13 @@ void AxFontDataModel::convertProperties( PropertyMap& rPropMap, const ControlCon ...@@ -875,10 +879,13 @@ void AxFontDataModel::convertProperties( PropertyMap& rPropMap, const ControlCon
rPropMap.setProperty( PROP_FontName, maFontData.maFontName ); rPropMap.setProperty( PROP_FontName, maFontData.maFontName );
// font effects // font effects
rPropMap.setProperty( PROP_FontWeight, getFlagValue( maFontData.mnFontEffects, AX_FONTDATA_BOLD, awt::FontWeight::BOLD, awt::FontWeight::NORMAL ) ); rPropMap.setProperty( PROP_FontWeight, maFontData.mnFontEffects & AxFontFlags::Bold ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL );
rPropMap.setProperty( PROP_FontSlant, getFlagValue( maFontData.mnFontEffects, AX_FONTDATA_ITALIC, FontSlant_ITALIC, FontSlant_NONE ) ); rPropMap.setProperty( PROP_FontSlant, maFontData.mnFontEffects & AxFontFlags::Italic ? FontSlant_ITALIC : FontSlant_NONE );
rPropMap.setProperty( PROP_FontUnderline, getFlagValue( maFontData.mnFontEffects, AX_FONTDATA_UNDERLINE, maFontData.mbDblUnderline ? awt::FontUnderline::DOUBLE : awt::FontUnderline::SINGLE, awt::FontUnderline::NONE ) ); if (maFontData.mnFontEffects & AxFontFlags::Underline)
rPropMap.setProperty( PROP_FontStrikeout, getFlagValue( maFontData.mnFontEffects, AX_FONTDATA_STRIKEOUT, awt::FontStrikeout::SINGLE, awt::FontStrikeout::NONE ) ); rPropMap.setProperty( PROP_FontUnderline, maFontData.mbDblUnderline ? awt::FontUnderline::DOUBLE : awt::FontUnderline::SINGLE );
else
rPropMap.setProperty( PROP_FontUnderline, awt::FontUnderline::NONE );
rPropMap.setProperty( PROP_FontStrikeout, maFontData.mnFontEffects & AxFontFlags::Strikeout ? awt::FontStrikeout::SINGLE : awt::FontStrikeout::NONE );
rPropMap.setProperty( PROP_FontHeight, maFontData.getHeightPoints() ); rPropMap.setProperty( PROP_FontHeight, maFontData.getHeightPoints() );
// font character set // font character set
...@@ -912,17 +919,17 @@ void AxFontDataModel::convertFromProperties( PropertySet& rPropSet, const Contro ...@@ -912,17 +919,17 @@ void AxFontDataModel::convertFromProperties( PropertySet& rPropSet, const Contro
rPropSet.getProperty( maFontData.maFontName, PROP_FontName ); rPropSet.getProperty( maFontData.maFontName, PROP_FontName );
float fontWeight = (float)0; float fontWeight = (float)0;
if ( rPropSet.getProperty(fontWeight, PROP_FontWeight ) ) if ( rPropSet.getProperty(fontWeight, PROP_FontWeight ) )
setFlag( maFontData.mnFontEffects, AX_FONTDATA_BOLD, ( fontWeight == awt::FontWeight::BOLD ) ); setFlag( maFontData.mnFontEffects, AxFontFlags::Bold, ( fontWeight == awt::FontWeight::BOLD ) );
FontSlant nSlant = FontSlant_NONE; FontSlant nSlant = FontSlant_NONE;
if ( rPropSet.getProperty( nSlant, PROP_FontSlant ) ) if ( rPropSet.getProperty( nSlant, PROP_FontSlant ) )
setFlag( maFontData.mnFontEffects, AX_FONTDATA_ITALIC, ( nSlant == FontSlant_ITALIC ) ); setFlag( maFontData.mnFontEffects, AxFontFlags::Italic, ( nSlant == FontSlant_ITALIC ) );
sal_Int16 nUnderLine = awt::FontUnderline::NONE; sal_Int16 nUnderLine = awt::FontUnderline::NONE;
if ( rPropSet.getProperty( nUnderLine, PROP_FontUnderline ) ) if ( rPropSet.getProperty( nUnderLine, PROP_FontUnderline ) )
setFlag( maFontData.mnFontEffects, AX_FONTDATA_UNDERLINE, nUnderLine != awt::FontUnderline::NONE ); setFlag( maFontData.mnFontEffects, AxFontFlags::Underline, nUnderLine != awt::FontUnderline::NONE );
sal_Int16 nStrikeout = awt::FontStrikeout::NONE ; sal_Int16 nStrikeout = awt::FontStrikeout::NONE ;
if ( rPropSet.getProperty( nStrikeout, PROP_FontStrikeout ) ) if ( rPropSet.getProperty( nStrikeout, PROP_FontStrikeout ) )
setFlag( maFontData.mnFontEffects, AX_FONTDATA_STRIKEOUT, nStrikeout != awt::FontStrikeout::NONE ); setFlag( maFontData.mnFontEffects, AxFontFlags::Strikeout, nStrikeout != awt::FontStrikeout::NONE );
float fontHeight = 0.0; float fontHeight = 0.0;
if ( rPropSet.getProperty( fontHeight, PROP_FontHeight ) ) if ( rPropSet.getProperty( fontHeight, PROP_FontHeight ) )
......
...@@ -26,7 +26,7 @@ namespace oox { ...@@ -26,7 +26,7 @@ namespace oox {
namespace ole { namespace ole {
AxFontData::AxFontData() : AxFontData::AxFontData() :
mnFontEffects( 0 ), mnFontEffects( AxFontFlags::NONE ),
mnFontHeight( 160 ), mnFontHeight( 160 ),
mnFontCharSet( WINDOWS_CHARSET_DEFAULT ), mnFontCharSet( WINDOWS_CHARSET_DEFAULT ),
mnHorAlign( AxHorizontalAlign::Left ), mnHorAlign( AxHorizontalAlign::Left ),
...@@ -51,7 +51,9 @@ bool AxFontData::importBinaryModel( BinaryInputStream& rInStrm ) ...@@ -51,7 +51,9 @@ bool AxFontData::importBinaryModel( BinaryInputStream& rInStrm )
{ {
AxBinaryPropertyReader aReader( rInStrm ); AxBinaryPropertyReader aReader( rInStrm );
aReader.readStringProperty( maFontName ); aReader.readStringProperty( maFontName );
aReader.readIntProperty< sal_uInt32 >( mnFontEffects ); sal_uInt32 nTmp32 = 0;
aReader.readIntProperty< sal_uInt32 >( nTmp32 );
mnFontEffects = static_cast<AxFontFlags>(nTmp32);
aReader.readIntProperty< sal_Int32 >( mnFontHeight ); aReader.readIntProperty< sal_Int32 >( mnFontHeight );
aReader.skipIntProperty< sal_Int32 >(); // font offset aReader.skipIntProperty< sal_Int32 >(); // font offset
aReader.readIntProperty< sal_uInt8 >( mnFontCharSet ); aReader.readIntProperty< sal_uInt8 >( mnFontCharSet );
...@@ -68,7 +70,7 @@ void AxFontData::exportBinaryModel( BinaryOutputStream& rOutStrm ) ...@@ -68,7 +70,7 @@ void AxFontData::exportBinaryModel( BinaryOutputStream& rOutStrm )
{ {
AxBinaryPropertyWriter aWriter( rOutStrm ); AxBinaryPropertyWriter aWriter( rOutStrm );
aWriter.writeStringProperty( maFontName ); aWriter.writeStringProperty( maFontName );
aWriter.writeIntProperty< sal_uInt32 >( mnFontEffects ); aWriter.writeIntProperty< sal_uInt32 >( static_cast<sal_uInt32>(mnFontEffects) );
aWriter.writeIntProperty< sal_Int32 >( mnFontHeight ); aWriter.writeIntProperty< sal_Int32 >( mnFontHeight );
aWriter.skipProperty(); // font offset aWriter.skipProperty(); // font offset
// TODO make AxFontDataModel::convertFromProperties convert the textencoding // TODO make AxFontDataModel::convertFromProperties convert the textencoding
...@@ -86,11 +88,11 @@ bool AxFontData::importStdFont( BinaryInputStream& rInStrm ) ...@@ -86,11 +88,11 @@ bool AxFontData::importStdFont( BinaryInputStream& rInStrm )
if( OleHelper::importStdFont( aFontInfo, rInStrm, false ) ) if( OleHelper::importStdFont( aFontInfo, rInStrm, false ) )
{ {
maFontName = aFontInfo.maName; maFontName = aFontInfo.maName;
mnFontEffects = 0; mnFontEffects = AxFontFlags::NONE;
setFlag( mnFontEffects, AX_FONTDATA_BOLD, aFontInfo.mnWeight >= OLE_STDFONT_BOLD ); setFlag( mnFontEffects, AxFontFlags::Bold, aFontInfo.mnWeight >= OLE_STDFONT_BOLD );
setFlag( mnFontEffects, AX_FONTDATA_ITALIC, getFlag( aFontInfo.mnFlags, OLE_STDFONT_ITALIC ) ); setFlag( mnFontEffects, AxFontFlags::Italic, getFlag( aFontInfo.mnFlags, OLE_STDFONT_ITALIC ) );
setFlag( mnFontEffects, AX_FONTDATA_UNDERLINE, getFlag( aFontInfo.mnFlags, OLE_STDFONT_UNDERLINE ) ); setFlag( mnFontEffects, AxFontFlags::Underline, getFlag( aFontInfo.mnFlags, OLE_STDFONT_UNDERLINE ) );
setFlag( mnFontEffects, AX_FONTDATA_STRIKEOUT, getFlag( aFontInfo.mnFlags,OLE_STDFONT_STRIKE ) ); setFlag( mnFontEffects, AxFontFlags::Strikeout, getFlag( aFontInfo.mnFlags,OLE_STDFONT_STRIKE ) );
mbDblUnderline = false; mbDblUnderline = false;
// StdFont stores font height in 1/10,000 of points // StdFont stores font height in 1/10,000 of points
setHeightPoints( getLimitedValue< sal_Int16, sal_Int32 >( aFontInfo.mnHeight / 10000, 0, SAL_MAX_INT16 ) ); setHeightPoints( getLimitedValue< sal_Int16, sal_Int32 >( aFontInfo.mnHeight / 10000, 0, SAL_MAX_INT16 ) );
......
...@@ -711,12 +711,12 @@ void VmlDrawing::convertControlFontData( AxFontData& rAxFontData, sal_uInt32& rn ...@@ -711,12 +711,12 @@ void VmlDrawing::convertControlFontData( AxFontData& rAxFontData, sal_uInt32& rn
rAxFontData.setHeightPoints( static_cast< sal_Int16 >( (rFontModel.monSize.get( 200 ) + 10) / 20 ) ); rAxFontData.setHeightPoints( static_cast< sal_Int16 >( (rFontModel.monSize.get( 200 ) + 10) / 20 ) );
// font effects // font effects
rAxFontData.mnFontEffects = 0; rAxFontData.mnFontEffects = AxFontFlags::NONE;
setFlag( rAxFontData.mnFontEffects, AX_FONTDATA_BOLD, rFontModel.mobBold.get( false ) ); setFlag( rAxFontData.mnFontEffects, AxFontFlags::Bold, rFontModel.mobBold.get( false ) );
setFlag( rAxFontData.mnFontEffects, AX_FONTDATA_ITALIC, rFontModel.mobItalic.get( false ) ); setFlag( rAxFontData.mnFontEffects, AxFontFlags::Italic, rFontModel.mobItalic.get( false ) );
setFlag( rAxFontData.mnFontEffects, AX_FONTDATA_STRIKEOUT, rFontModel.mobStrikeout.get( false ) ); setFlag( rAxFontData.mnFontEffects, AxFontFlags::Strikeout, rFontModel.mobStrikeout.get( false ) );
sal_Int32 nUnderline = rFontModel.monUnderline.get( XML_none ); sal_Int32 nUnderline = rFontModel.monUnderline.get( XML_none );
setFlag( rAxFontData.mnFontEffects, AX_FONTDATA_UNDERLINE, nUnderline != XML_none ); setFlag( rAxFontData.mnFontEffects, AxFontFlags::Underline, nUnderline != XML_none );
rAxFontData.mbDblUnderline = nUnderline == XML_double; rAxFontData.mbDblUnderline = nUnderline == XML_double;
// font color // font color
......
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