/****************************************************************************** * ME_GetRunSizeCommon * * Finds width, height, ascent and descent of a run, up to given character * (nLen). */ SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen, int startx, int *pAscent, int *pDescent) { SIZE size; WCHAR spaceW[] = {' ',0}; nLen = min( nLen, run->len ); if (run->nFlags & MERF_ENDPARA) { nLen = min( nLen, 1 ); ME_GetTextExtent(c, spaceW, nLen, run->style, &size); } else if (para->nFlags & MEPF_COMPLEX) { size.cx = run->nWidth; } else if (c->editor->cPasswordMask) { ME_String *szMasked = ME_MakeStringR(c->editor->cPasswordMask,nLen); ME_GetTextExtent(c, szMasked->szData, nLen,run->style, &size); ME_DestroyString(szMasked); } else { ME_GetTextExtent(c, get_text( run, 0 ), nLen, run->style, &size); } *pAscent = run->style->tm.tmAscent; *pDescent = run->style->tm.tmDescent; size.cy = *pAscent + *pDescent; if (run->nFlags & MERF_TAB) { int pos = 0, i = 0, ppos, shift = 0; const PARAFORMAT2 *pFmt = ¶->fmt; if (c->editor->bEmulateVersion10 && /* v1.0 - 3.0 */ pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE) /* The horizontal gap shifts the tab positions to leave the gap. */ shift = pFmt->dxOffset * 2; do { if (i < pFmt->cTabCount) { /* Only one side of the horizontal gap is needed at the end of * the table row. */ if (i == pFmt->cTabCount -1) shift = shift >> 1; pos = shift + (pFmt->rgxTabs[i]&0x00FFFFFF); i++; } else { pos += lDefaultTab - (pos % lDefaultTab); } ppos = ME_twips2pointsX(c, pos); if (ppos > startx + run->pt.x) { size.cx = ppos - startx - run->pt.x; break; } } while(1);
/****************************************************************************** * ME_GetRunSizeCommon * * Finds width, height, ascent and descent of a run, up to given character * (nLen). */ SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen, int startx, int *pAscent, int *pDescent) { SIZE size; int nMaxLen = run->len; if (nLen>nMaxLen) nLen = nMaxLen; /* FIXME the following call also ensures that TEXTMETRIC structure is filled * this is wasteful for MERF_NONTEXT runs, but that shouldn't matter * in practice */ if (c->editor->cPasswordMask) { ME_String *szMasked = ME_MakeStringR(c->editor->cPasswordMask,nLen); ME_GetTextExtent(c, szMasked->szData, nLen,run->style, &size); ME_DestroyString(szMasked); } else { ME_GetTextExtent(c, get_text( run, 0 ), nLen, run->style, &size); } *pAscent = run->style->tm.tmAscent; *pDescent = run->style->tm.tmDescent; size.cy = *pAscent + *pDescent; if (run->nFlags & MERF_TAB) { int pos = 0, i = 0, ppos, shift = 0; PARAFORMAT2 *pFmt = para->pFmt; if (c->editor->bEmulateVersion10 && /* v1.0 - 3.0 */ pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE) /* The horizontal gap shifts the tab positions to leave the gap. */ shift = pFmt->dxOffset * 2; do { if (i < pFmt->cTabCount) { /* Only one side of the horizontal gap is needed at the end of * the table row. */ if (i == pFmt->cTabCount -1) shift = shift >> 1; pos = shift + (pFmt->rgxTabs[i]&0x00FFFFFF); i++; } else { pos += lDefaultTab - (pos % lDefaultTab); } ppos = ME_twips2pointsX(c, pos); if (ppos > startx + run->pt.x) { size.cx = ppos - startx - run->pt.x; break; } } while(1);
/****************************************************************************** * ME_PointFromCharContext * * Returns a run-relative pixel position given a run-relative character * position (character offset) */ int ME_PointFromCharContext(ME_Context *c, ME_Run *pRun, int nOffset, BOOL visual_order) { SIZE size; ME_String *mask_text = NULL; WCHAR *str; if (pRun->nFlags & MERF_GRAPHICS) { if (nOffset) ME_GetOLEObjectSize(c, pRun, &size); return nOffset != 0; } else if (pRun->nFlags & MERF_ENDPARA) { nOffset = 0; } if (pRun->para->nFlags & MEPF_COMPLEX) { int x; ScriptCPtoX( nOffset, FALSE, pRun->len, pRun->num_glyphs, pRun->clusters, pRun->vis_attrs, pRun->advances, &pRun->script_analysis, &x ); if (visual_order && pRun->script_analysis.fRTL) x = pRun->nWidth - x - 1; return x; } if (c->editor->cPasswordMask) { mask_text = ME_MakeStringR(c->editor->cPasswordMask, pRun->len); str = mask_text->szData; } else str = get_text( pRun, 0 ); ME_GetTextExtent(c, str, nOffset, pRun->style, &size); ME_DestroyString( mask_text ); return size.cx; }
/****************************************************************************** * ME_PointFromCharContext * * Returns a run-relative pixel position given a run-relative character * position (character offset) */ int ME_PointFromCharContext(ME_Context *c, ME_Run *pRun, int nOffset, BOOL visual_order) { SIZE size; ME_String *mask_text = NULL; WCHAR *str; if (pRun->nFlags & MERF_GRAPHICS) { if (nOffset) ME_GetOLEObjectSize(c, pRun, &size); return nOffset != 0; } else if (pRun->nFlags & MERF_ENDPARA) { nOffset = 0; } if (c->editor->cPasswordMask) { mask_text = ME_MakeStringR(c->editor->cPasswordMask, pRun->len); str = mask_text->szData; } else str = get_text( pRun, 0 ); ME_GetTextExtent(c, str, nOffset, pRun->style, &size); ME_DestroyString( mask_text ); return size.cx; }