Calculating Cursor Size ar Run boundaries.


Subject: Calculating Cursor Size ar Run boundaries.
From: Martin Sevior (msevior@mccubbin.ph.unimelb.edu.au)
Date: Mon May 29 2000 - 21:00:15 CDT


Hi Jesper,
           You've done a great job in sorting out the findpointcoords
code. However I think there are cases where we will want to go beyond
what is inherent in the assumptions in this code. The best example is
inserting a superscript chaarcter into the first poistion of a
pre-existing superscript run. Right now this is impossible. If you
position the cursor before the superscript run the text will be entered as
normal. If we change abi behaviour so that text is inserted as superscript
text cannot be directly entered as normal. The only way to solve this is
to have the capability to move the insertion point in the piece table,
without moving the cursor in x on the screen BUT updating the cursor size
and position to reflect the insertion point in the document. So I move the
cursor to the end of a string of normal text. The cursor shows normal size
and location. I press ``forward arrow''. The cursor stays fixed in x but
jumps up on the line and changes size to reflect insertion as superscript.
This cannot be done with the current findpointcoords code.

My suggestion is to calculate the cursor size and height for ambiguous
cases using the Piece Table information directly. The code below shows how
this information is currently accessed (horrible isn't it?).

(Scan down past the code for continued discussion!)

In fp_Line::recalcHeight() is the code:

<snip>

                iAscent = pRun->getAscent();
                iDescent = pRun->getDescent();

<snip>

and then
                if (pRun->isSuperscript() || pRun->isSubscript())
                {
                        iAscent += iAscent * 1/2;
                        iDescent += iDescent;

<snip>

These are all that are needed to calculate the cursor size and location
(along with bEOL (thanks Mike)) given the x location and line number.
These quantities are in turn calculated in fp_TextRun in the following
cumbersome way.

<snip>

        const PP_AttrProp * pSpanAP = NULL;
        const PP_AttrProp * pBlockAP = NULL;
        const PP_AttrProp * pSectionAP = NULL; // TODO do we care about section-level inheritance?
        
        m_pBL->getSpanAttrProp(m_iOffsetFirst,UT_FALSE,&pSpanAP);
        m_pBL->getAttrProp(&pBlockAP);

        // look for fonts in this DocLayout's font cache
        FL_DocLayout * pLayout = m_pBL->getDocLayout();
        m_pFont = pLayout->findFont(pSpanAP,pBlockAP,pSectionAP, FL_DocLayout::FIND_FONT_AT_SCREEN_RESOLUTION);
        m_pFontLayout = pLayout->findFont(pSpanAP,pBlockAP,pSectionAP, FL_DocLayout::FIND_FONT_AT_LAYOUT_RESOLUTION);

        PD_Document * pDoc = m_pBL->getDocument();

        UT_parseColor(PP_evalProperty("color",pSpanAP,pBlockAP,pSectionAP, pDoc, UT_TRUE), m_colorFG);

        const XML_Char *pszDecor = PP_evalProperty("text-decoration",pSpanAP,pBlockAP,pSectionAP, pDoc, UT_TRUE);

<snip>

        const XML_Char * pszPosition = PP_evalProperty("text-position",pSpanAP,pBlockAP,pSectionAP, pDoc, UT_TRUE);

        if (0 == UT_stricmp(pszPosition, "superscript"))
        {
                m_fPosition = TEXT_POSITION_SUPERSCRIPT;
        }
        else if (0 == UT_stricmp(pszPosition, "subscript"))
        {
                m_fPosition = TEXT_POSITION_SUBSCRIPT;
        }
        else m_fPosition = TEXT_POSITION_NORMAL;

<snip>

        m_pG->setFont(m_pFont);
        m_iAscent = m_pG->getFontAscent();
        m_iDescent = m_pG->getFontDescent();
        m_iHeight = m_pG->getFontHeight();
<snip>

        Then getAscent() etc returns these values.

Now Sam's acessor functions will eventually enable us to do something
like:

        UT_uint32 iAscent = getCurrentDocPos()->getAscent();
        UT_Bool bSuperscript = getCurrentDocPos()->isSuperscript();

etc.

(Is this right Sam?)

 When Sam's accessor functions are available we can replace the above ugly
and slow code with direct calls on the Piece Table. I suggest that we implement
direct calculation of cursor size and location only for run boundaries
initially with these conventional calls and eventually replace those calls
with Sam's direct acessor functions.

With this code in place I'm sure I can make the other minor changes
neccesary to get Abi to Do The Right Thing.

Cheers

Martin



This archive was generated by hypermail 2b25 : Mon May 29 2000 - 21:00:27 CDT