[base] Fix use of bsearch
This commit is contained in:
parent
eddd456532
commit
a157342fce
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2016 Elie Roux <elie.roux@telecom-bretagne.eu>
|
* Copyright © 2016 Elie Roux <elie.roux@telecom-bretagne.eu>
|
||||||
* Copyright © 2018 Google, Inc.
|
* Copyright © 2018 Google, Inc.
|
||||||
* Copyright © 2018 Ebrahim Byagowi
|
* Copyright © 2018-2019 Ebrahim Byagowi
|
||||||
*
|
*
|
||||||
* This is part of HarfBuzz, a text shaping library.
|
* This is part of HarfBuzz, a text shaping library.
|
||||||
*
|
*
|
||||||
|
@ -32,9 +32,6 @@
|
||||||
#include "hb-open-type.hh"
|
#include "hb-open-type.hh"
|
||||||
#include "hb-ot-layout-common.hh"
|
#include "hb-ot-layout-common.hh"
|
||||||
|
|
||||||
/* To be removed */
|
|
||||||
typedef hb_tag_t hb_ot_layout_baseline_t;
|
|
||||||
|
|
||||||
namespace OT {
|
namespace OT {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -153,14 +150,9 @@ struct BaseCoord
|
||||||
|
|
||||||
struct FeatMinMaxRecord
|
struct FeatMinMaxRecord
|
||||||
{
|
{
|
||||||
HB_INTERNAL static int cmp (const void *key_, const void *entry_)
|
int cmp (hb_tag_t key) const { return tag.cmp (key); }
|
||||||
{
|
|
||||||
hb_tag_t key = * (hb_tag_t *) key_;
|
bool has_data () const { return tag; }
|
||||||
const FeatMinMaxRecord &entry = * (const FeatMinMaxRecord *) entry_;
|
|
||||||
return key < (unsigned int) entry.tag ? -1 :
|
|
||||||
key > (unsigned int) entry.tag ? 1 :
|
|
||||||
0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void get_min_max (const BaseCoord **min, const BaseCoord **max) const
|
void get_min_max (const BaseCoord **min, const BaseCoord **max) const
|
||||||
{
|
{
|
||||||
|
@ -198,14 +190,9 @@ struct MinMax
|
||||||
const BaseCoord **min,
|
const BaseCoord **min,
|
||||||
const BaseCoord **max) const
|
const BaseCoord **max) const
|
||||||
{
|
{
|
||||||
/* TODO Replace hb_bsearch() with .bsearch(). */
|
const FeatMinMaxRecord &minMaxCoord = featMinMaxRecords.bsearch (feature_tag);
|
||||||
const FeatMinMaxRecord *minMaxCoord = (const FeatMinMaxRecord *)
|
if (minMaxCoord.has_data ())
|
||||||
hb_bsearch (&feature_tag, featMinMaxRecords.arrayZ,
|
minMaxCoord.get_min_max (min, max);
|
||||||
featMinMaxRecords.len,
|
|
||||||
FeatMinMaxRecord::static_size,
|
|
||||||
FeatMinMaxRecord::cmp);
|
|
||||||
if (minMaxCoord)
|
|
||||||
minMaxCoord->get_min_max (min, max);
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (likely (min)) *min = &(this+minCoord);
|
if (likely (min)) *min = &(this+minCoord);
|
||||||
|
@ -271,14 +258,9 @@ struct BaseValues
|
||||||
|
|
||||||
struct BaseLangSysRecord
|
struct BaseLangSysRecord
|
||||||
{
|
{
|
||||||
HB_INTERNAL static int cmp (const void *key_, const void *entry_)
|
int cmp (hb_tag_t key) const { return baseLangSysTag.cmp (key); }
|
||||||
{
|
|
||||||
hb_tag_t key = * (hb_tag_t *) key_;
|
bool has_data () const { return baseLangSysTag; }
|
||||||
const BaseLangSysRecord &entry = * (const BaseLangSysRecord *) entry_;
|
|
||||||
return key < (unsigned int) entry.baseLangSysTag ? -1 :
|
|
||||||
key > (unsigned int) entry.baseLangSysTag ? 1 :
|
|
||||||
0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const MinMax &get_min_max () const
|
const MinMax &get_min_max () const
|
||||||
{ return this+minMax; }
|
{ return this+minMax; }
|
||||||
|
@ -303,19 +285,14 @@ struct BaseScript
|
||||||
{
|
{
|
||||||
const MinMax &get_min_max (hb_tag_t language_tag) const
|
const MinMax &get_min_max (hb_tag_t language_tag) const
|
||||||
{
|
{
|
||||||
/* TODO Replace hb_bsearch() with .bsearch(). */
|
const BaseLangSysRecord& record = baseLangSysRecords.bsearch (language_tag);
|
||||||
const BaseLangSysRecord* record = (const BaseLangSysRecord *)
|
return record.has_data () ? record.get_min_max () : this+defaultMinMax;
|
||||||
hb_bsearch (&language_tag, baseLangSysRecords.arrayZ,
|
|
||||||
baseLangSysRecords.len,
|
|
||||||
BaseLangSysRecord::static_size,
|
|
||||||
BaseLangSysRecord::cmp);
|
|
||||||
return record ? record->get_min_max () : this+defaultMinMax;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const BaseCoord &get_base_coord (int baseline_tag_index) const
|
const BaseCoord &get_base_coord (int baseline_tag_index) const
|
||||||
{ return (this+baseValues).get_base_coord (baseline_tag_index); }
|
{ return (this+baseValues).get_base_coord (baseline_tag_index); }
|
||||||
|
|
||||||
bool is_empty () const { return !baseValues; }
|
bool has_data () const { return baseValues; }
|
||||||
|
|
||||||
bool sanitize (hb_sanitize_context_t *c) const
|
bool sanitize (hb_sanitize_context_t *c) const
|
||||||
{
|
{
|
||||||
|
@ -345,14 +322,9 @@ struct BaseScript
|
||||||
struct BaseScriptList;
|
struct BaseScriptList;
|
||||||
struct BaseScriptRecord
|
struct BaseScriptRecord
|
||||||
{
|
{
|
||||||
HB_INTERNAL static int cmp (const void *key_, const void *entry_)
|
int cmp (hb_tag_t key) const { return baseScriptTag.cmp (key); }
|
||||||
{
|
|
||||||
hb_tag_t key = * (hb_tag_t *) key_;
|
bool has_data () const { return baseScriptTag; }
|
||||||
const BaseScriptRecord &entry = * (const BaseScriptRecord *) entry_;
|
|
||||||
return key < (unsigned int) entry.baseScriptTag ? -1 :
|
|
||||||
key > (unsigned int) entry.baseScriptTag ? 1 :
|
|
||||||
0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const BaseScript &get_base_script (const BaseScriptList *list) const
|
const BaseScript &get_base_script (const BaseScriptList *list) const
|
||||||
{ return list+baseScript; }
|
{ return list+baseScript; }
|
||||||
|
@ -376,20 +348,11 @@ struct BaseScriptRecord
|
||||||
|
|
||||||
struct BaseScriptList
|
struct BaseScriptList
|
||||||
{
|
{
|
||||||
const BaseScriptRecord *find_record (hb_tag_t script) const
|
|
||||||
{
|
|
||||||
/* TODO Replace hb_bsearch() with .bsearch(). */
|
|
||||||
return (const BaseScriptRecord *) hb_bsearch (&script, baseScriptRecords.arrayZ,
|
|
||||||
baseScriptRecords.len,
|
|
||||||
BaseScriptRecord::static_size,
|
|
||||||
BaseScriptRecord::cmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TODO: Or client should handle fallback? */
|
|
||||||
const BaseScript &get_base_script (hb_tag_t script) const
|
const BaseScript &get_base_script (hb_tag_t script) const
|
||||||
{
|
{
|
||||||
const BaseScriptRecord *record = find_record (script);
|
const BaseScriptRecord *record = &baseScriptRecords.bsearch (script);
|
||||||
if (!record) record = find_record ((hb_script_t) HB_TAG ('D','F','L','T'));
|
/* TODO: Or client should handle fallback? */
|
||||||
|
if (!record->has_data ()) record = &baseScriptRecords.bsearch (HB_TAG ('D','F','L','T'));
|
||||||
|
|
||||||
return record ? record->get_base_script (this) : Null (BaseScript);
|
return record ? record->get_base_script (this) : Null (BaseScript);
|
||||||
}
|
}
|
||||||
|
@ -417,9 +380,14 @@ struct Axis
|
||||||
const BaseCoord **coord) const
|
const BaseCoord **coord) const
|
||||||
{
|
{
|
||||||
const BaseScript &base_script = (this+baseScriptList).get_base_script (script_tag);
|
const BaseScript &base_script = (this+baseScriptList).get_base_script (script_tag);
|
||||||
if (base_script.is_empty ()) return false;
|
if (!base_script.has_data ()) return false;
|
||||||
|
|
||||||
if (likely (coord)) *coord = &base_script.get_base_coord ((this+baseTagList).bsearch (baseline));
|
if (likely (coord))
|
||||||
|
{
|
||||||
|
unsigned int tag_index = 0;
|
||||||
|
(this+baseTagList).bfind (baseline, &tag_index);
|
||||||
|
*coord = &base_script.get_base_coord (tag_index);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -431,7 +399,7 @@ struct Axis
|
||||||
const BaseCoord **max_coord) const
|
const BaseCoord **max_coord) const
|
||||||
{
|
{
|
||||||
const BaseScript &base_script = (this+baseScriptList).get_base_script (script_tag);
|
const BaseScript &base_script = (this+baseScriptList).get_base_script (script_tag);
|
||||||
if (base_script.is_empty ()) return false;
|
if (!base_script.has_data ()) return false;
|
||||||
|
|
||||||
base_script.get_min_max (language_tag).get_min_max (feature_tag, min_coord, max_coord);
|
base_script.get_min_max (language_tag).get_min_max (feature_tag, min_coord, max_coord);
|
||||||
|
|
||||||
|
@ -483,9 +451,9 @@ struct BASE
|
||||||
if (!get_axis (direction).get_baseline (baseline, script_tag, language_tag, &base_coord))
|
if (!get_axis (direction).get_baseline (baseline, script_tag, language_tag, &base_coord))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (likely (base && base_coord)) *base = base_coord->get_coord (font,
|
if (likely (base && base_coord))
|
||||||
get_var_store (),
|
*base = base_coord->get_coord (font, get_var_store (), direction);
|
||||||
direction);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue