tdf#104597 related: restore the mirroring of Bidi_Mirrored characters

The method PDFIProcessor::mirrorString() was removed, and
::comphelper::string::reverseString was used, by Kevin Suo in commit
69e9925ded.

The old PDFIProcessor::mirrorString() did two things:
1) Reverse the code points in the string. However, due to its use of iterateCodePoints(&i)
rather than iterateCodePoints(&i, -1) (i.e. iterating in forward rather than reversed order),
the reverse was not functioning at all.
2) Use GetMirroredChar (i.e. the icu unicode u_charMirror() which was dropped in
commit 720a093461) to get the mirrored-image of
characters with the Bidi_Mirrored properties.

Stephan Bergmann restored the #1 in commit 50d73574b6
(by introducing comphelper::string::reverseCodePoints). However, the #2 was not restored.

I do not see a clear reason to drop #2 (at least this is an area I don't quite familiar
with), so it's better to restore it as well, in *this* commit, named as SubstituteBidiMirrored.

Change-Id: Ic263097938310e6e04f3b95bb12e4f4e834198f2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143041
Tested-by: Jenkins
Reviewed-by: Kevin Suo <suokunlong@126.com>
This commit is contained in:
Kevin Suo
2022-11-30 13:40:24 +01:00
parent 11e72e61b6
commit e788317bb5
10 changed files with 39 additions and 1 deletions
+5
View File
@@ -97,6 +97,11 @@ unicode::getUnicodeDirection( const sal_Unicode ch ) {
return r;
}
sal_uInt32 unicode::GetMirroredChar(sal_uInt32 nChar) {
nChar = u_charMirror(nChar);
return nChar;
}
#define bit(name) (1U << name)
#define UPPERMASK bit(UnicodeType::UPPERCASE_LETTER)
+1
View File
@@ -43,6 +43,7 @@ public:
static sal_Unicode getUnicodeScriptStart(css::i18n::UnicodeScript type);
static sal_Unicode getUnicodeScriptEnd(css::i18n::UnicodeScript type);
static sal_uInt8 getUnicodeDirection(const sal_Unicode ch);
static sal_uInt32 GetMirroredChar(sal_uInt32);
static bool isControl(const sal_Unicode ch);
static bool isAlpha(const sal_Unicode ch);
static bool isSpace(const sal_Unicode ch);
+1
View File
@@ -34,6 +34,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sdext_pdfimport,\
unotest \
tl \
xo \
i18nutil \
))
$(eval $(call gb_CppunitTest_use_library_objects,sdext_pdfimport,pdfimport))
+1
View File
@@ -32,6 +32,7 @@ $(eval $(call gb_Executable_use_libraries,pdf2xml,\
sal \
tl \
xo \
i18nutil \
))
$(eval $(call gb_Executable_use_library_objects,pdf2xml,pdfimport))
+1
View File
@@ -30,6 +30,7 @@ $(eval $(call gb_Executable_use_libraries,pdfunzip,\
vcl \
tl \
xo \
i18nutil \
))
$(eval $(call gb_Executable_use_library_objects,pdfunzip,pdfimport))
+2
View File
@@ -29,10 +29,12 @@ $(eval $(call gb_Library_use_libraries,pdfimport,\
sal \
tl \
xo \
i18nutil \
))
$(eval $(call gb_Library_use_externals,pdfimport,\
boost_headers \
icu_headers \
zlib \
$(if $(filter-out WNT MACOSX,$(OS)),fontconfig) \
))
@@ -79,6 +79,8 @@ namespace pdfi
static void sortElements( Element* pElement );
static OUString SubstituteBidiMirrored(const OUString& rString);
private:
void processGlyphLine();
@@ -123,7 +123,12 @@ void DrawXmlEmitter::visit( TextElement& elem, const std::list< std::unique_ptr<
}
if (isRTL) // If so, reverse string
{
// First, produce mirrored-image for each code point which has the Bidi_Mirrored property.
str = PDFIProcessor::SubstituteBidiMirrored(str);
// Then, reverse the code points in the string, in backward order.
str = ::comphelper::string::reverseCodePoints(str);
}
m_rEmitContext.rEmitter.beginTag( "text:span", aProps );
+16 -1
View File
@@ -33,7 +33,7 @@
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <basegfx/utils/canvastools.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <vcl/svapp.hxx>
#include <i18nutil/unicode.hxx>
using namespace com::sun::star;
@@ -695,6 +695,21 @@ void PDFIProcessor::sortElements(Element* pEle)
pEle->Children.sort(lr_tb_sort);
}
/* Produce mirrored-image for each code point which has the Bidi_Mirrored property, within a string.
This need to be done in forward order.
*/
OUString PDFIProcessor::SubstituteBidiMirrored(const OUString& rString)
{
const sal_Int32 nLen = rString.getLength();
OUStringBuffer aMirror(nLen);
for (sal_Int32 i = 0; i < nLen;) {
const sal_uInt32 nCodePoint = rString.iterateCodePoints(&i);
aMirror.appendUtf32(unicode::GetMirroredChar(nCodePoint));
}
return aMirror.makeStringAndClear();
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@@ -112,7 +112,12 @@ void WriterXmlEmitter::visit( TextElement& elem, const std::list< std::unique_pt
}
if (isRTL) // If so, reverse string
{
// First, produce mirrored-image for each code point which has the Bidi_Mirrored property.
str = PDFIProcessor::SubstituteBidiMirrored(str);
// Then, reverse the code points in the string, in backward order.
str = ::comphelper::string::reverseCodePoints(str);
}
m_rEmitContext.rEmitter.beginTag( "text:span", aProps );