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

Reply via email to