2018-02-19 19:57:08 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2018 Ebrahim Byagowi
|
2018-02-24 09:19:42 +00:00
|
|
|
* Copyright © 2018 Google, Inc.
|
2018-02-19 19:57:08 +00:00
|
|
|
*
|
|
|
|
* This is part of HarfBuzz, a text shaping library.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, without written agreement and without
|
|
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose, provided that the
|
|
|
|
* above copyright notice and the following two paragraphs appear in
|
|
|
|
* all copies of this software.
|
|
|
|
*
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
|
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
|
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
*
|
|
|
|
* Google Author(s): Behdad Esfahbod
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HB_AAT_LAYOUT_TRAK_TABLE_HH
|
|
|
|
#define HB_AAT_LAYOUT_TRAK_TABLE_HH
|
|
|
|
|
2018-08-26 05:36:36 +00:00
|
|
|
#include "hb-aat-layout-common.hh"
|
|
|
|
#include "hb-ot-layout.hh"
|
|
|
|
#include "hb-open-type.hh"
|
2018-02-19 19:57:08 +00:00
|
|
|
|
2018-04-12 09:08:19 +00:00
|
|
|
/*
|
|
|
|
* trak -- Tracking
|
|
|
|
* https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6trak.html
|
|
|
|
*/
|
2018-03-26 07:34:30 +00:00
|
|
|
#define HB_AAT_TAG_trak HB_TAG('t','r','a','k')
|
2018-02-19 19:57:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace AAT {
|
|
|
|
|
|
|
|
|
|
|
|
struct TrackTableEntry
|
|
|
|
{
|
2018-04-18 07:39:37 +00:00
|
|
|
friend struct TrackData;
|
|
|
|
|
2018-10-11 14:18:46 +00:00
|
|
|
inline float get_track_value () const
|
2018-02-19 19:57:08 +00:00
|
|
|
{
|
2018-10-11 14:18:46 +00:00
|
|
|
return track.to_float ();
|
2018-02-25 09:00:33 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 14:18:46 +00:00
|
|
|
inline int get_value (const void *base,
|
|
|
|
unsigned int index,
|
|
|
|
unsigned int nSizes) const
|
2018-02-25 09:00:33 +00:00
|
|
|
{
|
2018-10-11 14:18:46 +00:00
|
|
|
return hb_array_t<FWORD> ((base+valuesZ).arrayZ, nSizes)[index];
|
2018-02-19 19:57:08 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 14:18:46 +00:00
|
|
|
public:
|
|
|
|
inline bool sanitize (hb_sanitize_context_t *c, const void *base,
|
|
|
|
unsigned int nSizes) const
|
2018-02-24 09:19:42 +00:00
|
|
|
{
|
2018-10-11 14:18:46 +00:00
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (likely (c->check_struct (this) &&
|
|
|
|
(valuesZ.sanitize (c, base, nSizes))));
|
2018-02-24 09:19:42 +00:00
|
|
|
}
|
|
|
|
|
2018-02-19 19:57:08 +00:00
|
|
|
protected:
|
2018-03-14 15:31:53 +00:00
|
|
|
Fixed track; /* Track value for this record. */
|
2018-10-11 14:18:46 +00:00
|
|
|
NameID trackNameID; /* The 'name' table index for this track.
|
|
|
|
* (a short word or phrase like "loose"
|
|
|
|
* or "very tight") */
|
2018-09-15 17:43:33 +00:00
|
|
|
OffsetTo<UnsizedArrayOf<FWORD>, HBUINT16, false>
|
2018-04-18 07:39:37 +00:00
|
|
|
valuesZ; /* Offset from start of tracking table to
|
2018-03-14 15:31:53 +00:00
|
|
|
* per-size tracking values for this track. */
|
2018-02-19 19:57:08 +00:00
|
|
|
|
|
|
|
public:
|
2018-02-20 23:02:25 +00:00
|
|
|
DEFINE_SIZE_STATIC (8);
|
2018-02-19 19:57:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct TrackData
|
|
|
|
{
|
2018-02-24 09:19:42 +00:00
|
|
|
inline float get_tracking (const void *base, float ptem) const
|
|
|
|
{
|
|
|
|
/* CoreText points are CSS pixels (96 per inch),
|
|
|
|
* NOT typographic points (72 per inch).
|
|
|
|
*
|
|
|
|
* https://developer.apple.com/library/content/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Explained/Explained.html
|
|
|
|
*/
|
|
|
|
float csspx = ptem * 96.f / 72.f;
|
|
|
|
Fixed fixed_size;
|
|
|
|
fixed_size.set_float (csspx);
|
|
|
|
|
2018-02-26 08:32:11 +00:00
|
|
|
/* XXX Clean this up. Make it work with nSizes==1 and 0. */
|
2018-02-26 02:54:52 +00:00
|
|
|
|
2018-02-26 08:18:17 +00:00
|
|
|
unsigned int sizes = nSizes;
|
2018-02-25 09:00:33 +00:00
|
|
|
|
|
|
|
const TrackTableEntry *trackTableEntry = nullptr;
|
|
|
|
for (unsigned int i = 0; i < sizes; ++i)
|
|
|
|
// For now we only seek for track entries with zero tracking value
|
2018-04-23 15:06:53 +00:00
|
|
|
if (trackTable[i].get_track_value () == 0.f)
|
2018-02-25 09:00:33 +00:00
|
|
|
trackTableEntry = &trackTable[0];
|
|
|
|
|
|
|
|
// We couldn't match any, exit
|
|
|
|
if (!trackTableEntry) return 0.;
|
2018-02-24 09:19:42 +00:00
|
|
|
|
2018-02-26 02:54:52 +00:00
|
|
|
/* TODO bfind() */
|
2018-02-24 09:19:42 +00:00
|
|
|
unsigned int size_index;
|
2018-02-25 09:00:33 +00:00
|
|
|
UnsizedArrayOf<Fixed> size_table = base+sizeTable;
|
|
|
|
for (size_index = 0; size_index < sizes; ++size_index)
|
|
|
|
if (size_table[size_index] >= fixed_size)
|
2018-02-24 09:19:42 +00:00
|
|
|
break;
|
|
|
|
|
2018-02-25 09:00:33 +00:00
|
|
|
// TODO(ebraminio): We don't attempt to extrapolate to larger or
|
|
|
|
// smaller values for now but we should do, per spec
|
|
|
|
if (size_index == sizes)
|
2018-10-11 14:18:46 +00:00
|
|
|
return trackTableEntry->get_value (base, sizes - 1, nSizes);
|
2018-02-25 09:00:33 +00:00
|
|
|
if (size_index == 0 || size_table[size_index] == fixed_size)
|
2018-10-11 14:18:46 +00:00
|
|
|
return trackTableEntry->get_value (base, size_index, nSizes);
|
2018-02-24 09:19:42 +00:00
|
|
|
|
2018-02-25 09:00:33 +00:00
|
|
|
float s0 = size_table[size_index - 1].to_float ();
|
|
|
|
float s1 = size_table[size_index].to_float ();
|
2018-02-24 09:19:42 +00:00
|
|
|
float t = (csspx - s0) / (s1 - s0);
|
2018-10-11 14:18:46 +00:00
|
|
|
return (float) t * trackTableEntry->get_value (base, size_index, nSizes) +
|
|
|
|
((float) 1.0 - t) * trackTableEntry->get_value (base, size_index - 1, nSizes);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
|
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) &&
|
|
|
|
sizeTable.sanitize (c, base, nSizes) &&
|
|
|
|
trackTable.sanitize (c, nTracks, base, nSizes));
|
2018-02-24 09:19:42 +00:00
|
|
|
}
|
|
|
|
|
2018-02-19 19:57:08 +00:00
|
|
|
protected:
|
2018-04-11 13:11:24 +00:00
|
|
|
HBUINT16 nTracks; /* Number of separate tracks included in this table. */
|
|
|
|
HBUINT16 nSizes; /* Number of point sizes included in this table. */
|
2018-09-15 17:43:33 +00:00
|
|
|
LOffsetTo<UnsizedArrayOf<Fixed>, false>
|
2018-10-11 14:18:46 +00:00
|
|
|
sizeTable; /* Offset from start of the tracking table to
|
|
|
|
* Array[nSizes] of size values.. */
|
2018-02-26 08:32:11 +00:00
|
|
|
UnsizedArrayOf<TrackTableEntry>
|
2018-04-11 13:11:24 +00:00
|
|
|
trackTable; /* Array[nTracks] of TrackTableEntry records. */
|
2018-02-19 19:57:08 +00:00
|
|
|
|
|
|
|
public:
|
2018-02-20 23:02:25 +00:00
|
|
|
DEFINE_SIZE_ARRAY (8, trackTable);
|
2018-02-19 19:57:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct trak
|
|
|
|
{
|
2018-03-26 07:34:30 +00:00
|
|
|
static const hb_tag_t tableTag = HB_AAT_TAG_trak;
|
2018-02-19 19:57:08 +00:00
|
|
|
|
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-02-25 09:00:33 +00:00
|
|
|
|
2018-04-18 07:39:37 +00:00
|
|
|
return_trace (unlikely (c->check_struct (this) &&
|
|
|
|
horizData.sanitize (c, this, this) &&
|
|
|
|
vertData.sanitize (c, this, this)));
|
2018-02-19 19:57:08 +00:00
|
|
|
}
|
|
|
|
|
2018-02-24 09:19:42 +00:00
|
|
|
inline bool apply (hb_aat_apply_context_t *c) const
|
|
|
|
{
|
|
|
|
TRACE_APPLY (this);
|
2018-02-26 02:54:52 +00:00
|
|
|
|
2018-02-24 09:19:42 +00:00
|
|
|
const float ptem = c->font->ptem;
|
2018-04-18 07:39:37 +00:00
|
|
|
if (unlikely (ptem <= 0.f))
|
2018-02-26 02:54:52 +00:00
|
|
|
return_trace (false);
|
|
|
|
|
|
|
|
hb_buffer_t *buffer = c->buffer;
|
|
|
|
if (HB_DIRECTION_IS_HORIZONTAL (buffer->props.direction))
|
2018-02-24 09:19:42 +00:00
|
|
|
{
|
2018-02-26 02:54:52 +00:00
|
|
|
const TrackData &trackData = this+horizData;
|
|
|
|
float tracking = trackData.get_tracking (this, ptem);
|
|
|
|
hb_position_t advance_to_add = c->font->em_scalef_x (tracking / 2);
|
|
|
|
foreach_grapheme (buffer, start, end)
|
2018-02-24 09:19:42 +00:00
|
|
|
{
|
2018-07-01 11:02:43 +00:00
|
|
|
buffer->pos[start].x_offset += advance_to_add;
|
2018-02-26 02:54:52 +00:00
|
|
|
buffer->pos[start].x_advance += advance_to_add;
|
|
|
|
buffer->pos[end].x_advance += advance_to_add;
|
2018-02-24 09:19:42 +00:00
|
|
|
}
|
2018-02-26 02:54:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const TrackData &trackData = this+vertData;
|
|
|
|
float tracking = trackData.get_tracking (this, ptem);
|
|
|
|
hb_position_t advance_to_add = c->font->em_scalef_y (tracking / 2);
|
|
|
|
foreach_grapheme (buffer, start, end)
|
2018-02-24 09:19:42 +00:00
|
|
|
{
|
2018-07-01 11:02:43 +00:00
|
|
|
buffer->pos[start].y_offset += advance_to_add;
|
2018-02-26 02:54:52 +00:00
|
|
|
buffer->pos[start].y_advance += advance_to_add;
|
|
|
|
buffer->pos[end].y_advance += advance_to_add;
|
2018-02-24 09:19:42 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-26 02:54:52 +00:00
|
|
|
|
|
|
|
return_trace (true);
|
2018-02-24 09:19:42 +00:00
|
|
|
}
|
|
|
|
|
2018-02-19 19:57:08 +00:00
|
|
|
protected:
|
2018-10-11 14:18:46 +00:00
|
|
|
FixedVersion<> version; /* Version of the tracking table
|
|
|
|
* (0x00010000u for version 1.0). */
|
|
|
|
HBUINT16 format; /* Format of the tracking table (set to 0). */
|
|
|
|
OffsetTo<TrackData> horizData; /* Offset from start of tracking table to TrackData
|
|
|
|
* for horizontal text (or 0 if none). */
|
|
|
|
OffsetTo<TrackData> vertData; /* Offset from start of tracking table to TrackData
|
|
|
|
* for vertical text (or 0 if none). */
|
2018-02-20 23:02:25 +00:00
|
|
|
HBUINT16 reserved; /* Reserved. Set to 0. */
|
2018-02-19 19:57:08 +00:00
|
|
|
|
|
|
|
public:
|
2018-10-11 14:18:46 +00:00
|
|
|
DEFINE_SIZE_STATIC (12);
|
2018-02-19 19:57:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace AAT */
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* HB_AAT_LAYOUT_TRAK_TABLE_HH */
|