Skip to content

Commit

Permalink
[autofit] Don't depend on 'hb-ft'.
Browse files Browse the repository at this point in the history
The circular dependency is still there, but at least we no longer depend on
the HarfBuzz API that is only present if HarfBuzz has been built with
FreeType support, making the bootstrapping a bit easier.

* src/autofit/ft-hb.c, src/autofit/ft-hb.h: New files, providing
`_hb_ft_font_create`, which is more or less a verbatim copy of the
corresponding HarfBuzz code from file `hb-ft.cc`.

* src/autofit/afglobal.c (af_face_globals_new): Use it.
* src/autofit/afshaper.h: Don't include `hb-ft.h` but `ft-hb.h`.
* src/autofit/autofit.c: Include `ft-hb.c`.

* LICENSE.TXT: Updated.
  • Loading branch information
Matthias Clasen authored and lemzwerg committed Jan 6, 2023
1 parent 262b47a commit ebe7e91
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 2 deletions.
4 changes: 4 additions & 0 deletions LICENSE.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ in earlier FreeType versions.
The gzip module uses the zlib license (see `src/gzip/zlib.h`) which
too is compatible to the above two licenses.

The files `src/autofit/ft-hb.c` and `src/autofit/ft-hb.h` contain code
taken almost verbatim from the HarfBuzz file `hb-ft.cc`, which uses
the 'Old MIT' license, compatible to the above two licenses.

The MD5 checksum support (only used for debugging in development
builds) is in the public domain.

Expand Down
2 changes: 1 addition & 1 deletion src/autofit/afglobal.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@
globals->scale_down_factor = 0;

#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
globals->hb_font = hb_ft_font_create( face, NULL );
globals->hb_font = _hb_ft_font_create( face, NULL );
globals->hb_buf = hb_buffer_create();
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/autofit/afshaper.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include <hb.h>
#include <hb-ot.h>
#include <hb-ft.h>
#include "ft-hb.h"

#endif

Expand Down
1 change: 1 addition & 0 deletions src/autofit/autofit.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#define FT_MAKE_OPTION_SINGLE_OBJECT

#include "ft-hb.c"
#include "afblue.c"
#include "afcjk.c"
#include "afdummy.c"
Expand Down
106 changes: 106 additions & 0 deletions src/autofit/ft-hb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright © 2009, 2023 Red Hat, Inc.
* Copyright © 2015 Google, Inc.
*
* 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.
*
* Red Hat Author(s): Behdad Esfahbod, Matthias Clasen
* Google Author(s): Behdad Esfahbod
*/

#include <freetype/freetype.h>
#include <freetype/tttables.h>

#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ

#include "ft-hb.h"

/* The following three functions are a more or less verbatim
* copy of corresponding HarfBuzz code from hb-ft.cc
*/

static hb_blob_t *
_hb_ft_reference_table (hb_face_t *face, hb_tag_t tag, void *user_data)
{
FT_Face ft_face = (FT_Face) user_data;
FT_Byte *buffer;
FT_ULong length = 0;
FT_Error error;

/* Note: FreeType like HarfBuzz uses the NONE tag for fetching the entire blob */

error = FT_Load_Sfnt_Table (ft_face, tag, 0, NULL, &length);
if (error)
return NULL;

buffer = (FT_Byte *) malloc (length);
if (!buffer)
return NULL;

error = FT_Load_Sfnt_Table (ft_face, tag, 0, buffer, &length);
if (error)
{
free (buffer);
return NULL;
}

return hb_blob_create ((const char *) buffer, length,
HB_MEMORY_MODE_WRITABLE,
buffer, free);
}

static hb_face_t *
_hb_ft_face_create (FT_Face ft_face,
hb_destroy_func_t destroy)
{
hb_face_t *face;

if (!ft_face->stream->read) {
hb_blob_t *blob;

blob = hb_blob_create ((const char *) ft_face->stream->base,
(unsigned int) ft_face->stream->size,
HB_MEMORY_MODE_READONLY,
ft_face, destroy);
face = hb_face_create (blob, ft_face->face_index);
hb_blob_destroy (blob);
} else {
face = hb_face_create_for_tables (_hb_ft_reference_table, ft_face, destroy);
}

hb_face_set_index (face, ft_face->face_index);
hb_face_set_upem (face, ft_face->units_per_EM);

return face;
}

hb_font_t *
_hb_ft_font_create (FT_Face ft_face,
hb_destroy_func_t destroy)
{
hb_font_t *font;
hb_face_t *face;

face = _hb_ft_face_create (ft_face, destroy);
font = hb_font_create (face);
hb_face_destroy (face);
return font;
}

#endif
35 changes: 35 additions & 0 deletions src/autofit/ft-hb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright © 2009, 2023 Red Hat, Inc.
* Copyright © 2015 Google, Inc.
*
* 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.
*
* Red Hat Author(s): Behdad Esfahbod, Matthias Clasen
* Google Author(s): Behdad Esfahbod
*/

#ifndef FT_HB_H
#define FT_HB_H

#include <hb.h>

hb_font_t * _hb_ft_font_create (FT_Face ft_face,
hb_destroy_func_t destroy);

#endif

0 comments on commit ebe7e91

Please sign in to comment.