Kaydet (Commit) 374d581a authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Some code sharing.

Change-Id: If80c4b0ceec5e0afd55d12ebe7511fb4f40b4797
üst 519634b3
...@@ -412,6 +412,13 @@ bool AxisLabelProperties::isStaggered() const ...@@ -412,6 +412,13 @@ bool AxisLabelProperties::isStaggered() const
return ( STAGGER_ODD == eStaggering || STAGGER_EVEN == eStaggering ); return ( STAGGER_ODD == eStaggering || STAGGER_EVEN == eStaggering );
} }
void AxisLabelProperties::autoRotate45()
{
fRotationAngleDegree = 45;
bLineBreakAllowed = false;
eStaggering = SIDE_BY_SIDE;
}
} //namespace chart } //namespace chart
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -82,6 +82,8 @@ struct AxisLabelProperties SAL_FINAL ...@@ -82,6 +82,8 @@ struct AxisLabelProperties SAL_FINAL
::com::sun::star::chart2::XAxis >& xAxisModel ); ::com::sun::star::chart2::XAxis >& xAxisModel );
bool isStaggered() const; bool isStaggered() const;
void autoRotate45();
}; };
struct AxisLabelAlignment struct AxisLabelAlignment
......
...@@ -365,6 +365,47 @@ bool lcl_hasWordBreak( const Reference<drawing::XShape>& xShape ) ...@@ -365,6 +365,47 @@ bool lcl_hasWordBreak( const Reference<drawing::XShape>& xShape )
return false; return false;
} }
OUString getTextLabelString(
const FixedNumberFormatter& rFixedNumberFormatter, const uno::Sequence<OUString>* pCategories,
const TickInfo* pTickInfo, bool bComplexCat, sal_Int32& rExtraColor, bool& rHasExtraColor )
{
if (pCategories)
{
// This is a normal category axis. Get the label string from the
// label string array.
sal_Int32 nIndex = static_cast<sal_Int32>(pTickInfo->getUnscaledTickValue()) - 1; //first category (index 0) matches with real number 1.0
if( nIndex>=0 && nIndex<pCategories->getLength() )
return (*pCategories)[nIndex];
return OUString();
}
else if (bComplexCat)
{
// This is a complex category axis. The label is stored in the tick.
return pTickInfo->aText;
}
// This is a numeric axis. Format the original tick value per number format.
return rFixedNumberFormatter.getFormattedString(pTickInfo->getUnscaledTickValue(), rExtraColor, rHasExtraColor);
}
void getAxisLabelProperties(
tNameSequence& rPropNames, tAnySequence& rPropValues, const AxisProperties& rAxisProp,
const AxisLabelProperties& rAxisLabelProp,
sal_Int32 nLimitedSpaceForText, bool bLimitedHeight )
{
Reference<beans::XPropertySet> xProps(rAxisProp.m_xAxisModel, uno::UNO_QUERY);
PropertyMapper::getTextLabelMultiPropertyLists(
xProps, rPropNames, rPropValues, false, nLimitedSpaceForText, bLimitedHeight);
LabelPositionHelper::doDynamicFontResize(
rPropValues, rPropNames, xProps, rAxisLabelProp.m_aFontReferenceSize);
LabelPositionHelper::changeTextAdjustment(
rPropValues, rPropNames, rAxisProp.maLabelAlignment.meAlignment);
}
/** /**
* Iterate through only the first 2 and last 2 tick info items, and the tick * Iterate through only the first 2 and last 2 tick info items, and the tick
* that has the longest text (in terms of character length) in case it's not * that has the longest text (in terms of character length) in case it's not
...@@ -644,17 +685,12 @@ bool VCartesianAxis::createTextShapes( ...@@ -644,17 +685,12 @@ bool VCartesianAxis::createTextShapes(
const TickInfo* pPREPreviousVisibleTickInfo = NULL; const TickInfo* pPREPreviousVisibleTickInfo = NULL;
const TickInfo* pLastVisibleNeighbourTickInfo = NULL; const TickInfo* pLastVisibleNeighbourTickInfo = NULL;
bool bLimitedHeight = fabs(aTextToTickDistance.getX()) > fabs(aTextToTickDistance.getY());
//prepare properties for multipropertyset-interface of shape //prepare properties for multipropertyset-interface of shape
tNameSequence aPropNames; tNameSequence aPropNames;
tAnySequence aPropValues; tAnySequence aPropValues;
getAxisLabelProperties(aPropNames, aPropValues, m_aAxisProperties, rAxisLabelProperties, nLimitedSpaceForText, bLimitedHeight);
bool bLimitedHeight = fabs(aTextToTickDistance.getX()) > fabs(aTextToTickDistance.getY());
Reference< beans::XPropertySet > xProps( m_aAxisProperties.m_xAxisModel, uno::UNO_QUERY );
PropertyMapper::getTextLabelMultiPropertyLists( xProps, aPropNames, aPropValues, false
, nLimitedSpaceForText, bLimitedHeight );
LabelPositionHelper::doDynamicFontResize( aPropValues, aPropNames, xProps
, m_aAxisLabelProperties.m_aFontReferenceSize );
LabelPositionHelper::changeTextAdjustment( aPropValues, aPropNames, m_aAxisProperties.maLabelAlignment.meAlignment );
uno::Any* pColorAny = PropertyMapper::getValuePointer(aPropValues,aPropNames,"CharColor"); uno::Any* pColorAny = PropertyMapper::getValuePointer(aPropValues,aPropNames,"CharColor");
sal_Int32 nColor = Color( COL_AUTO ).GetColor(); sal_Int32 nColor = Color( COL_AUTO ).GetColor();
...@@ -725,25 +761,9 @@ bool VCartesianAxis::createTextShapes( ...@@ -725,25 +761,9 @@ bool VCartesianAxis::createTextShapes(
bool bHasExtraColor=false; bool bHasExtraColor=false;
sal_Int32 nExtraColor=0; sal_Int32 nExtraColor=0;
OUString aLabel; OUString aLabel = getTextLabelString(
if(pCategories) aFixedNumberFormatter, pCategories, pTickInfo, isComplexCategoryAxis(),
{ nExtraColor, bHasExtraColor);
// This is a normal category axis. Get the label string from the
// label string array.
sal_Int32 nIndex = static_cast<sal_Int32>(pTickInfo->getUnscaledTickValue()) - 1; //first category (index 0) matches with real number 1.0
if( nIndex>=0 && nIndex<pCategories->getLength() )
aLabel = (*pCategories)[nIndex];
}
else if( m_aAxisProperties.m_bComplexCategories )
{
// This is a complex category axis. The label is stored in the tick.
aLabel = pTickInfo->aText;
}
else
{
// This is a numeric axis. Format the original tick value per number format.
aLabel = aFixedNumberFormatter.getFormattedString( pTickInfo->getUnscaledTickValue(), nExtraColor, bHasExtraColor );
}
if(pColorAny) if(pColorAny)
*pColorAny = uno::makeAny(bHasExtraColor?nExtraColor:nColor); *pColorAny = uno::makeAny(bHasExtraColor?nExtraColor:nColor);
...@@ -810,10 +830,7 @@ bool VCartesianAxis::createTextShapes( ...@@ -810,10 +830,7 @@ bool VCartesianAxis::createTextShapes(
// Try auto-rotating the labels at 45 degrees and // Try auto-rotating the labels at 45 degrees and
// start over. This rotation angle will be stored for // start over. This rotation angle will be stored for
// all future text shape creation runs. // all future text shape creation runs.
rAxisLabelProperties.autoRotate45();
rAxisLabelProperties.fRotationAngleDegree = 45;
rAxisLabelProperties.bLineBreakAllowed = false;
rAxisLabelProperties.eStaggering = SIDE_BY_SIDE;
m_aAxisLabelProperties.fRotationAngleDegree = rAxisLabelProperties.fRotationAngleDegree; // Store it for future runs. m_aAxisLabelProperties.fRotationAngleDegree = rAxisLabelProperties.fRotationAngleDegree; // Store it for future runs.
removeTextShapesFromTicks(); removeTextShapesFromTicks();
return false; return false;
...@@ -862,17 +879,12 @@ bool VCartesianAxis::createTextShapesSimple( ...@@ -862,17 +879,12 @@ bool VCartesianAxis::createTextShapesSimple(
const TickInfo* pPreviousVisibleTickInfo = NULL; const TickInfo* pPreviousVisibleTickInfo = NULL;
const TickInfo* pLastVisibleNeighbourTickInfo = NULL; const TickInfo* pLastVisibleNeighbourTickInfo = NULL;
bool bLimitedHeight = fabs(aTextToTickDistance.getX()) > fabs(aTextToTickDistance.getY());
//prepare properties for multipropertyset-interface of shape //prepare properties for multipropertyset-interface of shape
tNameSequence aPropNames; tNameSequence aPropNames;
tAnySequence aPropValues; tAnySequence aPropValues;
getAxisLabelProperties(aPropNames, aPropValues, m_aAxisProperties, rAxisLabelProperties, -1, bLimitedHeight);
bool bLimitedHeight = fabs(aTextToTickDistance.getX()) > fabs(aTextToTickDistance.getY());
Reference< beans::XPropertySet > xProps( m_aAxisProperties.m_xAxisModel, uno::UNO_QUERY );
PropertyMapper::getTextLabelMultiPropertyLists( xProps, aPropNames, aPropValues, false
, -1, bLimitedHeight );
LabelPositionHelper::doDynamicFontResize( aPropValues, aPropNames, xProps
, m_aAxisLabelProperties.m_aFontReferenceSize );
LabelPositionHelper::changeTextAdjustment( aPropValues, aPropNames, m_aAxisProperties.maLabelAlignment.meAlignment );
uno::Any* pColorAny = PropertyMapper::getValuePointer(aPropValues,aPropNames,"CharColor"); uno::Any* pColorAny = PropertyMapper::getValuePointer(aPropValues,aPropNames,"CharColor");
sal_Int32 nColor = Color( COL_AUTO ).GetColor(); sal_Int32 nColor = Color( COL_AUTO ).GetColor();
...@@ -921,25 +933,9 @@ bool VCartesianAxis::createTextShapesSimple( ...@@ -921,25 +933,9 @@ bool VCartesianAxis::createTextShapesSimple(
bool bHasExtraColor=false; bool bHasExtraColor=false;
sal_Int32 nExtraColor=0; sal_Int32 nExtraColor=0;
OUString aLabel; OUString aLabel = getTextLabelString(
if(pCategories) aFixedNumberFormatter, pCategories, pTickInfo, isComplexCategoryAxis(),
{ nExtraColor, bHasExtraColor);
// This is a normal category axis. Get the label string from the
// label string array.
sal_Int32 nIndex = static_cast<sal_Int32>(pTickInfo->getUnscaledTickValue()) - 1; //first category (index 0) matches with real number 1.0
if( nIndex>=0 && nIndex<pCategories->getLength() )
aLabel = (*pCategories)[nIndex];
}
else if( m_aAxisProperties.m_bComplexCategories )
{
// This is a complex category axis. The label is stored in the tick.
aLabel = pTickInfo->aText;
}
else
{
// This is a numeric axis. Format the original tick value per number format.
aLabel = aFixedNumberFormatter.getFormattedString( pTickInfo->getUnscaledTickValue(), nExtraColor, bHasExtraColor );
}
if(pColorAny) if(pColorAny)
*pColorAny = uno::makeAny(bHasExtraColor?nExtraColor:nColor); *pColorAny = uno::makeAny(bHasExtraColor?nExtraColor:nColor);
...@@ -975,10 +971,7 @@ bool VCartesianAxis::createTextShapesSimple( ...@@ -975,10 +971,7 @@ bool VCartesianAxis::createTextShapesSimple(
// Try auto-rotating the labels at 45 degrees and // Try auto-rotating the labels at 45 degrees and
// start over. This rotation angle will be stored for // start over. This rotation angle will be stored for
// all future text shape creation runs. // all future text shape creation runs.
rAxisLabelProperties.autoRotate45();
rAxisLabelProperties.fRotationAngleDegree = 45;
rAxisLabelProperties.bLineBreakAllowed = false;
rAxisLabelProperties.eStaggering = SIDE_BY_SIDE;
m_aAxisLabelProperties.fRotationAngleDegree = rAxisLabelProperties.fRotationAngleDegree; // Store it for future runs. m_aAxisLabelProperties.fRotationAngleDegree = rAxisLabelProperties.fRotationAngleDegree; // Store it for future runs.
removeTextShapesFromTicks(); removeTextShapesFromTicks();
return false; return false;
......
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