2005-03-05 12:19:14 +01:00
|
|
|
/*
|
|
|
|
* RichEdit - Paragraph wrapping. Don't try to understand it. You've been
|
|
|
|
* warned !
|
|
|
|
*
|
|
|
|
* Copyright 2004 by Krzysztof Foltman
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-03-05 12:19:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "editor.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(richedit);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unsolved problems:
|
2005-04-16 12:48:35 +02:00
|
|
|
*
|
2005-03-05 12:19:14 +01:00
|
|
|
* - center and right align in WordPad omits all spaces at the start, we don't
|
|
|
|
* - objects/images are not handled yet
|
2005-04-16 12:48:35 +02:00
|
|
|
* - no tabs
|
|
|
|
*/
|
|
|
|
|
2016-10-04 14:07:37 +02:00
|
|
|
typedef struct tagME_WrapContext
|
|
|
|
{
|
|
|
|
ME_Style *style;
|
|
|
|
ME_Context *context;
|
2016-10-07 11:49:35 +02:00
|
|
|
int nLeftMargin, nRightMargin;
|
|
|
|
int nFirstMargin; /* Offset to first line's text, always to the text itself even if a para number is present */
|
|
|
|
int nParaNumOffset; /* Offset to the para number */
|
|
|
|
int nAvailWidth; /* Width avail for text to wrap into. Does not include any para number text */
|
2016-10-04 14:07:37 +02:00
|
|
|
int nRow;
|
|
|
|
POINT pt;
|
|
|
|
BOOL bOverflown, bWordWrap;
|
2020-10-08 12:10:46 +02:00
|
|
|
ME_Paragraph *para;
|
2020-10-08 12:10:45 +02:00
|
|
|
ME_Run *pRowStart;
|
|
|
|
ME_Run *pLastSplittableRun;
|
2016-10-04 14:07:37 +02:00
|
|
|
} ME_WrapContext;
|
2014-01-15 14:06:43 +01:00
|
|
|
|
|
|
|
static BOOL get_run_glyph_buffers( ME_Run *run )
|
|
|
|
{
|
|
|
|
heap_free( run->glyphs );
|
|
|
|
run->glyphs = heap_alloc( run->max_glyphs * (sizeof(WORD) + sizeof(SCRIPT_VISATTR) + sizeof(int) + sizeof(GOFFSET)) );
|
|
|
|
if (!run->glyphs) return FALSE;
|
|
|
|
|
|
|
|
run->vis_attrs = (SCRIPT_VISATTR*)((char*)run->glyphs + run->max_glyphs * sizeof(WORD));
|
|
|
|
run->advances = (int*)((char*)run->glyphs + run->max_glyphs * (sizeof(WORD) + sizeof(SCRIPT_VISATTR)));
|
|
|
|
run->offsets = (GOFFSET*)((char*)run->glyphs + run->max_glyphs * (sizeof(WORD) + sizeof(SCRIPT_VISATTR) + sizeof(int)));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT shape_run( ME_Context *c, ME_Run *run )
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!run->glyphs)
|
|
|
|
{
|
|
|
|
run->max_glyphs = 1.5 * run->len + 16; /* This is suggested in the uniscribe documentation */
|
|
|
|
run->max_glyphs = (run->max_glyphs + 7) & ~7; /* Keep alignment simple */
|
|
|
|
get_run_glyph_buffers( run );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (run->max_clusters < run->len)
|
|
|
|
{
|
|
|
|
heap_free( run->clusters );
|
|
|
|
run->max_clusters = run->len * 2;
|
|
|
|
run->clusters = heap_alloc( run->max_clusters * sizeof(WORD) );
|
|
|
|
}
|
|
|
|
|
2019-08-19 11:55:28 +02:00
|
|
|
select_style( c, run->style );
|
2014-01-15 14:06:43 +01:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
hr = ScriptShape( c->hDC, &run->style->script_cache, get_text( run, 0 ), run->len, run->max_glyphs,
|
|
|
|
&run->script_analysis, run->glyphs, run->clusters, run->vis_attrs, &run->num_glyphs );
|
|
|
|
if (hr != E_OUTOFMEMORY) break;
|
|
|
|
if (run->max_glyphs > 10 * run->len) break; /* something has clearly gone wrong */
|
|
|
|
run->max_glyphs *= 2;
|
|
|
|
get_run_glyph_buffers( run );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = ScriptPlace( c->hDC, &run->style->script_cache, run->glyphs, run->num_glyphs, run->vis_attrs,
|
|
|
|
&run->script_analysis, run->advances, run->offsets, NULL );
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
for (i = 0, run->nWidth = 0; i < run->num_glyphs; i++)
|
|
|
|
run->nWidth += run->advances[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2013-02-12 16:48:14 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* calc_run_extent
|
|
|
|
*
|
|
|
|
* Updates the size of the run (fills width, ascent and descent). The height
|
|
|
|
* is calculated based on whole row's ascent and descent anyway, so no need
|
|
|
|
* to use it here.
|
|
|
|
*/
|
|
|
|
static void calc_run_extent(ME_Context *c, const ME_Paragraph *para, int startx, ME_Run *run)
|
|
|
|
{
|
|
|
|
if (run->nFlags & MERF_HIDDEN) run->nWidth = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SIZE size = ME_GetRunSizeCommon( c, para, run, run->len, startx, &run->nAscent, &run->nDescent );
|
|
|
|
run->nWidth = size.cx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-07 15:30:47 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* split_run_extents
|
|
|
|
*
|
|
|
|
* Splits a run into two in a given place. It also updates the screen position
|
|
|
|
* and size (extent) of the newly generated runs.
|
|
|
|
*/
|
2020-10-08 12:10:45 +02:00
|
|
|
static ME_Run *split_run_extents( ME_WrapContext *wc, ME_Run *run, int nVChar )
|
2013-02-07 15:30:47 +01:00
|
|
|
{
|
|
|
|
ME_TextEditor *editor = wc->context->editor;
|
2020-10-08 12:10:45 +02:00
|
|
|
ME_Run *run2;
|
2020-10-08 12:10:46 +02:00
|
|
|
ME_Cursor cursor = {para_get_di( wc->para ), run_get_di( run ), nVChar};
|
2013-02-07 15:30:47 +01:00
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
assert( run->nCharOfs != -1 );
|
2018-11-29 14:44:55 +01:00
|
|
|
ME_CheckCharOffsets(editor);
|
2013-02-07 15:30:47 +01:00
|
|
|
|
|
|
|
TRACE("Before split: %s(%d, %d)\n", debugstr_run( run ),
|
|
|
|
run->pt.x, run->pt.y);
|
|
|
|
|
2020-10-14 12:17:14 +02:00
|
|
|
run_split( editor, &cursor );
|
2013-02-07 15:30:47 +01:00
|
|
|
|
|
|
|
run2 = &cursor.pRun->member.run;
|
2014-01-15 14:06:43 +01:00
|
|
|
run2->script_analysis = run->script_analysis;
|
2013-02-07 15:30:47 +01:00
|
|
|
|
2014-01-15 14:06:43 +01:00
|
|
|
shape_run( wc->context, run );
|
|
|
|
shape_run( wc->context, run2 );
|
2020-10-08 12:10:46 +02:00
|
|
|
calc_run_extent(wc->context, wc->para, wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, run);
|
2013-02-07 15:30:47 +01:00
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
run2->pt.x = run->pt.x + run->nWidth;
|
2013-02-07 15:30:47 +01:00
|
|
|
run2->pt.y = run->pt.y;
|
|
|
|
|
2018-11-29 14:44:55 +01:00
|
|
|
ME_CheckCharOffsets(editor);
|
2016-01-04 09:09:53 +01:00
|
|
|
|
|
|
|
TRACE("After split: %s(%d, %d), %s(%d, %d)\n",
|
|
|
|
debugstr_run( run ), run->pt.x, run->pt.y,
|
|
|
|
debugstr_run( run2 ), run2->pt.x, run2->pt.y);
|
2013-02-07 15:30:47 +01:00
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
return &cursor.pRun->member.run;
|
2013-02-07 15:30:47 +01:00
|
|
|
}
|
|
|
|
|
2013-02-08 12:45:03 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* find_split_point
|
|
|
|
*
|
|
|
|
* Returns a character position to split inside the run given a run-relative
|
|
|
|
* pixel horizontal position. This version rounds left (ie. if the second
|
|
|
|
* character is at pixel position 8, then for cx=0..7 it returns 0).
|
|
|
|
*/
|
|
|
|
static int find_split_point( ME_Context *c, int cx, ME_Run *run )
|
|
|
|
{
|
|
|
|
if (!run->len || cx <= 0) return 0;
|
2013-04-17 13:56:37 +02:00
|
|
|
return ME_CharFromPointContext( c, cx, run, FALSE, FALSE );
|
2013-02-08 12:45:03 +01:00
|
|
|
}
|
2013-02-07 15:30:47 +01:00
|
|
|
|
2020-11-04 07:56:24 +01:00
|
|
|
static ME_Row *row_create( int height, int baseline, int width )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_DisplayItem *item = ME_MakeDI(diStartRow);
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
item->member.row.nHeight = height;
|
|
|
|
item->member.row.nBaseline = baseline;
|
|
|
|
item->member.row.nWidth = width;
|
2020-11-04 07:56:24 +01:00
|
|
|
return &item->member.row;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2009-02-06 07:09:56 +01:00
|
|
|
static void ME_BeginRow(ME_WrapContext *wc)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-23 11:25:03 +02:00
|
|
|
ME_Cell *cell;
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
wc->pRowStart = NULL;
|
|
|
|
wc->bOverflown = FALSE;
|
|
|
|
wc->pLastSplittableRun = NULL;
|
2008-10-10 23:50:44 +02:00
|
|
|
wc->bWordWrap = wc->context->editor->bWordWrap;
|
2020-10-08 12:10:46 +02:00
|
|
|
if (wc->para->nFlags & (MEPF_ROWSTART | MEPF_ROWEND))
|
|
|
|
{
|
2008-08-07 18:31:41 +02:00
|
|
|
wc->nAvailWidth = 0;
|
2008-10-10 23:50:44 +02:00
|
|
|
wc->bWordWrap = FALSE;
|
2020-10-08 12:10:46 +02:00
|
|
|
if (wc->para->nFlags & MEPF_ROWEND)
|
2008-08-07 18:31:41 +02:00
|
|
|
{
|
2020-10-23 11:25:03 +02:00
|
|
|
cell = table_row_end_cell( wc->para );
|
2008-08-07 18:31:41 +02:00
|
|
|
cell->nWidth = 0;
|
|
|
|
}
|
2020-10-08 12:10:46 +02:00
|
|
|
}
|
2020-10-23 11:25:03 +02:00
|
|
|
else if (para_cell( wc->para ))
|
2020-10-08 12:10:46 +02:00
|
|
|
{
|
2008-08-07 18:31:41 +02:00
|
|
|
int width;
|
|
|
|
|
2020-10-23 11:25:03 +02:00
|
|
|
cell = para_cell( wc->para );
|
2008-08-07 18:31:41 +02:00
|
|
|
width = cell->nRightBoundary;
|
2020-10-23 11:25:03 +02:00
|
|
|
if (cell_prev( cell )) width -= cell_prev( cell )->nRightBoundary;
|
|
|
|
else
|
2008-08-13 05:15:29 +02:00
|
|
|
{
|
2020-10-09 13:59:22 +02:00
|
|
|
int rowIndent = table_row_end( wc->para )->fmt.dxStartIndent;
|
2008-08-13 05:15:29 +02:00
|
|
|
width -= rowIndent;
|
|
|
|
}
|
2008-08-07 18:31:41 +02:00
|
|
|
cell->nWidth = max(ME_twips2pointsX(wc->context, width), 0);
|
|
|
|
|
|
|
|
wc->nAvailWidth = cell->nWidth
|
|
|
|
- (wc->nRow ? wc->nLeftMargin : wc->nFirstMargin) - wc->nRightMargin;
|
2008-10-10 23:50:44 +02:00
|
|
|
wc->bWordWrap = TRUE;
|
2020-10-23 11:25:03 +02:00
|
|
|
}
|
|
|
|
else
|
2009-02-02 07:32:20 +01:00
|
|
|
wc->nAvailWidth = wc->context->nAvailWidth
|
2008-12-18 07:56:49 +01:00
|
|
|
- (wc->nRow ? wc->nLeftMargin : wc->nFirstMargin) - wc->nRightMargin;
|
2020-10-23 11:25:03 +02:00
|
|
|
|
2008-08-07 18:31:41 +02:00
|
|
|
wc->pt.x = wc->context->pt.x;
|
2008-08-13 05:15:32 +02:00
|
|
|
if (wc->context->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
|
2020-10-23 11:25:03 +02:00
|
|
|
para_in_table( wc->para ))
|
2008-08-13 05:15:32 +02:00
|
|
|
/* Shift the text down because of the border. */
|
|
|
|
wc->pt.y++;
|
2005-04-16 12:48:35 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
static void layout_row( ME_Run *start, ME_Run *last )
|
2014-01-15 14:06:43 +01:00
|
|
|
{
|
2020-10-08 12:10:45 +02:00
|
|
|
ME_Run *run;
|
2014-01-15 14:06:43 +01:00
|
|
|
int i, num_runs = 0;
|
|
|
|
int buf[16 * 5]; /* 5 arrays - 4 of int & 1 of BYTE, alloc space for 5 of ints */
|
|
|
|
int *vis_to_log = buf, *log_to_vis, *widths, *pos;
|
|
|
|
BYTE *levels;
|
|
|
|
BOOL found_black = FALSE;
|
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
for (run = last; run; run = run_prev( run ))
|
2014-01-15 14:06:43 +01:00
|
|
|
{
|
2020-10-08 12:10:45 +02:00
|
|
|
if (!found_black) found_black = !(run->nFlags & (MERF_WHITESPACE | MERF_ENDPARA));
|
|
|
|
if (found_black) num_runs++;
|
|
|
|
if (run == start) break;
|
2014-01-15 14:06:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("%d runs\n", num_runs);
|
|
|
|
if (!num_runs) return;
|
|
|
|
|
2018-09-10 22:49:39 +02:00
|
|
|
if (num_runs > ARRAY_SIZE( buf ) / 5)
|
2014-01-15 14:06:43 +01:00
|
|
|
vis_to_log = heap_alloc( num_runs * sizeof(int) * 5 );
|
|
|
|
|
|
|
|
log_to_vis = vis_to_log + num_runs;
|
|
|
|
widths = vis_to_log + 2 * num_runs;
|
|
|
|
pos = vis_to_log + 3 * num_runs;
|
|
|
|
levels = (BYTE*)(vis_to_log + 4 * num_runs);
|
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
for (i = 0, run = start; i < num_runs; run = run_next( run ))
|
2014-01-15 14:06:43 +01:00
|
|
|
{
|
2020-10-08 12:10:45 +02:00
|
|
|
levels[i] = run->script_analysis.s.uBidiLevel;
|
|
|
|
widths[i] = run->nWidth;
|
|
|
|
TRACE( "%d: level %d width %d\n", i, levels[i], widths[i] );
|
|
|
|
i++;
|
2014-01-15 14:06:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ScriptLayout( num_runs, levels, vis_to_log, log_to_vis );
|
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
pos[0] = run->para->pt.x;
|
2014-01-15 14:06:43 +01:00
|
|
|
for (i = 1; i < num_runs; i++)
|
|
|
|
pos[i] = pos[i - 1] + widths[ vis_to_log[ i - 1 ] ];
|
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
for (i = 0, run = start; i < num_runs; run = run_next( run ))
|
2014-01-15 14:06:43 +01:00
|
|
|
{
|
2020-10-08 12:10:45 +02:00
|
|
|
run->pt.x = pos[ log_to_vis[ i ] ];
|
|
|
|
TRACE( "%d: x = %d\n", i, run->pt.x );
|
|
|
|
i++;
|
2014-01-15 14:06:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vis_to_log != buf) heap_free( vis_to_log );
|
|
|
|
}
|
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
static void ME_InsertRowStart( ME_WrapContext *wc, ME_Run *last )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-08 12:10:45 +02:00
|
|
|
ME_Run *run;
|
2020-11-04 07:56:24 +01:00
|
|
|
ME_Row *row;
|
2020-10-08 12:10:45 +02:00
|
|
|
BOOL bSkippingSpaces = TRUE;
|
|
|
|
int ascent = 0, descent = 0, width = 0, shift = 0, align = 0;
|
2013-11-21 13:26:52 +01:00
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
/* Include height of para numbering label */
|
2020-10-08 12:10:46 +02:00
|
|
|
if (wc->nRow == 0 && wc->para->fmt.wNumbering)
|
2020-10-08 12:10:45 +02:00
|
|
|
{
|
2020-10-08 12:10:46 +02:00
|
|
|
ascent = wc->para->para_num.style->tm.tmAscent;
|
|
|
|
descent = wc->para->para_num.style->tm.tmDescent;
|
2020-10-08 12:10:45 +02:00
|
|
|
}
|
2008-06-23 23:09:53 +02:00
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
for (run = last; run; run = run_prev( run ))
|
|
|
|
{
|
|
|
|
/* ENDPARA run shouldn't affect row height, except if it's the only run in the paragraph */
|
|
|
|
if (run == wc->pRowStart || !(run->nFlags & MERF_ENDPARA))
|
2008-06-23 23:09:53 +02:00
|
|
|
{
|
2020-10-08 12:10:46 +02:00
|
|
|
if (run->nAscent > ascent) ascent = run->nAscent;
|
|
|
|
if (run->nDescent > descent) descent = run->nDescent;
|
2020-10-08 12:10:45 +02:00
|
|
|
if (bSkippingSpaces)
|
|
|
|
{
|
|
|
|
/* Exclude space characters from run width.
|
|
|
|
* Other whitespace or delimiters are not treated this way. */
|
|
|
|
int len = run->len;
|
|
|
|
WCHAR *text = get_text( run, len - 1 );
|
|
|
|
|
|
|
|
assert(len);
|
|
|
|
if (~run->nFlags & MERF_GRAPHICS)
|
|
|
|
while (len && *(text--) == ' ') len--;
|
|
|
|
if (len)
|
|
|
|
{
|
|
|
|
if (len == run->len)
|
|
|
|
width += run->nWidth;
|
|
|
|
else
|
|
|
|
width += ME_PointFromCharContext( wc->context, run, len, FALSE );
|
|
|
|
}
|
|
|
|
bSkippingSpaces = !len;
|
|
|
|
}
|
|
|
|
else if (!(run->nFlags & MERF_ENDPARA))
|
|
|
|
width += run->nWidth;
|
|
|
|
}
|
|
|
|
if (run == wc->pRowStart) break;
|
|
|
|
}
|
2008-06-23 23:09:53 +02:00
|
|
|
|
2020-10-08 12:10:46 +02:00
|
|
|
wc->para->nWidth = max( wc->para->nWidth, width );
|
2020-11-04 07:56:24 +01:00
|
|
|
row = row_create( ascent + descent, ascent, width );
|
2020-10-08 12:10:45 +02:00
|
|
|
if (wc->context->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
|
2020-10-08 12:10:46 +02:00
|
|
|
(wc->para->fmt.dwMask & PFM_TABLE) && (wc->para->fmt.wEffects & PFE_TABLE))
|
2020-10-08 12:10:45 +02:00
|
|
|
{
|
|
|
|
/* The text was shifted down in ME_BeginRow so move the wrap context
|
|
|
|
* back to where it should be. */
|
|
|
|
wc->pt.y--;
|
|
|
|
/* The height of the row is increased by the borders. */
|
2020-11-04 07:56:24 +01:00
|
|
|
row->nHeight += 2;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2020-11-04 07:56:24 +01:00
|
|
|
row->pt = wc->pt;
|
|
|
|
row->nLMargin = (!wc->nRow ? wc->nFirstMargin : wc->nLeftMargin);
|
|
|
|
row->nRMargin = wc->nRightMargin;
|
2020-10-08 12:10:46 +02:00
|
|
|
assert(wc->para->fmt.dwMask & PFM_ALIGNMENT);
|
|
|
|
align = wc->para->fmt.wAlignment;
|
2020-10-08 12:10:45 +02:00
|
|
|
if (align == PFA_CENTER) shift = max((wc->nAvailWidth-width)/2, 0);
|
|
|
|
if (align == PFA_RIGHT) shift = max(wc->nAvailWidth-width, 0);
|
2016-10-07 11:49:35 +02:00
|
|
|
|
2020-10-08 12:10:46 +02:00
|
|
|
if (wc->para->nFlags & MEPF_COMPLEX) layout_row( wc->pRowStart, last );
|
2016-10-07 11:49:35 +02:00
|
|
|
|
2020-11-04 07:56:24 +01:00
|
|
|
row->pt.x = row->nLMargin + shift;
|
2020-10-08 12:10:45 +02:00
|
|
|
|
|
|
|
for (run = wc->pRowStart; run; run = run_next( run ))
|
|
|
|
{
|
2020-11-04 07:56:24 +01:00
|
|
|
run->pt.x += row->nLMargin + shift;
|
2020-10-08 12:10:45 +02:00
|
|
|
if (run == last) break;
|
|
|
|
}
|
|
|
|
|
2020-10-08 12:10:46 +02:00
|
|
|
if (wc->nRow == 0 && wc->para->fmt.wNumbering)
|
2020-10-08 12:10:45 +02:00
|
|
|
{
|
2020-10-08 12:10:46 +02:00
|
|
|
wc->para->para_num.pt.x = wc->nParaNumOffset + shift;
|
2020-11-04 07:56:24 +01:00
|
|
|
wc->para->para_num.pt.y = wc->pt.y + row->nBaseline;
|
2020-10-08 12:10:45 +02:00
|
|
|
}
|
|
|
|
|
2020-11-04 07:56:24 +01:00
|
|
|
ME_InsertBefore( run_get_di( wc->pRowStart ), row_get_di( row ) );
|
2020-10-08 12:10:45 +02:00
|
|
|
wc->nRow++;
|
2020-11-04 07:56:24 +01:00
|
|
|
wc->pt.y += row->nHeight;
|
2020-10-08 12:10:45 +02:00
|
|
|
ME_BeginRow( wc );
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
static void ME_WrapEndParagraph( ME_WrapContext *wc )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-08 12:10:46 +02:00
|
|
|
if (wc->pRowStart) ME_InsertRowStart( wc, wc->para->eop_run );
|
2020-10-08 12:10:45 +02:00
|
|
|
|
2008-08-13 05:15:32 +02:00
|
|
|
if (wc->context->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
|
2020-10-08 12:10:46 +02:00
|
|
|
wc->para->fmt.dwMask & PFM_TABLE && wc->para->fmt.wEffects & PFE_TABLE)
|
2008-08-13 05:15:32 +02:00
|
|
|
{
|
|
|
|
/* ME_BeginRow was called an extra time for the paragraph, and it shifts the
|
|
|
|
* text down by one pixel for the border, so fix up the wrap context. */
|
|
|
|
wc->pt.y--;
|
|
|
|
}
|
2005-04-16 12:48:35 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
static void ME_WrapSizeRun( ME_WrapContext *wc, ME_Run *run )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
/* FIXME compose style (out of character and paragraph styles) here */
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
ME_UpdateRunFlags( wc->context->editor, run );
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2020-10-08 12:10:46 +02:00
|
|
|
calc_run_extent( wc->context, wc->para,
|
2020-10-08 12:10:45 +02:00
|
|
|
wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, run );
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2013-02-05 14:19:40 +01:00
|
|
|
|
|
|
|
static int find_non_whitespace(const WCHAR *s, int len, int start)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = start; i < len && ME_IsWSpace( s[i] ); i++)
|
|
|
|
;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* note: these two really return the first matching offset (starting from EOS)+1
|
|
|
|
* in other words, an offset of the first trailing white/black */
|
|
|
|
|
|
|
|
/* note: returns offset of the first trailing whitespace */
|
|
|
|
static int reverse_find_non_whitespace(const WCHAR *s, int start)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = start; i > 0 && ME_IsWSpace( s[i - 1] ); i--)
|
|
|
|
;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* note: returns offset of the first trailing nonwhitespace */
|
|
|
|
static int reverse_find_whitespace(const WCHAR *s, int start)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = start; i > 0 && !ME_IsWSpace( s[i - 1] ); i--)
|
|
|
|
;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
static ME_Run *ME_MaximizeSplit( ME_WrapContext *wc, ME_Run *run, int i )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-08 12:10:45 +02:00
|
|
|
ME_Run *new_run, *iter = run;
|
2005-03-05 12:19:14 +01:00
|
|
|
int j;
|
|
|
|
if (!i)
|
|
|
|
return NULL;
|
2020-10-08 12:10:45 +02:00
|
|
|
j = reverse_find_non_whitespace( get_text( run, 0 ), i );
|
|
|
|
if (j > 0)
|
|
|
|
{
|
|
|
|
new_run = split_run_extents( wc, iter, j );
|
|
|
|
wc->pt.x += iter->nWidth;
|
|
|
|
return new_run;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-08 12:10:45 +02:00
|
|
|
new_run = iter;
|
2005-03-05 12:19:14 +01:00
|
|
|
/* omit all spaces before split point */
|
2020-10-08 12:10:45 +02:00
|
|
|
while (iter != wc->pRowStart)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-08 12:10:45 +02:00
|
|
|
iter = run_prev( iter );
|
|
|
|
if (iter->nFlags & MERF_WHITESPACE)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-08 12:10:45 +02:00
|
|
|
new_run = iter;
|
2005-03-05 12:19:14 +01:00
|
|
|
continue;
|
|
|
|
}
|
2020-10-08 12:10:45 +02:00
|
|
|
if (iter->nFlags & MERF_ENDWHITE)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-08 12:10:45 +02:00
|
|
|
i = reverse_find_non_whitespace( get_text( iter, 0 ), iter->len );
|
|
|
|
new_run = split_run_extents( wc, iter, i );
|
|
|
|
wc->pt = new_run->pt;
|
|
|
|
return new_run;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
/* this run is the end of spaces, so the run edge is a good point to split */
|
2020-10-08 12:10:45 +02:00
|
|
|
wc->pt = new_run->pt;
|
2005-03-05 12:19:14 +01:00
|
|
|
wc->bOverflown = TRUE;
|
2020-10-08 12:10:45 +02:00
|
|
|
TRACE( "Split point is: %s|%s\n", debugstr_run( iter ), debugstr_run( new_run ) );
|
|
|
|
return new_run;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2020-10-08 12:10:45 +02:00
|
|
|
wc->pt = iter->pt;
|
|
|
|
return iter;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
static ME_Run *ME_SplitByBacktracking( ME_WrapContext *wc, ME_Run *run, int loc )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-08 12:10:45 +02:00
|
|
|
ME_Run *new_run;
|
2005-03-05 12:19:14 +01:00
|
|
|
int i, idesp, len;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2013-02-08 12:45:03 +01:00
|
|
|
idesp = i = find_split_point( wc->context, loc, run );
|
2013-01-31 14:48:00 +01:00
|
|
|
len = run->len;
|
2020-10-08 12:10:45 +02:00
|
|
|
assert( len > 0 );
|
|
|
|
assert( i < len );
|
|
|
|
if (i)
|
|
|
|
{
|
2005-03-05 12:19:14 +01:00
|
|
|
/* don't split words */
|
2013-02-05 14:19:40 +01:00
|
|
|
i = reverse_find_whitespace( get_text( run, 0 ), i );
|
2020-10-08 12:10:45 +02:00
|
|
|
new_run = ME_MaximizeSplit(wc, run, i);
|
2020-10-07 14:20:39 +02:00
|
|
|
if (new_run) return new_run;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2020-10-08 12:10:45 +02:00
|
|
|
TRACE("Must backtrack to split at: %s\n", debugstr_run( run ));
|
2005-03-05 12:19:14 +01:00
|
|
|
if (wc->pLastSplittableRun)
|
|
|
|
{
|
2020-10-08 12:10:45 +02:00
|
|
|
if (wc->pLastSplittableRun->nFlags & (MERF_GRAPHICS|MERF_TAB))
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-08 12:10:45 +02:00
|
|
|
wc->pt = wc->pLastSplittableRun->pt;
|
2005-03-05 12:19:14 +01:00
|
|
|
return wc->pLastSplittableRun;
|
|
|
|
}
|
2020-10-08 12:10:45 +02:00
|
|
|
else if (wc->pLastSplittableRun->nFlags & MERF_SPLITTABLE)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
/* the following two lines are just to check if we forgot to call UpdateRunFlags earlier,
|
|
|
|
they serve no other purpose */
|
|
|
|
ME_UpdateRunFlags(wc->context->editor, run);
|
2020-10-08 12:10:45 +02:00
|
|
|
assert((wc->pLastSplittableRun->nFlags & MERF_SPLITTABLE));
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
run = wc->pLastSplittableRun;
|
2013-01-31 14:48:00 +01:00
|
|
|
len = run->len;
|
2005-03-05 12:19:14 +01:00
|
|
|
/* don't split words */
|
2013-02-05 14:19:40 +01:00
|
|
|
i = reverse_find_whitespace( get_text( run, 0 ), len );
|
2005-03-05 12:19:14 +01:00
|
|
|
if (i == len)
|
2013-02-05 14:19:40 +01:00
|
|
|
i = reverse_find_non_whitespace( get_text( run, 0 ), len );
|
2020-10-08 12:10:45 +02:00
|
|
|
new_run = split_run_extents(wc, run, i);
|
|
|
|
wc->pt = new_run->pt;
|
2020-10-07 14:20:39 +02:00
|
|
|
return new_run;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* restart from the first run beginning with spaces */
|
2020-10-08 12:10:45 +02:00
|
|
|
wc->pt = wc->pLastSplittableRun->pt;
|
2005-03-05 12:19:14 +01:00
|
|
|
return wc->pLastSplittableRun;
|
|
|
|
}
|
|
|
|
}
|
2020-10-08 12:10:45 +02:00
|
|
|
TRACE("Backtracking failed, trying desperate: %s\n", debugstr_run( run ));
|
2005-03-05 12:19:14 +01:00
|
|
|
/* OK, no better idea, so assume we MAY split words if we can split at all*/
|
|
|
|
if (idesp)
|
2020-10-08 12:10:45 +02:00
|
|
|
return split_run_extents(wc, run, idesp);
|
2005-03-05 12:19:14 +01:00
|
|
|
else
|
2020-10-08 12:10:45 +02:00
|
|
|
if (wc->pRowStart && run != wc->pRowStart)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
/* don't need to break current run, because it's possible to split
|
|
|
|
before this run */
|
|
|
|
wc->bOverflown = TRUE;
|
2020-10-08 12:10:45 +02:00
|
|
|
return run;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* split point inside first character - no choice but split after that char */
|
2020-10-08 12:10:45 +02:00
|
|
|
if (len != 1)
|
2005-03-05 12:19:14 +01:00
|
|
|
/* the run is more than 1 char, so we may split */
|
2020-10-08 12:10:45 +02:00
|
|
|
return split_run_extents( wc, run, 1 );
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
/* the run is one char, can't split it */
|
2020-10-08 12:10:45 +02:00
|
|
|
return run;
|
2005-04-16 12:48:35 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
static ME_Run *ME_WrapHandleRun( ME_WrapContext *wc, ME_Run *run )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-08 12:10:45 +02:00
|
|
|
ME_Run *new_run;
|
2005-03-05 12:19:14 +01:00
|
|
|
int len;
|
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
if (!wc->pRowStart) wc->pRowStart = run;
|
2005-03-05 12:19:14 +01:00
|
|
|
run->pt.x = wc->pt.x;
|
|
|
|
run->pt.y = wc->pt.y;
|
2020-10-08 12:10:45 +02:00
|
|
|
ME_WrapSizeRun( wc, run );
|
2013-01-31 14:48:00 +01:00
|
|
|
len = run->len;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
if (wc->bOverflown) /* just skipping final whitespaces */
|
2005-04-16 12:48:35 +02:00
|
|
|
{
|
2008-07-10 16:17:30 +02:00
|
|
|
/* End paragraph run can't overflow to the next line by itself. */
|
2020-10-08 12:10:45 +02:00
|
|
|
if (run->nFlags & MERF_ENDPARA) return run_next( run );
|
2008-07-10 16:17:30 +02:00
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
if (run->nFlags & MERF_WHITESPACE)
|
|
|
|
{
|
2008-07-10 16:17:39 +02:00
|
|
|
wc->pt.x += run->nWidth;
|
2005-03-05 12:19:14 +01:00
|
|
|
/* skip runs consisting of only whitespaces */
|
2020-10-08 12:10:45 +02:00
|
|
|
return run_next( run );
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
if (run->nFlags & MERF_STARTWHITE)
|
|
|
|
{
|
2005-03-05 12:19:14 +01:00
|
|
|
/* try to split the run at the first non-white char */
|
|
|
|
int black;
|
2013-02-05 14:19:40 +01:00
|
|
|
black = find_non_whitespace( get_text( run, 0 ), run->len, 0 );
|
2020-10-08 12:10:45 +02:00
|
|
|
if (black)
|
|
|
|
{
|
|
|
|
ME_Run *new_run;
|
2005-03-05 12:19:14 +01:00
|
|
|
wc->bOverflown = FALSE;
|
2020-10-08 12:10:45 +02:00
|
|
|
new_run = split_run_extents( wc, run, black );
|
2020-10-08 12:10:46 +02:00
|
|
|
calc_run_extent( wc->context, wc->para,
|
2020-10-08 12:10:45 +02:00
|
|
|
wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, run );
|
|
|
|
ME_InsertRowStart( wc, run );
|
|
|
|
return new_run;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* black run: the row goes from pRowStart to the previous run */
|
2020-10-08 12:10:45 +02:00
|
|
|
ME_InsertRowStart( wc, run_prev( run ) );
|
|
|
|
return run;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2008-03-16 21:46:36 +01:00
|
|
|
/* simply end the current row and move on to next one */
|
|
|
|
if (run->nFlags & MERF_ENDROW)
|
|
|
|
{
|
2020-10-08 12:10:45 +02:00
|
|
|
ME_InsertRowStart( wc, run );
|
|
|
|
return run_next( run );
|
2008-03-16 21:46:36 +01:00
|
|
|
}
|
2008-03-16 21:47:08 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
/* will current run fit? */
|
2008-10-10 23:50:44 +02:00
|
|
|
if (wc->bWordWrap &&
|
|
|
|
wc->pt.x + run->nWidth - wc->context->pt.x > wc->nAvailWidth)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2008-08-07 18:31:41 +02:00
|
|
|
int loc = wc->context->pt.x + wc->nAvailWidth - wc->pt.x;
|
2016-10-07 11:49:30 +02:00
|
|
|
/* total white run or end para */
|
|
|
|
if (run->nFlags & (MERF_WHITESPACE | MERF_ENDPARA)) {
|
2005-03-05 12:19:14 +01:00
|
|
|
/* let the overflow logic handle it */
|
|
|
|
wc->bOverflown = TRUE;
|
2020-10-08 12:10:45 +02:00
|
|
|
return run;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2008-01-27 19:01:58 +01:00
|
|
|
/* TAB: we can split before */
|
|
|
|
if (run->nFlags & MERF_TAB) {
|
|
|
|
wc->bOverflown = TRUE;
|
2020-10-08 12:10:45 +02:00
|
|
|
if (wc->pRowStart == run)
|
2008-07-17 17:55:19 +02:00
|
|
|
/* Don't split before the start of the run, or we will get an
|
|
|
|
* endless loop. */
|
2020-10-08 12:10:45 +02:00
|
|
|
return run_next( run );
|
2008-07-17 17:55:19 +02:00
|
|
|
else
|
2020-10-08 12:10:45 +02:00
|
|
|
return run;
|
2008-01-27 19:01:58 +01:00
|
|
|
}
|
|
|
|
/* graphics: we can split before, if run's width is smaller than row's width */
|
|
|
|
if ((run->nFlags & MERF_GRAPHICS) && run->nWidth <= wc->nAvailWidth) {
|
2005-03-05 12:19:14 +01:00
|
|
|
wc->bOverflown = TRUE;
|
2020-10-08 12:10:45 +02:00
|
|
|
return run;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
/* can we separate out the last spaces ? (to use overflow logic later) */
|
|
|
|
if (run->nFlags & MERF_ENDWHITE)
|
|
|
|
{
|
|
|
|
/* we aren't sure if it's *really* necessary, it's a good start however */
|
2013-02-05 14:19:40 +01:00
|
|
|
int black = reverse_find_non_whitespace( get_text( run, 0 ), len );
|
2020-10-08 12:10:45 +02:00
|
|
|
split_run_extents( wc, run, black );
|
2005-03-05 12:19:14 +01:00
|
|
|
/* handle both parts again */
|
2020-10-08 12:10:45 +02:00
|
|
|
return run;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
/* determine the split point by backtracking */
|
2020-10-08 12:10:45 +02:00
|
|
|
new_run = ME_SplitByBacktracking( wc, run, loc );
|
|
|
|
if (new_run == wc->pRowStart)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2008-07-10 16:17:43 +02:00
|
|
|
if (run->nFlags & MERF_STARTWHITE)
|
|
|
|
{
|
2008-10-03 06:49:39 +02:00
|
|
|
/* We had only spaces so far, so we must be on the first line of the
|
|
|
|
* paragraph (or the first line after MERF_ENDROW forced the line
|
|
|
|
* break within the paragraph), since no other lines of the paragraph
|
|
|
|
* start with spaces. */
|
|
|
|
|
2008-07-10 16:17:43 +02:00
|
|
|
/* The lines will only contain spaces, and the rest of the run will
|
|
|
|
* overflow onto the next line. */
|
|
|
|
wc->bOverflown = TRUE;
|
2020-10-08 12:10:45 +02:00
|
|
|
return run;
|
2008-07-10 16:17:43 +02:00
|
|
|
}
|
|
|
|
/* Couldn't split the first run, possible because we have a large font
|
|
|
|
* with a single character that caused an overflow.
|
|
|
|
*/
|
2008-07-10 16:17:39 +02:00
|
|
|
wc->pt.x += run->nWidth;
|
2020-10-08 12:10:45 +02:00
|
|
|
return run_next( run );
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2020-10-08 12:10:45 +02:00
|
|
|
if (run != new_run) /* found a suitable split point */
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
wc->bOverflown = TRUE;
|
2020-10-08 12:10:45 +02:00
|
|
|
return new_run;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
/* we detected that it's best to split on start of this run */
|
|
|
|
if (wc->bOverflown)
|
2020-10-08 12:10:45 +02:00
|
|
|
return new_run;
|
2005-03-05 12:19:14 +01:00
|
|
|
ERR("failure!\n");
|
|
|
|
/* not found anything - writing over margins is the only option left */
|
|
|
|
}
|
2005-04-16 12:48:35 +02:00
|
|
|
if ((run->nFlags & (MERF_SPLITTABLE | MERF_STARTWHITE))
|
2020-10-08 12:10:45 +02:00
|
|
|
|| ((run->nFlags & (MERF_GRAPHICS|MERF_TAB)) && (run != wc->pRowStart)))
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-08 12:10:45 +02:00
|
|
|
wc->pLastSplittableRun = run;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
wc->pt.x += run->nWidth;
|
2020-10-08 12:10:45 +02:00
|
|
|
return run_next( run );
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2010-02-09 18:07:22 +01:00
|
|
|
static int ME_GetParaLineSpace(ME_Context* c, ME_Paragraph* para)
|
|
|
|
{
|
|
|
|
int sp = 0, ls = 0;
|
2016-09-29 11:13:11 +02:00
|
|
|
if (!(para->fmt.dwMask & PFM_LINESPACING)) return 0;
|
2010-02-09 18:07:22 +01:00
|
|
|
|
|
|
|
/* FIXME: how to compute simply the line space in ls ??? */
|
|
|
|
/* FIXME: does line spacing include the line itself ??? */
|
2016-09-29 11:13:11 +02:00
|
|
|
switch (para->fmt.bLineSpacingRule)
|
2010-02-09 18:07:22 +01:00
|
|
|
{
|
|
|
|
case 0: sp = ls; break;
|
|
|
|
case 1: sp = (3 * ls) / 2; break;
|
|
|
|
case 2: sp = 2 * ls; break;
|
2016-09-29 11:13:11 +02:00
|
|
|
case 3: sp = ME_twips2pointsY(c, para->fmt.dyLineSpacing); if (sp < ls) sp = ls; break;
|
|
|
|
case 4: sp = ME_twips2pointsY(c, para->fmt.dyLineSpacing); break;
|
|
|
|
case 5: sp = para->fmt.dyLineSpacing / 20; break;
|
|
|
|
default: FIXME("Unsupported spacing rule value %d\n", para->fmt.bLineSpacingRule);
|
2010-02-09 18:07:22 +01:00
|
|
|
}
|
|
|
|
if (c->editor->nZoomNumerator == 0)
|
|
|
|
return sp;
|
|
|
|
else
|
|
|
|
return sp * c->editor->nZoomNumerator / c->editor->nZoomDenominator;
|
|
|
|
}
|
|
|
|
|
2020-10-08 12:10:47 +02:00
|
|
|
static void ME_PrepareParagraphForWrapping( ME_TextEditor *editor, ME_Context *c, ME_Paragraph *para )
|
|
|
|
{
|
|
|
|
ME_DisplayItem *p;
|
|
|
|
|
|
|
|
para->nWidth = 0;
|
|
|
|
/* remove row start items as they will be reinserted by the
|
|
|
|
* paragraph wrapper anyway */
|
|
|
|
editor->total_rows -= para->nRows;
|
|
|
|
para->nRows = 0;
|
|
|
|
for (p = para_get_di( para ); p != para->next_para; p = p->next)
|
|
|
|
{
|
|
|
|
if (p->type == diStartRow)
|
|
|
|
{
|
|
|
|
ME_DisplayItem *pRow = p;
|
|
|
|
p = p->prev;
|
|
|
|
ME_Remove( pRow );
|
|
|
|
ME_DestroyDisplayItem( pRow );
|
|
|
|
}
|
2011-10-22 20:17:04 +02:00
|
|
|
}
|
2020-10-08 12:10:47 +02:00
|
|
|
|
|
|
|
/* join runs that can be joined */
|
|
|
|
for (p = para_get_di( para )->next; p != para->next_para; p = p->next)
|
|
|
|
{
|
|
|
|
assert(p->type != diStartRow); /* should have been deleted above */
|
|
|
|
if (p->type == diRun)
|
|
|
|
{
|
|
|
|
while (p->next->type == diRun && ME_CanJoinRuns( &p->member.run, &p->next->member.run ))
|
2020-10-13 12:16:36 +02:00
|
|
|
run_join( c->editor, &p->member.run );
|
2020-10-08 12:10:47 +02:00
|
|
|
}
|
2011-10-22 20:17:04 +02:00
|
|
|
}
|
|
|
|
}
|
2007-12-14 07:45:28 +01:00
|
|
|
|
2020-10-08 12:10:48 +02:00
|
|
|
static HRESULT itemize_para( ME_Context *c, ME_Paragraph *para )
|
2014-01-15 14:06:43 +01:00
|
|
|
{
|
|
|
|
ME_Run *run;
|
|
|
|
SCRIPT_ITEM buf[16], *items = buf;
|
2018-09-10 22:49:39 +02:00
|
|
|
int items_passed = ARRAY_SIZE( buf ), num_items, cur_item;
|
2014-01-15 14:06:43 +01:00
|
|
|
SCRIPT_CONTROL control = { LANG_USER_DEFAULT, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
|
|
|
|
FALSE, FALSE, 0 };
|
|
|
|
SCRIPT_STATE state = { 0, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 0, 0 };
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-09-29 11:13:11 +02:00
|
|
|
if (para->fmt.dwMask & PFM_RTLPARA && para->fmt.wEffects & PFE_RTLPARA)
|
2016-03-10 12:59:42 +01:00
|
|
|
state.uBidiLevel = 1;
|
|
|
|
|
|
|
|
TRACE( "Base embedding level %d\n", state.uBidiLevel );
|
|
|
|
|
2014-01-15 14:06:43 +01:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
hr = ScriptItemize( para->text->szData, para->text->nLen, items_passed, &control,
|
|
|
|
&state, items, &num_items );
|
|
|
|
if (hr != E_OUTOFMEMORY) break; /* may not be enough items if hr == E_OUTOFMEMORY */
|
|
|
|
if (items_passed > para->text->nLen + 1) break; /* something else has gone wrong */
|
|
|
|
items_passed *= 2;
|
|
|
|
if (items == buf)
|
|
|
|
items = heap_alloc( items_passed * sizeof( *items ) );
|
|
|
|
else
|
|
|
|
items = heap_realloc( items, items_passed * sizeof( *items ) );
|
|
|
|
if (!items) break;
|
|
|
|
}
|
|
|
|
if (FAILED( hr )) goto end;
|
|
|
|
|
|
|
|
if (TRACE_ON( richedit ))
|
|
|
|
{
|
|
|
|
TRACE( "got items:\n" );
|
|
|
|
for (cur_item = 0; cur_item < num_items; cur_item++)
|
|
|
|
{
|
|
|
|
TRACE( "\t%d - %d RTL %d bidi level %d\n", items[cur_item].iCharPos, items[cur_item+1].iCharPos - 1,
|
|
|
|
items[cur_item].a.fRTL, items[cur_item].a.s.uBidiLevel );
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE( "before splitting runs into ranges\n" );
|
2020-10-08 12:10:48 +02:00
|
|
|
for (run = para_first_run( para ); run; run = run_next( run ))
|
|
|
|
TRACE( "\t%d: %s\n", run->nCharOfs, debugstr_run( run ) );
|
2014-01-15 14:06:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* split runs into ranges at item boundaries */
|
2020-10-08 12:10:48 +02:00
|
|
|
for (run = para_first_run( para ), cur_item = 0; run; run = run_next( run ))
|
2014-01-15 14:06:43 +01:00
|
|
|
{
|
|
|
|
if (run->nCharOfs == items[cur_item+1].iCharPos) cur_item++;
|
|
|
|
|
|
|
|
items[cur_item].a.fLogicalOrder = TRUE;
|
|
|
|
run->script_analysis = items[cur_item].a;
|
|
|
|
|
|
|
|
if (run->nFlags & MERF_ENDPARA) break; /* don't split eop runs */
|
|
|
|
|
|
|
|
if (run->nCharOfs + run->len > items[cur_item+1].iCharPos)
|
|
|
|
{
|
2020-10-08 12:10:48 +02:00
|
|
|
ME_Cursor cursor = {para_get_di( para ), run_get_di( run ), items[cur_item+1].iCharPos - run->nCharOfs};
|
2020-10-14 12:17:14 +02:00
|
|
|
run_split( c->editor, &cursor );
|
2014-01-15 14:06:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TRACE_ON( richedit ))
|
|
|
|
{
|
|
|
|
TRACE( "after splitting into ranges\n" );
|
2020-10-08 12:10:48 +02:00
|
|
|
for (run = para_first_run( para ); run; run = run_next( run ))
|
|
|
|
TRACE( "\t%d: %s\n", run->nCharOfs, debugstr_run( run ) );
|
2014-01-15 14:06:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
para->nFlags |= MEPF_COMPLEX;
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (items != buf) heap_free( items );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-08 12:10:49 +02:00
|
|
|
static HRESULT shape_para( ME_Context *c, ME_Paragraph *para )
|
2014-01-15 14:06:43 +01:00
|
|
|
{
|
|
|
|
ME_Run *run;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2020-10-08 12:10:49 +02:00
|
|
|
for (run = para_first_run( para ); run; run = run_next( run ))
|
2014-01-15 14:06:43 +01:00
|
|
|
{
|
|
|
|
hr = shape_run( c, run );
|
|
|
|
if (FAILED( hr ))
|
|
|
|
{
|
2020-10-08 12:10:49 +02:00
|
|
|
para->nFlags &= ~MEPF_COMPLEX;
|
2014-01-15 14:06:43 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-10-08 12:10:47 +02:00
|
|
|
static void ME_WrapTextParagraph( ME_TextEditor *editor, ME_Context *c, ME_Paragraph *para )
|
2020-10-08 12:10:45 +02:00
|
|
|
{
|
|
|
|
ME_Run *run;
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_WrapContext wc;
|
2008-01-01 22:04:46 +01:00
|
|
|
int border = 0;
|
2008-01-01 22:04:58 +01:00
|
|
|
int linespace = 0;
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2020-10-08 12:10:47 +02:00
|
|
|
if (!(para->nFlags & MEPF_REWRAP)) return;
|
|
|
|
|
|
|
|
ME_PrepareParagraphForWrapping( editor, c, para );
|
2014-01-15 14:06:43 +01:00
|
|
|
|
2016-10-07 11:49:35 +02:00
|
|
|
/* Calculate paragraph numbering label */
|
2020-10-08 12:10:47 +02:00
|
|
|
para_num_init( c, para );
|
2016-10-07 11:49:35 +02:00
|
|
|
|
2014-01-15 14:06:43 +01:00
|
|
|
/* For now treating all non-password text as complex for better testing */
|
|
|
|
if (!c->editor->cPasswordMask /* &&
|
|
|
|
ScriptIsComplex( tp->member.para.text->szData, tp->member.para.text->nLen, SIC_COMPLEX ) == S_OK */)
|
|
|
|
{
|
2020-10-08 12:10:48 +02:00
|
|
|
if (SUCCEEDED( itemize_para( c, para ) ))
|
2020-10-08 12:10:49 +02:00
|
|
|
shape_para( c, para );
|
2014-01-15 14:06:43 +01:00
|
|
|
}
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
wc.context = c;
|
2020-10-08 12:10:47 +02:00
|
|
|
wc.para = para;
|
2005-03-05 12:19:14 +01:00
|
|
|
wc.style = NULL;
|
2016-10-07 11:49:35 +02:00
|
|
|
wc.nParaNumOffset = 0;
|
2020-10-08 12:10:47 +02:00
|
|
|
if (para->nFlags & MEPF_ROWEND)
|
2008-08-13 05:15:29 +02:00
|
|
|
wc.nFirstMargin = wc.nLeftMargin = wc.nRightMargin = 0;
|
2020-10-08 12:10:47 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
int dxStartIndent = para->fmt.dxStartIndent;
|
2020-10-23 11:25:03 +02:00
|
|
|
if (para_cell( wc.para )) dxStartIndent += table_row_end( para )->fmt.dxOffset;
|
2020-10-08 12:10:47 +02:00
|
|
|
|
|
|
|
wc.nLeftMargin = ME_twips2pointsX( c, dxStartIndent + para->fmt.dxOffset );
|
|
|
|
wc.nFirstMargin = ME_twips2pointsX( c, dxStartIndent );
|
|
|
|
if (para->fmt.wNumbering)
|
2016-10-07 11:49:35 +02:00
|
|
|
{
|
|
|
|
wc.nParaNumOffset = wc.nFirstMargin;
|
2020-10-08 12:10:47 +02:00
|
|
|
dxStartIndent = max( ME_twips2pointsX(c, para->fmt.wNumberingTab),
|
|
|
|
para->para_num.width );
|
2016-10-07 11:49:35 +02:00
|
|
|
wc.nFirstMargin += dxStartIndent;
|
|
|
|
}
|
2020-10-08 12:10:47 +02:00
|
|
|
wc.nRightMargin = ME_twips2pointsX( c, para->fmt.dxRightIndent );
|
2016-04-18 15:14:39 +02:00
|
|
|
|
2020-10-08 12:10:47 +02:00
|
|
|
if (wc.nFirstMargin < 0) wc.nFirstMargin = 0;
|
|
|
|
if (wc.nLeftMargin < 0) wc.nLeftMargin = 0;
|
2008-08-13 05:15:29 +02:00
|
|
|
}
|
|
|
|
if (c->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
|
2020-10-08 12:10:47 +02:00
|
|
|
para->fmt.dwMask & PFM_TABLE && para->fmt.wEffects & PFE_TABLE)
|
2008-08-13 05:15:29 +02:00
|
|
|
{
|
2020-10-08 12:10:47 +02:00
|
|
|
wc.nFirstMargin += ME_twips2pointsX( c, para->fmt.dxOffset * 2 );
|
2008-08-13 05:15:29 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
wc.nRow = 0;
|
|
|
|
wc.pt.y = 0;
|
2020-10-08 12:10:47 +02:00
|
|
|
if (para->fmt.dwMask & PFM_SPACEBEFORE)
|
|
|
|
wc.pt.y += ME_twips2pointsY( c, para->fmt.dySpaceBefore );
|
|
|
|
if (!(para->fmt.dwMask & PFM_TABLE && para->fmt.wEffects & PFE_TABLE) &&
|
|
|
|
para->fmt.dwMask & PFM_BORDER)
|
2008-01-01 22:04:46 +01:00
|
|
|
{
|
2020-10-08 12:10:47 +02:00
|
|
|
border = ME_GetParaBorderWidth( c, para->fmt.wBorders );
|
|
|
|
if (para->fmt.wBorders & 1)
|
|
|
|
{
|
2008-01-01 22:04:46 +01:00
|
|
|
wc.nFirstMargin += border;
|
|
|
|
wc.nLeftMargin += border;
|
|
|
|
}
|
2020-10-08 12:10:47 +02:00
|
|
|
if (para->fmt.wBorders & 2) wc.nRightMargin -= border;
|
|
|
|
if (para->fmt.wBorders & 4) wc.pt.y += border;
|
2008-01-01 22:04:46 +01:00
|
|
|
}
|
|
|
|
|
2020-10-08 12:10:47 +02:00
|
|
|
linespace = ME_GetParaLineSpace( c, para );
|
2008-01-01 22:04:58 +01:00
|
|
|
|
2020-10-08 12:10:47 +02:00
|
|
|
ME_BeginRow( &wc );
|
2020-10-28 09:43:53 +01:00
|
|
|
run = para_first_run( para );
|
2020-10-08 12:10:45 +02:00
|
|
|
while (run)
|
|
|
|
{
|
|
|
|
run = ME_WrapHandleRun( &wc, run );
|
|
|
|
if (wc.nRow && run == wc.pRowStart) wc.pt.y += linespace;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2020-10-08 12:10:45 +02:00
|
|
|
ME_WrapEndParagraph( &wc );
|
2020-10-08 12:10:47 +02:00
|
|
|
if (!(para->fmt.dwMask & PFM_TABLE && para->fmt.wEffects & PFE_TABLE) &&
|
|
|
|
(para->fmt.dwMask & PFM_BORDER) && (para->fmt.wBorders & 8))
|
2008-01-01 22:04:46 +01:00
|
|
|
wc.pt.y += border;
|
2020-10-08 12:10:47 +02:00
|
|
|
if (para->fmt.dwMask & PFM_SPACEAFTER)
|
|
|
|
wc.pt.y += ME_twips2pointsY( c, para->fmt.dySpaceAfter );
|
2008-01-01 22:04:46 +01:00
|
|
|
|
2020-10-08 12:10:47 +02:00
|
|
|
para->nFlags &= ~MEPF_REWRAP;
|
|
|
|
para->nHeight = wc.pt.y;
|
|
|
|
para->nRows = wc.nRow;
|
2018-11-29 14:44:54 +01:00
|
|
|
editor->total_rows += wc.nRow;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2020-10-12 14:09:05 +02:00
|
|
|
struct repaint_range
|
2012-05-09 09:13:31 +02:00
|
|
|
{
|
2020-10-12 14:09:06 +02:00
|
|
|
ME_Paragraph *start, *end;
|
2020-10-12 14:09:05 +02:00
|
|
|
};
|
|
|
|
|
2020-10-12 14:09:06 +02:00
|
|
|
static void update_repaint( ME_Paragraph *para, struct repaint_range *repaint )
|
2020-10-12 14:09:05 +02:00
|
|
|
{
|
|
|
|
if (!repaint->start) repaint->start = para;
|
|
|
|
repaint->end = para;
|
2012-05-09 09:13:31 +02:00
|
|
|
}
|
|
|
|
|
2020-10-12 14:09:05 +02:00
|
|
|
static void adjust_para_y( ME_Paragraph *para, ME_Context *c, struct repaint_range *repaint )
|
2018-11-29 14:44:50 +01:00
|
|
|
{
|
2020-10-23 11:25:03 +02:00
|
|
|
ME_Cell *cell;
|
|
|
|
|
2020-10-09 13:59:19 +02:00
|
|
|
if (para->nFlags & MEPF_ROWSTART)
|
2018-11-29 14:44:50 +01:00
|
|
|
{
|
2020-10-12 14:09:07 +02:00
|
|
|
ME_Paragraph *end_row_para = table_row_end( para );
|
2018-11-29 14:44:50 +01:00
|
|
|
int borderWidth = 0;
|
2020-10-23 11:25:03 +02:00
|
|
|
|
|
|
|
cell = table_row_first_cell( para );
|
|
|
|
cell->pt = c->pt;
|
2018-11-29 14:44:50 +01:00
|
|
|
/* Offset the text by the largest top border width. */
|
2020-10-23 11:25:03 +02:00
|
|
|
while (cell_next( cell ))
|
2018-11-29 14:44:50 +01:00
|
|
|
{
|
2020-10-23 11:25:03 +02:00
|
|
|
borderWidth = max( borderWidth, cell->border.top.width );
|
|
|
|
cell = cell_next( cell );
|
2018-11-29 14:44:50 +01:00
|
|
|
}
|
|
|
|
if (borderWidth > 0)
|
|
|
|
{
|
|
|
|
borderWidth = max(ME_twips2pointsY(c, borderWidth), 1);
|
|
|
|
while (cell)
|
|
|
|
{
|
2020-10-23 11:25:03 +02:00
|
|
|
cell->yTextOffset = borderWidth;
|
|
|
|
cell = cell_prev( cell );
|
2018-11-29 14:44:50 +01:00
|
|
|
}
|
|
|
|
c->pt.y += borderWidth;
|
|
|
|
}
|
2020-10-12 14:09:07 +02:00
|
|
|
if (end_row_para->fmt.dxStartIndent > 0)
|
2018-11-29 14:44:50 +01:00
|
|
|
{
|
2020-10-23 11:25:03 +02:00
|
|
|
cell = table_row_first_cell( para );
|
|
|
|
cell->pt.x += ME_twips2pointsX( c, end_row_para->fmt.dxStartIndent );
|
|
|
|
c->pt.x = cell->pt.x;
|
2018-11-29 14:44:50 +01:00
|
|
|
}
|
|
|
|
}
|
2020-10-09 13:59:19 +02:00
|
|
|
else if (para->nFlags & MEPF_ROWEND)
|
2018-11-29 14:44:50 +01:00
|
|
|
{
|
|
|
|
/* Set all the cells to the height of the largest cell */
|
2020-10-12 14:09:07 +02:00
|
|
|
ME_Paragraph *start_row_para = table_row_start( para );
|
2018-11-29 14:44:50 +01:00
|
|
|
int prevHeight, nHeight, bottomBorder = 0;
|
2020-10-23 11:25:03 +02:00
|
|
|
|
|
|
|
cell = table_row_end_cell( para );
|
|
|
|
para->nWidth = cell->pt.x + cell->nWidth;
|
2020-10-12 14:09:07 +02:00
|
|
|
if (!(para_next( para )->nFlags & MEPF_ROWSTART))
|
2018-11-29 14:44:50 +01:00
|
|
|
{
|
|
|
|
/* Last row, the bottom border is added to the height. */
|
2020-10-23 11:25:03 +02:00
|
|
|
while ((cell = cell_prev( cell )))
|
|
|
|
bottomBorder = max( bottomBorder, cell->border.bottom.width );
|
|
|
|
|
2018-11-29 14:44:50 +01:00
|
|
|
bottomBorder = ME_twips2pointsY(c, bottomBorder);
|
2020-10-23 11:25:03 +02:00
|
|
|
cell = table_row_end_cell( para );
|
2018-11-29 14:44:50 +01:00
|
|
|
}
|
2020-10-23 11:25:03 +02:00
|
|
|
prevHeight = cell->nHeight;
|
|
|
|
nHeight = cell_prev( cell )->nHeight + bottomBorder;
|
|
|
|
cell->nHeight = nHeight;
|
2020-10-09 13:59:19 +02:00
|
|
|
para->nHeight = nHeight;
|
2020-10-23 11:25:03 +02:00
|
|
|
while (cell_prev( cell ))
|
2018-11-29 14:44:50 +01:00
|
|
|
{
|
2020-10-23 11:25:03 +02:00
|
|
|
cell = cell_prev( cell );
|
|
|
|
cell->nHeight = nHeight;
|
2018-11-29 14:44:50 +01:00
|
|
|
}
|
2020-10-23 11:25:03 +02:00
|
|
|
|
2018-11-29 14:44:50 +01:00
|
|
|
/* Also set the height of the start row paragraph */
|
2020-10-12 14:09:07 +02:00
|
|
|
start_row_para->nHeight = nHeight;
|
|
|
|
c->pt.x = start_row_para->pt.x;
|
2020-10-23 11:25:03 +02:00
|
|
|
c->pt.y = cell->pt.y + nHeight;
|
2018-11-29 14:44:50 +01:00
|
|
|
if (prevHeight < nHeight)
|
|
|
|
{
|
|
|
|
/* The height of the cells has grown, so invalidate the bottom of
|
|
|
|
* the cells. */
|
2020-10-12 14:09:06 +02:00
|
|
|
update_repaint( para, repaint );
|
2020-10-23 11:25:03 +02:00
|
|
|
cell = cell_prev( table_row_end_cell( para ) );
|
2018-11-29 14:44:50 +01:00
|
|
|
while (cell)
|
|
|
|
{
|
2020-10-23 11:25:03 +02:00
|
|
|
update_repaint( cell_end_para( cell ), repaint );
|
|
|
|
cell = cell_prev( cell );
|
2018-11-29 14:44:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-23 11:25:03 +02:00
|
|
|
else if ((cell = para_cell( para )) && para == cell_end_para( cell ))
|
2018-11-29 14:44:50 +01:00
|
|
|
{
|
|
|
|
/* The next paragraph is in the next cell in the table row. */
|
2020-10-09 13:59:19 +02:00
|
|
|
cell->nHeight = c->pt.y + para->nHeight - cell->pt.y;
|
2018-11-29 14:44:50 +01:00
|
|
|
|
|
|
|
/* Propagate the largest height to the end so that it can be easily
|
|
|
|
* sent back to all the cells at the end of the row. */
|
2020-10-23 11:25:03 +02:00
|
|
|
if (cell_prev( cell ))
|
|
|
|
cell->nHeight = max( cell->nHeight, cell_prev( cell )->nHeight );
|
2018-11-29 14:44:50 +01:00
|
|
|
|
|
|
|
c->pt.x = cell->pt.x + cell->nWidth;
|
|
|
|
c->pt.y = cell->pt.y;
|
2020-10-23 11:25:03 +02:00
|
|
|
cell_next( cell )->pt = c->pt;
|
|
|
|
if (!(para_next( para )->nFlags & MEPF_ROWEND))
|
2018-11-29 14:44:50 +01:00
|
|
|
c->pt.y += cell->yTextOffset;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-23 11:25:03 +02:00
|
|
|
if ((cell = para_cell( para ))) /* Next paragraph in the same cell. */
|
|
|
|
c->pt.x = cell->pt.x;
|
|
|
|
else /* Normal paragraph */
|
2018-11-29 14:44:50 +01:00
|
|
|
c->pt.x = 0;
|
2020-10-09 13:59:19 +02:00
|
|
|
c->pt.y += para->nHeight;
|
2018-11-29 14:44:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-18 07:56:49 +01:00
|
|
|
BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor)
|
|
|
|
{
|
2020-10-09 13:59:19 +02:00
|
|
|
ME_Paragraph *para, *next;
|
2020-10-20 13:50:37 +02:00
|
|
|
struct wine_rb_entry *entry, *next_entry = NULL;
|
2005-03-09 12:48:59 +01:00
|
|
|
ME_Context c;
|
2020-10-09 13:59:20 +02:00
|
|
|
int totalWidth = editor->nTotalWidth, prev_width;
|
2020-10-12 14:09:05 +02:00
|
|
|
struct repaint_range repaint = { NULL, NULL };
|
2018-11-29 14:44:53 +01:00
|
|
|
|
2020-10-09 13:59:20 +02:00
|
|
|
if (!editor->marked_paras.root) return FALSE;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2009-01-20 07:41:32 +01:00
|
|
|
ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2020-10-09 13:59:20 +02:00
|
|
|
entry = wine_rb_head( editor->marked_paras.root );
|
|
|
|
while (entry)
|
2018-11-29 14:44:53 +01:00
|
|
|
{
|
2020-10-09 13:59:20 +02:00
|
|
|
para = WINE_RB_ENTRY_VALUE( entry, ME_Paragraph, marked_entry );
|
2020-10-20 13:50:37 +02:00
|
|
|
|
|
|
|
/* If the first entry lies inside a table, go back to the start
|
|
|
|
of the table to ensure cell heights are kept in sync. */
|
|
|
|
if (!next_entry && para_in_table( para ) && para != table_outer_para( para ))
|
|
|
|
{
|
|
|
|
para = table_outer_para( para );
|
|
|
|
next_entry = entry;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
next_entry = wine_rb_next( entry );
|
2020-10-09 13:59:20 +02:00
|
|
|
|
|
|
|
c.pt = para->pt;
|
2020-10-09 13:59:19 +02:00
|
|
|
prev_width = para->nWidth;
|
|
|
|
ME_WrapTextParagraph( editor, &c, para );
|
|
|
|
if (prev_width == totalWidth && para->nWidth < totalWidth)
|
2018-11-29 14:44:53 +01:00
|
|
|
totalWidth = get_total_width(editor);
|
|
|
|
else
|
2020-10-09 13:59:19 +02:00
|
|
|
totalWidth = max(totalWidth, para->nWidth);
|
2005-03-09 12:48:59 +01:00
|
|
|
|
2020-10-12 14:09:06 +02:00
|
|
|
update_repaint( para, &repaint );
|
2020-10-12 14:09:05 +02:00
|
|
|
adjust_para_y( para, &c, &repaint );
|
2018-11-29 14:44:53 +01:00
|
|
|
|
2020-10-12 14:09:06 +02:00
|
|
|
if (para_next( para ))
|
2018-11-29 14:44:53 +01:00
|
|
|
{
|
2020-10-20 13:50:37 +02:00
|
|
|
if (c.pt.x != para_next( para )->pt.x || c.pt.y != para_next( para )->pt.y ||
|
|
|
|
para_in_table( para ))
|
2018-11-29 14:44:53 +01:00
|
|
|
{
|
2020-10-09 13:59:19 +02:00
|
|
|
next = para;
|
2020-10-12 14:09:06 +02:00
|
|
|
while (para_next( next ) && &next->marked_entry != next_entry &&
|
2020-10-09 13:59:19 +02:00
|
|
|
next != &editor->pBuffer->pLast->member.para)
|
2018-11-29 14:44:53 +01:00
|
|
|
{
|
2020-10-12 14:09:06 +02:00
|
|
|
update_repaint( para_next( next ), &repaint );
|
2020-10-20 13:50:36 +02:00
|
|
|
para_next( next )->pt = c.pt;
|
2020-10-12 14:09:06 +02:00
|
|
|
adjust_para_y( para_next( next ), &c, &repaint );
|
|
|
|
next = para_next( next );
|
2018-11-29 14:44:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-09 13:59:20 +02:00
|
|
|
entry = next_entry;
|
2005-03-09 12:48:59 +01:00
|
|
|
}
|
2020-10-09 13:59:20 +02:00
|
|
|
wine_rb_clear( &editor->marked_paras, NULL, NULL );
|
|
|
|
|
2005-03-09 12:48:59 +01:00
|
|
|
editor->sizeWindow.cx = c.rcView.right-c.rcView.left;
|
|
|
|
editor->sizeWindow.cy = c.rcView.bottom-c.rcView.top;
|
2009-01-14 19:24:02 +01:00
|
|
|
|
2020-10-09 13:59:20 +02:00
|
|
|
editor->nTotalLength = editor->pBuffer->pLast->member.para.pt.y;
|
2009-01-14 19:24:02 +01:00
|
|
|
editor->nTotalWidth = totalWidth;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2009-01-20 07:41:32 +01:00
|
|
|
ME_DestroyContext(&c);
|
2008-03-16 21:48:13 +01:00
|
|
|
|
2020-10-12 14:09:05 +02:00
|
|
|
if (repaint.start || editor->nTotalLength < editor->nLastTotalLength)
|
2020-10-12 14:09:06 +02:00
|
|
|
para_range_invalidate( editor, repaint.start, repaint.end);
|
2020-10-12 14:09:05 +02:00
|
|
|
return !!repaint.start;
|
2006-08-07 17:27:16 +02:00
|
|
|
}
|
2006-01-10 20:23:41 +01:00
|
|
|
|
2020-10-12 14:09:06 +02:00
|
|
|
void para_range_invalidate( ME_TextEditor *editor, ME_Paragraph *start_para,
|
|
|
|
ME_Paragraph *last_para )
|
2008-10-19 10:43:17 +02:00
|
|
|
{
|
|
|
|
RECT rc;
|
|
|
|
int ofs;
|
2006-08-07 17:27:16 +02:00
|
|
|
|
2020-10-09 13:59:21 +02:00
|
|
|
rc = editor->rcFormat;
|
2009-01-14 19:24:02 +01:00
|
|
|
ofs = editor->vert_si.nPos;
|
2008-10-19 10:43:17 +02:00
|
|
|
|
2020-10-09 13:59:21 +02:00
|
|
|
if (start_para)
|
|
|
|
{
|
2020-10-12 14:09:06 +02:00
|
|
|
start_para = table_outer_para( start_para );
|
|
|
|
last_para = table_outer_para( last_para );
|
|
|
|
rc.top += start_para->pt.y - ofs;
|
2012-05-18 06:30:03 +02:00
|
|
|
} else {
|
2020-10-09 13:59:21 +02:00
|
|
|
rc.top += editor->nTotalLength - ofs;
|
2008-10-19 10:43:17 +02:00
|
|
|
}
|
|
|
|
if (editor->nTotalLength < editor->nLastTotalLength)
|
2020-10-09 13:59:21 +02:00
|
|
|
rc.bottom = editor->rcFormat.top + editor->nLastTotalLength - ofs;
|
2012-05-18 06:30:03 +02:00
|
|
|
else
|
2020-10-12 14:09:06 +02:00
|
|
|
rc.bottom = editor->rcFormat.top + last_para->pt.y + last_para->nHeight - ofs;
|
2012-05-18 06:30:03 +02:00
|
|
|
ITextHost_TxInvalidateRect(editor->texthost, &rc, TRUE);
|
2005-03-09 12:48:59 +01:00
|
|
|
}
|
2005-11-03 10:52:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ME_SendRequestResize(ME_TextEditor *editor, BOOL force)
|
|
|
|
{
|
|
|
|
if (editor->nEventMask & ENM_REQUESTRESIZE)
|
|
|
|
{
|
|
|
|
RECT rc;
|
|
|
|
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxGetClientRect(editor->texthost, &rc);
|
2005-11-03 10:52:29 +01:00
|
|
|
|
|
|
|
if (force || rc.bottom != editor->nTotalLength)
|
|
|
|
{
|
|
|
|
REQRESIZE info;
|
|
|
|
|
2009-09-28 09:44:19 +02:00
|
|
|
info.nmhdr.hwndFrom = NULL;
|
|
|
|
info.nmhdr.idFrom = 0;
|
2005-11-03 10:52:29 +01:00
|
|
|
info.nmhdr.code = EN_REQUESTRESIZE;
|
|
|
|
info.rc = rc;
|
2009-01-14 19:24:02 +01:00
|
|
|
info.rc.right = editor->nTotalWidth;
|
2005-11-03 10:52:29 +01:00
|
|
|
info.rc.bottom = editor->nTotalLength;
|
2008-01-01 22:03:52 +01:00
|
|
|
|
|
|
|
editor->nEventMask &= ~ENM_REQUESTRESIZE;
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxNotify(editor->texthost, info.nmhdr.code, &info);
|
2008-01-01 22:03:52 +01:00
|
|
|
editor->nEventMask |= ENM_REQUESTRESIZE;
|
2005-11-03 10:52:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|