Hi LiuTao,

you don't need to touch VCL for this, because VCL can't help you with
this feature.

VCL only sees single text portions, so it can't calculate the correct
positions when it comes to complete text lines.

This needs to be done in the EditEngine.

For TOP and BOTTOM it should be easy.

No changes needed in calculation, only in output.

In ImpEditEngine::Paint:

TOP: Instead of adding nMaxAscent to Y postions, don't manipulate Y and
tell VCL to use ALIGN_TOP.

BOTTOM: Instead of adding nMaxAscent to Y postions, add line height and
tell VCL to use ALIGN_BOTTOM.

Please recognize the different manipulations needed for
horizontal/vertical writing.

CENTER: Can be more complicated, but also might be simple.
One solution could be to calculate the font metrics for the portion that
you want to draw, handle Y postions like for TOP, but now add
(lineheight - textheight) to Y position.

This should work in Draw/Impress only.
Maybe even only in edit mode - it might be that Draw use some special
routines for repainting text objects which are not in edit mode (not
sure). I also can't say if it would automatically works in presentation
mode.

Writer would need an own implementation anyway.

In Calc it only works in cell edit mode. When painting cells, Calc
normally uses DrawText directly for performance reasons.
But they use the EditEngine for painting when the content has different
attributes. So it might also be able to convince Calc to use the
EditEngine when an other align mode is used.

Last but not least: Please recognize that ODF probably doesn't support
the attributes that you want to introduce...

HTH,
Malte.



JiaXiang Liu wrote, On 12/03/09 02:14:
> Hello all,
> 
>  I want to ask you some questons. I am developing a new feature called
> "text-align" recently. this feature is like this:
>     it can set text align in 4 ways: 1.TOP,2.CENTER,3.BASELINE,4.BOTTOM in
> Impress module. Then it can be set in SW and SC modules.
> I implement it like this:
>                  1.define a menu item ;
>                  2.define slot_ID;
>                  3.define a SvxTextAlignItem like  SvxAdjustItem.
>                  4. for example. I add these code:
> case SID_TEXT_ALIGN_TOP:
> {
>        aNewAttr.Put( SvxTextAlignItem( SVX_TEXTALIGN_TOP, EE_TEXT_ALIGN ) );
> }
> like this code:
> case SID_ATTR_PARA_ADJUST_LEFT,:
> {
>     aNewAttr.Put( SvxAdjustItem( SVX_ADJUST_LEFT, EE_PARA_JUST ) );
> }
>                   5. after that I think it should do calculate and paint.I
> found some code in vcl like this:
>     // calculate text offset depending on TextAlignment
>     TextAlign eAlign = maFont.GetAlign();
>     if ( eAlign == ALIGN_BASELINE )
>     {
>         mnTextOffX = 0;
>         mnTextOffY = 0;
>     }
>     else if ( eAlign == ALIGN_TOP )
>     {
>         mnTextOffX = 0;
>         mnTextOffY = +pFontEntry->maMetric.mnAscent + mnEmphasisAscent;
>         if ( pFontEntry->mnOrientation )
>             ImplRotatePos( 0, 0, mnTextOffX, mnTextOffY,
> pFontEntry->mnOrientation );
>     }
>     //---liutao---modify---091109---15:31---start---//
>     //else // eAlign == ALIGN_BOTTOM
>     //{
>     //    mnTextOffX = 0;
>     //    mnTextOffY = -pFontEntry->maMetric.mnDescent + mnEmphasisDescent;
>     //    if ( pFontEntry->mnOrientation )
>     //        ImplRotatePos( 0, 0, mnTextOffX, mnTextOffY,
> pFontEntry->mnOrientation );
>     //}
>     else if (eAlign == ALIGN_BOTTOM)
>     {
>         mnTextOffX = 0;
>         mnTextOffY = -pFontEntry->maMetric.mnDescent + mnEmphasisDescent;
>         if ( pFontEntry->mnOrientation )
>             ImplRotatePos( 0, 0, mnTextOffX, mnTextOffY,
> pFontEntry->mnOrientation );
>     }
>     else //(eAlign == ALIGN_CENTER)
>     {
>         mnTextOffX = 0;
>         mnTextOffY = -pFontEntry->maMetric.mnDescent + mnEmphasisDescent;
>         if ( pFontEntry->mnOrientation )
>             ImplRotatePos( 0, 0, mnTextOffX, mnTextOffY,
> pFontEntry->mnOrientation );
>     }
> //---liutao---modify---091109---15:31---end---//
> I did some modify.
> I think the calculation is done by someone else. so it become easy to
> implement this feature.
> my question is this:
> 1.how to call this calculation function?
>              I add some code like this in the createfont function in
> editdoc.cxx file:
> //---liutao---modify---091109---15:39---start---//
>     rFont.SetAlign( ALIGN_BASELINE );
>     //enum TextAlign at = ALIGN_BASELINE;
>     //if ( bSearchInParent || ( rSet.GetItemState( EE_PARA_ALIGN ) ==
> SFX_ITEM_ON ) )
>     //{
>     //    SvxTextAlignItem svAD = (const SvxTextAlignItem&)rSet.Get(
> EE_PARA_ALIGN );
>     //    if (svAD.GetTextAlign() == SVX_TEXTALIGN_TOP)
>     //    {
>     //        at = ALIGN_TOP;
>     //    }
>     //    else if (svAD.GetTextAlign() == SVX_TEXTALIGN_BOTTOM)
>     //    {
>     //        at = ALIGN_BOTTOM;
>     //    }
>     //    else if (svAD.GetTextAlign() == SVX_TEXTALIGN_CENTER)
>     //    {
>     //        at = ALIGN_CENTER;
>     //    }
>     //    else
>     //    {
>     //        at = ALIGN_BASELINE;
>     //    }
>     //}
>     //rFont.SetAlign(at);
> //---liutao---modify---091109---15:39---end---//
> these code can change the position of the words. for example,after I add
> these code and implement it. the phenomena is like this:
> 1.1.create a new Impress document
> 1.2.select a layout and input some words in a Editbox. these words should
> have different size.
> 1.3.implement this new feature(align top)
> 1.4.result:
> these words are down to the bottom line. I can only see only a little "head"
> of these words . (PIC1) BUT  I think it is aligned top.(PIC2)
> after I exit the edit status. it will be dispalied as original.(PIC3)(if we
> set para align left in edit status and exit edit status,it will not
> dispalied as original.)
> 2. what is the function mean "void CreateFont( SvxFont& rFont, const
> SfxItemSet& rSet, bool bSearchInParent, short nScriptType )" in editdoc.cxx
> file.It has no class.
> 3. what is the arithmetic mean in vcl module:
>     TextAlign eAlign = maFont.GetAlign();
>     if ( eAlign == ALIGN_BASELINE )
>     {
>         mnTextOffX = 0;
>         mnTextOffY = 0;
>     }
>     else if ( eAlign == ALIGN_TOP )
>     {
>         mnTextOffX = 0;
>         mnTextOffY = +pFontEntry->maMetric.mnAscent + mnEmphasisAscent;
>         if ( pFontEntry->mnOrientation )
>             ImplRotatePos( 0, 0, mnTextOffX, mnTextOffY,
> pFontEntry->mnOrientation );
>     }
> for example:what is the mean of" mnTextOffX = 0;" and what is the mean of "
> mnTextOffY = +pFontEntry->maMetric.mnAscent + mnEmphasisAscent;
>         if ( pFontEntry->mnOrientation )
>             ImplRotatePos( 0, 0, mnTextOffX, mnTextOffY,
> pFontEntry->mnOrientation );"
> 4.if I should define  a new class EditCharAttribAlign like
> EditCharAttribShadow to implement this feature?I added this class but
> unfortunately I don't know how to use it. and seems it should be defined.
> EditCharAttribShadow::EditCharAttribShadow( const SvxShadowedItem& rAttr,
> USHORT _nStart, USHORT _nEnd )
>     : EditCharAttrib( rAttr, _nStart, _nEnd )
> {
>     DBG_ASSERT( rAttr.Which() == EE_CHAR_SHADOW, "Kein Shadowattribut!" );
> }
> void EditCharAttribShadow::SetFont( SvxFont& rFont, OutputDevice* )
> {
>     rFont.SetShadow( (BOOL)((const SvxShadowedItem*)GetItem())->GetValue()
> );
> }
> // -------------------------------------------------------------------------
> //---liutao---add---091109---15:18---start---//
> // -------------------------------------------------------------------------
> // class EditCharAttribShadow
> // -------------------------------------------------------------------------
> //EditCharAttribAlign::EditCharAttribAlign( const SvxTextAlignItem& rAttr,
> USHORT _nStart, USHORT _nEnd )
> //    : EditCharAttrib( rAttr, _nStart, _nEnd )
> //{
> //    DBG_ASSERT( rAttr.Which() == EE_PARA_ALIGN, "Paragraph Textalign!" );
> //}
> //
> //void EditCharAttribAlign::SetFont( SvxFont& rFont, OutputDevice* )
> //{
> //    rFont.SetAlign((TextAlign)((const
> SvxTextAlignItem*)GetItem())->GetEnumValue() );
> //}
> Please look at the PIC1 TO PIC 3:
> 
> http://wiki.services.openoffice.org/wiki/Picture1-3
> 
> I wish you can give me explanation .wish your reply.
> With Best Regards,
> LiuTao
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to