Feature: drop ICU-lx in favour of directly interfacing with harfbuzz
This means we have RTL support again with ICU 58+. It makes use of: - ICU for bidi-itemization - ICU for script-itemization - OpenTTD for style-itemization - harfbuzz for shapingpull/532/head
parent
9cb60768fe
commit
81d4fa6999
@ -0,0 +1,65 @@
|
||||
#[=======================================================================[.rst:
|
||||
FindHarfBuzz
|
||||
-------
|
||||
|
||||
Finds the harfbuzz library.
|
||||
|
||||
Result Variables
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This will define the following variables:
|
||||
|
||||
``Harfbuzz_FOUND``
|
||||
True if the system has the harfbuzz library.
|
||||
``Harfbuzz_INCLUDE_DIRS``
|
||||
Include directories needed to use harfbuzz.
|
||||
``Harfbuzz_LIBRARIES``
|
||||
Libraries needed to link to harfbuzz.
|
||||
``Harfbuzz_VERSION``
|
||||
The version of the harfbuzz library which was found.
|
||||
|
||||
Cache Variables
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
The following cache variables may also be set:
|
||||
|
||||
``Harfbuzz_INCLUDE_DIR``
|
||||
The directory containing ``hb.h``.
|
||||
``Harfbuzz_LIBRARY``
|
||||
The path to the harfbuzz library.
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
find_package(PkgConfig QUIET)
|
||||
pkg_check_modules(PC_Harfbuzz QUIET harfbuzz)
|
||||
|
||||
find_path(Harfbuzz_INCLUDE_DIR
|
||||
NAMES hb.h
|
||||
PATHS ${PC_Harfbuzz_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
find_library(Harfbuzz_LIBRARY
|
||||
NAMES harfbuzz
|
||||
PATHS ${PC_Harfbuzz_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
set(Harfbuzz_VERSION ${PC_Harfbuzz_VERSION})
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(Harfbuzz
|
||||
FOUND_VAR Harfbuzz_FOUND
|
||||
REQUIRED_VARS
|
||||
Harfbuzz_LIBRARY
|
||||
Harfbuzz_INCLUDE_DIR
|
||||
VERSION_VAR Harfbuzz_VERSION
|
||||
)
|
||||
|
||||
if(Harfbuzz_FOUND)
|
||||
set(Harfbuzz_LIBRARIES ${Harfbuzz_LIBRARY})
|
||||
set(Harfbuzz_INCLUDE_DIRS ${Harfbuzz_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
mark_as_advanced(
|
||||
Harfbuzz_INCLUDE_DIR
|
||||
Harfbuzz_LIBRARY
|
||||
)
|
@ -0,0 +1,5 @@
|
||||
add_files(
|
||||
scriptrun.cpp
|
||||
scriptrun.h
|
||||
CONDITION ICU_i18n_FOUND
|
||||
)
|
@ -0,0 +1,208 @@
|
||||
// © 2016 and later: Unicode, Inc. and others.
|
||||
// License & terms of use: http://www.unicode.org/copyright.html
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1999-2016, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
* file name: scrptrun.cpp
|
||||
*
|
||||
* created on: 10/17/2001
|
||||
* created by: Eric R. Mader
|
||||
*/
|
||||
|
||||
#include <unicode/utypes.h>
|
||||
#include <unicode/uscript.h>
|
||||
|
||||
#include "scriptrun.h"
|
||||
|
||||
// Copied from cmemory.h
|
||||
#define UPRV_LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
const char ScriptRun::fgClassID=0;
|
||||
|
||||
UChar32 ScriptRun::pairedChars[] = {
|
||||
0x0028, 0x0029, // ascii paired punctuation
|
||||
0x003c, 0x003e,
|
||||
0x005b, 0x005d,
|
||||
0x007b, 0x007d,
|
||||
0x00ab, 0x00bb, // guillemets
|
||||
0x2018, 0x2019, // general punctuation
|
||||
0x201c, 0x201d,
|
||||
0x2039, 0x203a,
|
||||
0x3008, 0x3009, // chinese paired punctuation
|
||||
0x300a, 0x300b,
|
||||
0x300c, 0x300d,
|
||||
0x300e, 0x300f,
|
||||
0x3010, 0x3011,
|
||||
0x3014, 0x3015,
|
||||
0x3016, 0x3017,
|
||||
0x3018, 0x3019,
|
||||
0x301a, 0x301b
|
||||
};
|
||||
|
||||
const int32_t ScriptRun::pairedCharCount = UPRV_LENGTHOF(pairedChars);
|
||||
const int32_t ScriptRun::pairedCharPower = 1 << highBit(pairedCharCount);
|
||||
const int32_t ScriptRun::pairedCharExtra = pairedCharCount - pairedCharPower;
|
||||
|
||||
int8_t ScriptRun::highBit(int32_t value)
|
||||
{
|
||||
if (value <= 0) {
|
||||
return -32;
|
||||
}
|
||||
|
||||
int8_t bit = 0;
|
||||
|
||||
if (value >= 1 << 16) {
|
||||
value >>= 16;
|
||||
bit += 16;
|
||||
}
|
||||
|
||||
if (value >= 1 << 8) {
|
||||
value >>= 8;
|
||||
bit += 8;
|
||||
}
|
||||
|
||||
if (value >= 1 << 4) {
|
||||
value >>= 4;
|
||||
bit += 4;
|
||||
}
|
||||
|
||||
if (value >= 1 << 2) {
|
||||
value >>= 2;
|
||||
bit += 2;
|
||||
}
|
||||
|
||||
if (value >= 1 << 1) {
|
||||
value >>= 1;
|
||||
bit += 1;
|
||||
}
|
||||
|
||||
return bit;
|
||||
}
|
||||
|
||||
int32_t ScriptRun::getPairIndex(UChar32 ch)
|
||||
{
|
||||
int32_t probe = pairedCharPower;
|
||||
int32_t index = 0;
|
||||
|
||||
if (ch >= pairedChars[pairedCharExtra]) {
|
||||
index = pairedCharExtra;
|
||||
}
|
||||
|
||||
while (probe > (1 << 0)) {
|
||||
probe >>= 1;
|
||||
|
||||
if (ch >= pairedChars[index + probe]) {
|
||||
index += probe;
|
||||
}
|
||||
}
|
||||
|
||||
if (pairedChars[index] != ch) {
|
||||
index = -1;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
UBool ScriptRun::sameScript(int32_t scriptOne, int32_t scriptTwo)
|
||||
{
|
||||
return scriptOne <= USCRIPT_INHERITED || scriptTwo <= USCRIPT_INHERITED || scriptOne == scriptTwo;
|
||||
}
|
||||
|
||||
UBool ScriptRun::next()
|
||||
{
|
||||
int32_t startSP = parenSP; // used to find the first new open character
|
||||
UErrorCode error = U_ZERO_ERROR;
|
||||
|
||||
// if we've fallen off the end of the text, we're done
|
||||
if (scriptEnd >= charLimit) {
|
||||
return false;
|
||||
}
|
||||
|
||||
scriptCode = USCRIPT_COMMON;
|
||||
|
||||
for (scriptStart = scriptEnd; scriptEnd < charLimit; scriptEnd += 1) {
|
||||
char16_t high = charArray[scriptEnd];
|
||||
UChar32 ch = high;
|
||||
|
||||
// if the character is a high surrogate and it's not the last one
|
||||
// in the text, see if it's followed by a low surrogate
|
||||
if (high >= 0xD800 && high <= 0xDBFF && scriptEnd < charLimit - 1)
|
||||
{
|
||||
char16_t low = charArray[scriptEnd + 1];
|
||||
|
||||
// if it is followed by a low surrogate,
|
||||
// consume it and form the full character
|
||||
if (low >= 0xDC00 && low <= 0xDFFF) {
|
||||
ch = (high - 0xD800) * 0x0400 + low - 0xDC00 + 0x10000;
|
||||
scriptEnd += 1;
|
||||
}
|
||||
}
|
||||
|
||||
UScriptCode sc = uscript_getScript(ch, &error);
|
||||
int32_t pairIndex = getPairIndex(ch);
|
||||
|
||||
// Paired character handling:
|
||||
//
|
||||
// if it's an open character, push it onto the stack.
|
||||
// if it's a close character, find the matching open on the
|
||||
// stack, and use that script code. Any non-matching open
|
||||
// characters above it on the stack will be poped.
|
||||
if (pairIndex >= 0) {
|
||||
if ((pairIndex & 1) == 0) {
|
||||
parenStack[++parenSP].pairIndex = pairIndex;
|
||||
parenStack[parenSP].scriptCode = scriptCode;
|
||||
} else if (parenSP >= 0) {
|
||||
int32_t pi = pairIndex & ~1;
|
||||
|
||||
while (parenSP >= 0 && parenStack[parenSP].pairIndex != pi) {
|
||||
parenSP -= 1;
|
||||
}
|
||||
|
||||
if (parenSP < startSP) {
|
||||
startSP = parenSP;
|
||||
}
|
||||
|
||||
if (parenSP >= 0) {
|
||||
sc = parenStack[parenSP].scriptCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sameScript(scriptCode, sc)) {
|
||||
if (scriptCode <= USCRIPT_INHERITED && sc > USCRIPT_INHERITED) {
|
||||
scriptCode = sc;
|
||||
|
||||
// now that we have a final script code, fix any open
|
||||
// characters we pushed before we knew the script code.
|
||||
while (startSP < parenSP) {
|
||||
parenStack[++startSP].scriptCode = scriptCode;
|
||||
}
|
||||
}
|
||||
|
||||
// if this character is a close paired character,
|
||||
// pop it from the stack
|
||||
if (pairIndex >= 0 && (pairIndex & 1) != 0 && parenSP >= 0) {
|
||||
parenSP -= 1;
|
||||
startSP -= 1;
|
||||
}
|
||||
} else {
|
||||
// if the run broke on a surrogate pair,
|
||||
// end it before the high surrogate
|
||||
if (ch >= 0x10000) {
|
||||
scriptEnd -= 1;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
@ -0,0 +1,159 @@
|
||||
// © 2016 and later: Unicode, Inc. and others.
|
||||
// License & terms of use: http://www.unicode.org/copyright.html
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1999-2003, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
* file name: scrptrun.h
|
||||
*
|
||||
* created on: 10/17/2001
|
||||
* created by: Eric R. Mader
|
||||
*/
|
||||
|
||||
#ifndef __SCRPTRUN_H
|
||||
#define __SCRPTRUN_H
|
||||
|
||||
#include <unicode/utypes.h>
|
||||
#include <unicode/uobject.h>
|
||||
#include <unicode/uscript.h>
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
struct ScriptRecord
|
||||
{
|
||||
UChar32 startChar;
|
||||
UChar32 endChar;
|
||||
UScriptCode scriptCode;
|
||||
};
|
||||
|
||||
struct ParenStackEntry
|
||||
{
|
||||
int32_t pairIndex;
|
||||
UScriptCode scriptCode;
|
||||
};
|
||||
|
||||
class ScriptRun : public UObject {
|
||||
public:
|
||||
ScriptRun();
|
||||
|
||||
ScriptRun(const char16_t *chars, int32_t length);
|
||||
|
||||
ScriptRun(const char16_t *chars, int32_t start, int32_t length);
|
||||
|
||||
void reset();
|
||||
|
||||
void reset(int32_t start, int32_t count);
|
||||
|
||||
void reset(const char16_t *chars, int32_t start, int32_t length);
|
||||
|
||||
int32_t getScriptStart();
|
||||
|
||||
int32_t getScriptEnd();
|
||||
|
||||
UScriptCode getScriptCode();
|
||||
|
||||
UBool next();
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
virtual inline UClassID getDynamicClassID() const override { return getStaticClassID(); }
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
static inline UClassID getStaticClassID() { return (UClassID)const_cast<char *>(&fgClassID); }
|
||||
|
||||
private:
|
||||
|
||||
static UBool sameScript(int32_t scriptOne, int32_t scriptTwo);
|
||||
|
||||
int32_t charStart;
|
||||
int32_t charLimit;
|
||||
const char16_t *charArray;
|
||||
|
||||
int32_t scriptStart;
|
||||
int32_t scriptEnd;
|
||||
UScriptCode scriptCode;
|
||||
|
||||
ParenStackEntry parenStack[128];
|
||||
int32_t parenSP;
|
||||
|
||||
static int8_t highBit(int32_t value);
|
||||
static int32_t getPairIndex(UChar32 ch);
|
||||
|
||||
static UChar32 pairedChars[];
|
||||
static const int32_t pairedCharCount;
|
||||
static const int32_t pairedCharPower;
|
||||
static const int32_t pairedCharExtra;
|
||||
|
||||
/**
|
||||
* The address of this static class variable serves as this class's ID
|
||||
* for ICU "poor man's RTTI".
|
||||
*/
|
||||
static const char fgClassID;
|
||||
};
|
||||
|
||||
inline ScriptRun::ScriptRun()
|
||||
{
|
||||
reset(nullptr, 0, 0);
|
||||
}
|
||||
|
||||
inline ScriptRun::ScriptRun(const char16_t *chars, int32_t length)
|
||||
{
|
||||
reset(chars, 0, length);
|
||||
}
|
||||
|
||||
inline ScriptRun::ScriptRun(const char16_t *chars, int32_t start, int32_t length)
|
||||
{
|
||||
reset(chars, start, length);
|
||||
}
|
||||
|
||||
inline int32_t ScriptRun::getScriptStart()
|
||||
{
|
||||
return scriptStart;
|
||||
}
|
||||
|
||||
inline int32_t ScriptRun::getScriptEnd()
|
||||
{
|
||||
return scriptEnd;
|
||||
}
|
||||
|
||||
inline UScriptCode ScriptRun::getScriptCode()
|
||||
{
|
||||
return scriptCode;
|
||||
}
|
||||
|
||||
inline void ScriptRun::reset()
|
||||
{
|
||||
scriptStart = charStart;
|
||||
scriptEnd = charStart;
|
||||
scriptCode = USCRIPT_INVALID_CODE;
|
||||
parenSP = -1;
|
||||
}
|
||||
|
||||
inline void ScriptRun::reset(int32_t start, int32_t length)
|
||||
{
|
||||
charStart = start;
|
||||
charLimit = start + length;
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
inline void ScriptRun::reset(const char16_t *chars, int32_t start, int32_t length)
|
||||
{
|
||||
charArray = chars;
|
||||
|
||||
reset(start, length);
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue