relative sizes to resize fonts without changing the model

This commit is contained in:
Björn Milcke 2003-11-12 18:41:43 +00:00
parent 17f9b5a09c
commit 90dcbd3955
8 changed files with 254 additions and 19 deletions

View file

@ -0,0 +1,87 @@
/*************************************************************************
*
* $RCSfile: RelativeSizeHelper.hxx,v $
*
* $Revision: 1.1 $
*
* last change: $Author: bm $ $Date: 2003-11-12 19:41:34 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (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.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2003 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#ifndef CHART2_RELATIVESIZEHELPER_HXX
#define CHART2_RELATIVESIZEHELPER_HXX
#ifndef _COM_SUN_STAR_AWT_SIZE_HPP_
#include <com/sun/star/awt/Size.hpp>
#endif
namespace chart
{
class RelativeSizeHelper
{
public:
static double calculate(
const ::com::sun::star::awt::Size & rOldReferenceSize,
const ::com::sun::star::awt::Size & rNewReferenceSize,
double fValue );
private:
// not implemented
RelativeSizeHelper();
};
} // namespace chart
// CHART2_RELATIVESIZEHELPER_HXX
#endif

View file

@ -2,9 +2,9 @@
*
* $RCSfile: Legend.cxx,v $
*
* $Revision: 1.6 $
* $Revision: 1.7 $
*
* last change: $Author: bm $ $Date: 2003-10-29 09:49:09 $
* last change: $Author: bm $ $Date: 2003-11-12 19:41:35 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -74,6 +74,9 @@
#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
#include <com/sun/star/beans/PropertyAttribute.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_SIZE_HPP_
#include <com/sun/star/awt/Size.hpp>
#endif
#ifndef _DRAFTS_COM_SUN_STAR_LAYOUT_ALIGNMENT_HPP_
#include <drafts/com/sun/star/layout/Alignment.hpp>
@ -106,7 +109,8 @@ enum
{
PROP_LEGEND_POSITION,
PROP_LEGEND_PREFERRED_EXPANSION,
PROP_LEGEND_SHOW
PROP_LEGEND_SHOW,
PROP_LEGEND_REF_PAGE_SIZE
};
void lcl_AddPropertiesToVector(
@ -132,6 +136,12 @@ void lcl_AddPropertiesToVector(
::getBooleanCppuType(),
beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::MAYBEDEFAULT ));
rOutProperties.push_back(
Property( C2U( "ReferencePageSize" ),
PROP_LEGEND_REF_PAGE_SIZE,
::getCppuType( reinterpret_cast< const awt::Size * >(0)),
beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::MAYBEVOID ));
}
void lcl_AddDefaultsToMap(
@ -144,6 +154,11 @@ void lcl_AddDefaultsToMap(
OSL_ASSERT( rOutMap.end() == rOutMap.find( PROP_LEGEND_SHOW ));
rOutMap[ PROP_LEGEND_SHOW ] =
uno::makeAny( sal_True );
// todo: default is just for testing. should be void
OSL_ASSERT( rOutMap.end() == rOutMap.find( PROP_LEGEND_REF_PAGE_SIZE ));
rOutMap[ PROP_LEGEND_REF_PAGE_SIZE ] =
uno::makeAny( awt::Size( 20000, 15000 ) );
}
const uno::Sequence< Property > & lcl_GetPropertySequence()

View file

@ -2,9 +2,9 @@
*
* $RCSfile: Title.cxx,v $
*
* $Revision: 1.1.1.1 $
* $Revision: 1.2 $
*
* last change: $Author: bm $ $Date: 2003-10-06 09:58:31 $
* last change: $Author: bm $ $Date: 2003-11-12 19:41:36 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -81,6 +81,9 @@
#ifndef _COM_SUN_STAR_DRAWING_LINESTYLE_HPP_
#include <com/sun/star/drawing/LineStyle.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_SIZE_HPP_
#include <com/sun/star/awt/Size.hpp>
#endif
#ifndef _RTL_UUID_H_
#include <rtl/uuid.h>
@ -116,7 +119,8 @@ enum
PROP_TITLE_PARA_IS_HYPHENATION,
PROP_TITLE_TEXT_ROTATION,
PROP_TITLE_TEXT_STACKED
PROP_TITLE_TEXT_STACKED,
PROP_TITLE_REF_PAGE_SIZE
};
void lcl_AddPropertiesToVector(
@ -183,6 +187,12 @@ void lcl_AddPropertiesToVector(
::getBooleanCppuType(),
beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::MAYBEDEFAULT ));
rOutProperties.push_back(
Property( C2U( "ReferencePageSize" ),
PROP_TITLE_REF_PAGE_SIZE,
::getCppuType( reinterpret_cast< const awt::Size * >(0)),
beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::MAYBEVOID ));
}
void lcl_AddDefaultsToMap(
@ -219,6 +229,11 @@ void lcl_AddDefaultsToMap(
rOutMap[ PROP_TITLE_TEXT_STACKED ] =
uno::makeAny( sal_Bool( sal_False ) );
// todo: default is just for testing. should be void
OSL_ASSERT( rOutMap.end() == rOutMap.find( PROP_TITLE_REF_PAGE_SIZE ));
rOutMap[ PROP_TITLE_REF_PAGE_SIZE ] =
uno::makeAny( awt::Size( 3000, 2000 ) );
// override other defaults
rOutMap[ ::chart::FillProperties::PROP_FILL_STYLE ] =
uno::makeAny( drawing::FillStyle_NONE );

View file

@ -0,0 +1,86 @@
/*************************************************************************
*
* $RCSfile: RelativeSizeHelper.cxx,v $
*
* $Revision: 1.1 $
*
* last change: $Author: bm $ $Date: 2003-11-12 19:41:37 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (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.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2003 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#include "RelativeSizeHelper.hxx"
#include <algorithm>
using namespace ::com::sun::star::awt;
namespace chart
{
// static
double RelativeSizeHelper::calculate(
const Size & rOldReferenceSize,
const Size & rNewReferenceSize,
double fValue )
{
if( rOldReferenceSize.Width <= 0 ||
rOldReferenceSize.Height <= 0 )
return fValue;
return ::std::min(
static_cast< double >( rNewReferenceSize.Width ) / static_cast< double >( rOldReferenceSize.Width ),
static_cast< double >( rNewReferenceSize.Height ) / static_cast< double >( rOldReferenceSize.Height ))
* fValue;
}
} // namespace chart

View file

@ -2,9 +2,9 @@
#
# $RCSfile: makefile.mk,v $
#
# $Revision: 1.6 $
# $Revision: 1.7 $
#
# last change: $Author: bm $ $Date: 2003-11-11 12:19:19 $
# last change: $Author: bm $ $Date: 2003-11-12 19:41:39 $
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
@ -94,6 +94,7 @@ SLOFILES= \
$(SLO)$/OIndexContainer.obj \
$(SLO)$/OPropertySet.obj \
$(SLO)$/OStyle.obj \
$(SLO)$/RelativeSizeHelper.obj \
$(SLO)$/Scaling.obj \
$(SLO)$/ChartModelHelper.obj \
$(SLO)$/ChartTypeHelper.obj \

View file

@ -2,9 +2,9 @@
*
* $RCSfile: ChartView.cxx,v $
*
* $Revision: 1.13 $
* $Revision: 1.14 $
*
* last change: $Author: iha $ $Date: 2003-11-08 22:51:06 $
* last change: $Author: bm $ $Date: 2003-11-12 19:41:41 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -583,7 +583,8 @@ void createLegend( const uno::Reference< XLegend > & xLegend
{
VLegend aVLegend( xLegend );
aVLegend.init( xPageShapes, xShapeFactory );
aVLegend.createShapes( awt::Size( rOutSpaceLeft.Width, rOutSpaceLeft.Height ) );
aVLegend.createShapes( awt::Size( rOutSpaceLeft.Width, rOutSpaceLeft.Height ),
rPageSize );
aVLegend.changePosition( rOutSpaceLeft, rPageSize );
}
}

View file

@ -2,9 +2,9 @@
*
* $RCSfile: VLegend.cxx,v $
*
* $Revision: 1.20 $
* $Revision: 1.21 $
*
* last change: $Author: bm $ $Date: 2003-11-04 12:37:45 $
* last change: $Author: bm $ $Date: 2003-11-12 19:41:42 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -66,6 +66,7 @@
#include "chartview/ObjectIdentifier.hxx"
#include "LayoutHelper.hxx"
#include "ShapeFactory.hxx"
#include "RelativeSizeHelper.hxx"
#ifndef _COM_SUN_STAR_TEXT_XTEXTRANGE_HPP_
#include <com/sun/star/text/XTextRange.hpp>
@ -189,7 +190,8 @@ void lcl_getProperties(
const uno::Reference< beans::XPropertySet > & xLegendProp,
tPropertyValues & rOutLineFillProperties,
tPropertyValues & rOutTextProperties,
sal_Int32 nMaxLabelWidth )
sal_Int32 nMaxLabelWidth,
const awt::Size & rReferenceSize )
{
// Get Line- and FillProperties from model legend
if( xLegendProp.is())
@ -217,6 +219,31 @@ void lcl_getProperties(
aTextValueMap[ C2U("TextHorizontalAdjust") ] = uno::makeAny( eHorizAdjust );
aTextValueMap[ C2U("TextMaximumFrameWidth") ] = uno::makeAny( nMaxLabelWidth );
// recalculate font size
awt::Size aPropRefSize;
float fFontHeight;
if( (xLegendProp->getPropertyValue( C2U( "ReferencePageSize" )) >>= aPropRefSize) &&
(aPropRefSize.Height > 0) &&
(aTextValueMap[ C2U("CharHeight") ] >>= fFontHeight) )
{
aTextValueMap[ C2U("CharHeight") ] = uno::makeAny(
static_cast< double >(
::chart::RelativeSizeHelper::calculate( aPropRefSize, rReferenceSize, fFontHeight )));
if( aTextValueMap[ C2U("CharHeightAsian") ] >>= fFontHeight )
{
aTextValueMap[ C2U("CharHeightAsian") ] = uno::makeAny(
static_cast< double >(
::chart::RelativeSizeHelper::calculate( aPropRefSize, rReferenceSize, fFontHeight )));
}
if( aTextValueMap[ C2U("CharHeightComplex") ] >>= fFontHeight )
{
aTextValueMap[ C2U("CharHeightComplex") ] = uno::makeAny(
static_cast< double >(
::chart::RelativeSizeHelper::calculate( aPropRefSize, rReferenceSize, fFontHeight )));
}
}
::chart::PropertyMapper::getMultiPropertyListsFromValueMap(
rOutTextProperties.first, rOutTextProperties.second, aTextValueMap );
}
@ -592,7 +619,8 @@ bool VLegend::isVisible( const uno::Reference< chart2::XLegend > & xLegend )
// ----------------------------------------
void VLegend::createShapes(
const awt::Size & rAvailableSpace )
const awt::Size & rAvailableSpace,
const awt::Size & rPageSize )
{
if(! (m_xLegend.is() &&
m_xShapeFactory.is() &&
@ -640,7 +668,8 @@ void VLegend::createShapes(
{
// limit the width of texts to 20% of the total available width
sal_Int32 nMaxLabelWidth = rAvailableSpace.Width / 5;
lcl_getProperties( xLegendProp, aLineFillProperties, aTextProperties, nMaxLabelWidth );
lcl_getProperties( xLegendProp, aLineFillProperties, aTextProperties, nMaxLabelWidth,
rPageSize );
// get Expansion property
xLegendProp->getPropertyValue( C2U( "Expansion" )) >>= eExpansion;

View file

@ -2,9 +2,9 @@
*
* $RCSfile: VLegend.hxx,v $
*
* $Revision: 1.9 $
* $Revision: 1.10 $
*
* last change: $Author: bm $ $Date: 2003-10-28 16:15:53 $
* last change: $Author: bm $ $Date: 2003-11-12 19:41:43 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -100,7 +100,8 @@ public:
const ::com::sun::star::uno::Reference<
::com::sun::star::lang::XMultiServiceFactory >& xFactory );
void createShapes( const ::com::sun::star::awt::Size & rAvailableSpace );
void createShapes( const ::com::sun::star::awt::Size & rAvailableSpace,
const ::com::sun::star::awt::Size & rPageSize );
/** Sets the position according to its internal anchor.