summaryrefslogtreecommitdiff
path: root/source/fitz/ucdn.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2018-04-19 13:27:24 +0200
committerTor Andersson <tor.andersson@artifex.com>2018-04-25 12:26:33 +0200
commitd69dcb5afd27a7cbce35ac4dadec9c6145799a15 (patch)
tree137802d159a255cb9ae1830947e39368710941d2 /source/fitz/ucdn.c
parent73ce99685536764bf17dc097f5cba7208cd8f9c1 (diff)
downloadmupdf-d69dcb5afd27a7cbce35ac4dadec9c6145799a15.tar.xz
Update UCDN.
Diffstat (limited to 'source/fitz/ucdn.c')
-rw-r--r--source/fitz/ucdn.c96
1 files changed, 49 insertions, 47 deletions
diff --git a/source/fitz/ucdn.c b/source/fitz/ucdn.c
index d6b4135e..4e000246 100644
--- a/source/fitz/ucdn.c
+++ b/source/fitz/ucdn.c
@@ -17,13 +17,13 @@
#include "mupdf/fitz.h"
#include "mupdf/ucdn.h"
+#include <stdio.h>
#include <stdlib.h>
typedef struct {
unsigned char category;
unsigned char combining;
unsigned char bidi_class;
- unsigned char mirrored;
unsigned char east_asian_width;
unsigned char script;
unsigned char linebreak_class;
@@ -43,7 +43,7 @@ typedef struct {
short count, index;
} Reindex;
-#include "unicodedata_db.h"
+#include "ucdn_db.h"
/* constants required for Hangul (de)composition */
#define SBASE 0xAC00
@@ -91,20 +91,30 @@ static const unsigned short *get_decomp_record(uint32_t code)
return &decomp_data[index];
}
-static int get_comp_index(uint32_t code, const Reindex *idx)
+static int compare_reindex(const void *a, const void *b)
{
- int i;
-
- for (i = 0; idx[i].start; i++) {
- const Reindex *cur = &idx[i];
- if (code < cur->start)
- return -1;
- if (code <= cur->start + cur->count) {
- return cur->index + (code - cur->start);
- }
- }
+ Reindex *ra = (Reindex *)a;
+ Reindex *rb = (Reindex *)b;
- return -1;
+ if (ra->start < rb->start)
+ return -1;
+ else if (ra->start > (rb->start + rb->count))
+ return 1;
+ else
+ return 0;
+}
+
+static int get_comp_index(uint32_t code, const Reindex *idx, size_t len)
+{
+ Reindex *res;
+ Reindex r = {0, 0, 0};
+ r.start = code;
+ res = (Reindex *) bsearch(&r, idx, len, sizeof(Reindex), compare_reindex);
+
+ if (res != NULL)
+ return res->index + (code - res->start);
+ else
+ return -1;
}
static int compare_mp(const void *a, const void *b)
@@ -154,23 +164,18 @@ static int hangul_pair_decompose(uint32_t code, uint32_t *a, uint32_t *b)
static int hangul_pair_compose(uint32_t *code, uint32_t a, uint32_t b)
{
- if (b < VBASE || b >= (TBASE + TCOUNT))
- return 0;
-
- if ((a < LBASE || a >= (LBASE + LCOUNT))
- && (a < SBASE || a >= (SBASE + SCOUNT)))
- return 0;
-
- if (a >= SBASE) {
+ if (a >= SBASE && a < (SBASE + SCOUNT) && b >= TBASE && b < (TBASE + TCOUNT)) {
/* LV,T */
*code = a + (b - TBASE);
return 3;
- } else {
+ } else if (a >= LBASE && a < (LBASE + LCOUNT) && b >= VBASE && b < (VBASE + VCOUNT)) {
/* L,V */
int li = a - LBASE;
int vi = b - VBASE;
*code = SBASE + li * NCOUNT + vi * TCOUNT;
return 2;
+ } else {
+ return 0;
}
}
@@ -178,7 +183,7 @@ static uint32_t decode_utf16(const unsigned short **code_ptr)
{
const unsigned short *code = *code_ptr;
- if ((code[0] & 0xd800) != 0xd800) {
+ if (code[0] < 0xd800 || code[0] > 0xdc00) {
*code_ptr += 1;
return (uint32_t)code[0];
} else {
@@ -215,7 +220,7 @@ int ucdn_get_bidi_class(uint32_t code)
int ucdn_get_mirrored(uint32_t code)
{
- return get_ucd_record(code)->mirrored;
+ return ucdn_mirror(code) != code;
}
int ucdn_get_script(uint32_t code)
@@ -234,28 +239,28 @@ int ucdn_get_resolved_linebreak_class(uint32_t code)
switch (record->linebreak_class)
{
- case UCDN_LINEBREAK_CLASS_AI:
- case UCDN_LINEBREAK_CLASS_SG:
- case UCDN_LINEBREAK_CLASS_XX:
- return UCDN_LINEBREAK_CLASS_AL;
+ case UCDN_LINEBREAK_CLASS_AI:
+ case UCDN_LINEBREAK_CLASS_SG:
+ case UCDN_LINEBREAK_CLASS_XX:
+ return UCDN_LINEBREAK_CLASS_AL;
- case UCDN_LINEBREAK_CLASS_SA:
- if (record->category == UCDN_GENERAL_CATEGORY_MC ||
- record->category == UCDN_GENERAL_CATEGORY_MN)
- return UCDN_LINEBREAK_CLASS_CM;
- return UCDN_LINEBREAK_CLASS_AL;
+ case UCDN_LINEBREAK_CLASS_SA:
+ if (record->category == UCDN_GENERAL_CATEGORY_MC ||
+ record->category == UCDN_GENERAL_CATEGORY_MN)
+ return UCDN_LINEBREAK_CLASS_CM;
+ return UCDN_LINEBREAK_CLASS_AL;
- case UCDN_LINEBREAK_CLASS_CJ:
- return UCDN_LINEBREAK_CLASS_NS;
+ case UCDN_LINEBREAK_CLASS_CJ:
+ return UCDN_LINEBREAK_CLASS_NS;
- case UCDN_LINEBREAK_CLASS_CB:
- return UCDN_LINEBREAK_CLASS_B2;
+ case UCDN_LINEBREAK_CLASS_CB:
+ return UCDN_LINEBREAK_CLASS_B2;
- case UCDN_LINEBREAK_CLASS_NL:
- return UCDN_LINEBREAK_CLASS_BK;
+ case UCDN_LINEBREAK_CLASS_NL:
+ return UCDN_LINEBREAK_CLASS_BK;
- default:
- return record->linebreak_class;
+ default:
+ return record->linebreak_class;
}
}
@@ -264,9 +269,6 @@ uint32_t ucdn_mirror(uint32_t code)
MirrorPair mp = {0};
MirrorPair *res;
- if (get_ucd_record(code)->mirrored == 0)
- return code;
-
mp.from = code;
res = (MirrorPair *) bsearch(&mp, mirror_pairs, BIDI_MIRROR_LEN,
sizeof(MirrorPair), compare_mp);
@@ -326,8 +328,8 @@ int ucdn_compose(uint32_t *code, uint32_t a, uint32_t b)
if (hangul_pair_compose(code, a, b))
return 1;
- l = get_comp_index(a, nfc_first);
- r = get_comp_index(b, nfc_last);
+ l = get_comp_index(a, nfc_first, sizeof(nfc_first) / sizeof(Reindex));
+ r = get_comp_index(b, nfc_last, sizeof(nfc_last) / sizeof(Reindex));
if (l < 0 || r < 0)
return 0;