diff options
author | Mark Hung <marklh9@gmail.com> | 2021-01-05 20:26:51 +0800 |
---|---|---|
committer | Mark Hung <marklh9@gmail.com> | 2021-01-09 05:13:55 +0100 |
commit | 621c189173b35ac7f5ce4c578f57045479c63ab6 (patch) | |
tree | acc1c75c57021e341841d31c29e15414f464a19d /sc/source/ui/dbgui | |
parent | 65b3a5cbc7e018b4e3f4f61228bf9334fd9a956e (diff) |
tdf#104927 consider character width for CSV import
dialog in fixed width mode. Postions and column width
in csvgrid.cxx are muliplied by character width to
get X coordinate. Positions are calculated based
on the string length, disregard the fact that the
characters may have different visual width.
Most CJK ideographs and symbols are designed so that
their width are twice of the western characters in
the same font in general.
This patch implement ScImportExport::CountVisualWidth()
to count their visual width, convert the position
so string that contains CJK ideographs render at the
right place, and separate the string based on the
calculated visual width instead of the number of
sal_Unicode chars.
Change-Id: Ic5c1ec219820cf4e1d6c554d5eaccca9f8210ec6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108802
Tested-by: Jenkins
Reviewed-by: Mark Hung <marklh9@gmail.com>
Diffstat (limited to 'sc/source/ui/dbgui')
-rw-r--r-- | sc/source/ui/dbgui/csvgrid.cxx | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/sc/source/ui/dbgui/csvgrid.cxx b/sc/source/ui/dbgui/csvgrid.cxx index 1fd2cea6de69..13b8f671c3e8 100644 --- a/sc/source/ui/dbgui/csvgrid.cxx +++ b/sc/source/ui/dbgui/csvgrid.cxx @@ -789,7 +789,7 @@ void ScCsvGrid::ImplSetTextLineSep( /* TODO: signal overflow somewhere in UI */ // update column width - sal_Int32 nWidth = std::max( CSV_MINCOLWIDTH, aCellText.getLength() + 1 ); + sal_Int32 nWidth = std::max( CSV_MINCOLWIDTH, ScImportExport::CountVisualWidth( aCellText ) + 1 ); if( IsValidColumn( nColIx ) ) { // expand existing column @@ -826,9 +826,9 @@ void ScCsvGrid::ImplSetTextLineFix( sal_Int32 nLine, const OUString& rTextLine ) { if( nLine < GetFirstVisLine() ) return; - sal_Int32 nChars = rTextLine.getLength(); - if( nChars > GetPosCount() ) - Execute( CSVCMD_SETPOSCOUNT, nChars ); + sal_Int32 nWidth = ScImportExport::CountVisualWidth( rTextLine ); + if( nWidth > GetPosCount() ) + Execute( CSVCMD_SETPOSCOUNT, nWidth ); sal_uInt32 nLineIx = nLine - GetFirstVisLine(); while( maTexts.size() <= nLineIx ) @@ -842,9 +842,11 @@ void ScCsvGrid::ImplSetTextLineFix( sal_Int32 nLine, const OUString& rTextLine ) for( sal_uInt32 nColIx = 0; (nColIx < nColCount) && (nStrIx < nStrLen); ++nColIx ) { sal_Int32 nColWidth = GetColumnWidth( nColIx ); - sal_Int32 nLen = std::min( std::min( nColWidth, CSV_MAXSTRLEN ), nStrLen - nStrIx); + sal_Int32 nLastIx = nStrIx; + ScImportExport::CountVisualWidth( rTextLine, nLastIx, nColWidth ); + sal_Int32 nLen = std::min( CSV_MAXSTRLEN, nLastIx - nStrIx ); rStrVec.push_back( rTextLine.copy( nStrIx, nLen ) ); - nStrIx = nStrIx + nColWidth; + nStrIx = nStrIx + nLen; } InvalidateGfx(); } |