2008-01-15 23:46:32 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2000 Red Hat, Inc.
|
2000-12-20 05:41:36 +01:00
|
|
|
*
|
2008-01-15 23:46:32 +01:00
|
|
|
* This is part of HarfBuzz, an OpenType Layout engine library.
|
2000-12-20 05:41:36 +01:00
|
|
|
*
|
2008-01-15 23:46:32 +01:00
|
|
|
* 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.
|
2000-12-20 05:41:36 +01:00
|
|
|
*
|
2008-01-15 23:46:32 +01:00
|
|
|
* 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.
|
2000-12-20 05:41:36 +01:00
|
|
|
*
|
2008-01-15 23:46:32 +01:00
|
|
|
* 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): Owen Taylor
|
2000-12-20 05:41:36 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2007-11-07 09:06:01 +01:00
|
|
|
#include "harfbuzz.h"
|
2006-03-31 14:28:09 +02:00
|
|
|
#include "harfbuzz-dump.h"
|
2000-12-20 05:41:36 +01:00
|
|
|
|
|
|
|
#define N_ELEMENTS(arr) (sizeof(arr)/ sizeof((arr)[0]))
|
|
|
|
|
2005-08-29 12:06:40 +02:00
|
|
|
static int
|
2007-10-11 02:07:58 +02:00
|
|
|
croak (const char *situation, HB_Error error)
|
2000-12-20 05:41:36 +01:00
|
|
|
{
|
|
|
|
fprintf (stderr, "%s: Error %d\n", situation, error);
|
|
|
|
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2005-08-29 12:06:40 +02:00
|
|
|
#if 0
|
2000-12-20 05:41:36 +01:00
|
|
|
enum {
|
|
|
|
I = 1 << 0,
|
|
|
|
M = 1 << 1,
|
|
|
|
F = 1 << 2,
|
|
|
|
L = 1 << 3
|
|
|
|
};
|
|
|
|
|
2005-08-29 12:06:40 +02:00
|
|
|
static void
|
2007-10-25 00:44:47 +02:00
|
|
|
print_tag (HB_UInt tag)
|
2000-12-20 05:41:36 +01:00
|
|
|
{
|
|
|
|
fprintf (stderr, "%c%c%c%c",
|
|
|
|
(unsigned char)(tag >> 24),
|
2005-08-29 12:06:40 +02:00
|
|
|
(unsigned char)((tag >> 16) & 0xff),
|
|
|
|
(unsigned char)((tag >> 8) & 0xff),
|
2000-12-20 05:41:36 +01:00
|
|
|
(unsigned char)(tag & 0xff));
|
|
|
|
}
|
|
|
|
|
2005-08-29 12:06:40 +02:00
|
|
|
static void
|
2006-03-31 14:28:09 +02:00
|
|
|
maybe_add_feature (HB_GSUB gsub,
|
2007-10-25 00:44:47 +02:00
|
|
|
HB_UShort script_index,
|
|
|
|
HB_UInt tag,
|
|
|
|
HB_UShort property)
|
2000-12-20 05:41:36 +01:00
|
|
|
{
|
2007-10-11 02:07:58 +02:00
|
|
|
HB_Error error;
|
2007-10-25 00:44:47 +02:00
|
|
|
HB_UShort feature_index;
|
2000-12-20 05:41:36 +01:00
|
|
|
|
|
|
|
/* 0xffff == default language system */
|
2006-03-31 14:28:09 +02:00
|
|
|
error = HB_GSUB_Select_Feature (gsub, tag, script_index, 0xffff, &feature_index);
|
2000-12-20 05:41:36 +01:00
|
|
|
|
|
|
|
if (error)
|
|
|
|
{
|
2006-03-31 14:28:09 +02:00
|
|
|
if (error == HB_Err_Not_Covered)
|
2000-12-20 05:41:36 +01:00
|
|
|
{
|
|
|
|
print_tag (tag);
|
|
|
|
fprintf (stderr, " not covered, ignored\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-03-31 14:28:09 +02:00
|
|
|
croak ("HB_GSUB_Select_Feature", error);
|
2000-12-20 05:41:36 +01:00
|
|
|
}
|
|
|
|
|
2006-03-31 14:28:09 +02:00
|
|
|
if ((error = HB_GSUB_Add_Feature (gsub, feature_index, property)))
|
|
|
|
croak ("HB_GSUB_Add_Feature", error);
|
2000-12-20 05:41:36 +01:00
|
|
|
}
|
|
|
|
|
2005-08-29 12:06:40 +02:00
|
|
|
static void
|
2006-03-31 14:28:09 +02:00
|
|
|
add_features (HB_GSUB gsub)
|
2000-12-20 05:41:36 +01:00
|
|
|
{
|
2007-10-11 02:07:58 +02:00
|
|
|
HB_Error error;
|
2007-10-25 02:23:46 +02:00
|
|
|
HB_UInt tag = HB_MAKE_TAG ('a', 'r', 'a', 'b');
|
2007-10-25 00:44:47 +02:00
|
|
|
HB_UShort script_index;
|
2000-12-20 05:41:36 +01:00
|
|
|
|
2006-03-31 14:28:09 +02:00
|
|
|
error = HB_GSUB_Select_Script (gsub, tag, &script_index);
|
2000-12-20 05:41:36 +01:00
|
|
|
|
|
|
|
if (error)
|
|
|
|
{
|
2006-03-31 14:28:09 +02:00
|
|
|
if (error == HB_Err_Not_Covered)
|
2000-12-20 05:41:36 +01:00
|
|
|
{
|
|
|
|
fprintf (stderr, "Arabic not covered, no features used\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-03-31 14:28:09 +02:00
|
|
|
croak ("HB_GSUB_Select_Script", error);
|
2000-12-20 05:41:36 +01:00
|
|
|
}
|
|
|
|
|
2007-10-25 02:23:46 +02:00
|
|
|
maybe_add_feature (gsub, script_index, HB_MAKE_TAG ('i', 'n', 'i', 't'), I);
|
|
|
|
maybe_add_feature (gsub, script_index, HB_MAKE_TAG ('m', 'e', 'd', 'i'), M);
|
|
|
|
maybe_add_feature (gsub, script_index, HB_MAKE_TAG ('f', 'i', 'n', 'a'), F);
|
|
|
|
maybe_add_feature (gsub, script_index, HB_MAKE_TAG ('l', 'i', 'g', 'a'), L);
|
2000-12-20 05:41:36 +01:00
|
|
|
}
|
2005-08-29 12:06:40 +02:00
|
|
|
#endif
|
2000-12-20 05:41:36 +01:00
|
|
|
|
2004-02-29 16:44:50 +01:00
|
|
|
#if 0
|
2000-12-20 05:41:36 +01:00
|
|
|
void
|
2006-03-31 14:28:09 +02:00
|
|
|
dump_string (HB_GSUB_String *str)
|
2000-12-20 05:41:36 +01:00
|
|
|
{
|
2007-10-25 00:44:47 +02:00
|
|
|
HB_UInt i;
|
2000-12-20 05:41:36 +01:00
|
|
|
|
|
|
|
fprintf (stderr, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
|
|
|
|
for (i = 0; i < str->length; i++)
|
|
|
|
{
|
2003-07-26 04:10:42 +02:00
|
|
|
fprintf (stderr, "%2lu: %#06x %#06x %4d %4d\n",
|
2000-12-20 05:41:36 +01:00
|
|
|
i,
|
|
|
|
str->string[i],
|
|
|
|
str->properties[i],
|
|
|
|
str->components[i],
|
|
|
|
str->ligIDs[i]);
|
|
|
|
}
|
|
|
|
fprintf (stderr, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
|
|
|
|
}
|
|
|
|
|
2007-10-25 00:44:47 +02:00
|
|
|
HB_UShort arabic_str[] = { 0x645, 0x643, 0x64a, 0x644, 0x639, 0x20, 0x645, 0x627, 0x644, 0x633, 0x644, 0x627 };
|
|
|
|
HB_UShort arabic_props[] = { I|L, M|L, M|L, M|L, M|L, F|L, I|L, M|L, M|L, M|L, M|L, F|L };
|
2000-12-20 05:41:36 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
try_string (FT_Library library,
|
2007-11-07 10:59:18 +01:00
|
|
|
HB_Font font,
|
2006-03-31 14:28:09 +02:00
|
|
|
HB_GSUB gsub)
|
2000-12-20 05:41:36 +01:00
|
|
|
{
|
2007-10-11 02:07:58 +02:00
|
|
|
HB_Error error;
|
2006-03-31 14:28:09 +02:00
|
|
|
HB_GSUB_String *in_str;
|
|
|
|
HB_GSUB_String *out_str;
|
2007-10-25 00:44:47 +02:00
|
|
|
HB_UInt i;
|
2000-12-20 05:41:36 +01:00
|
|
|
|
2007-11-07 10:59:18 +01:00
|
|
|
if ((error = HB_GSUB_String_New (font->memory, &in_str)))
|
2006-03-31 14:28:09 +02:00
|
|
|
croak ("HB_GSUB_String_New", error);
|
2007-11-07 10:59:18 +01:00
|
|
|
if ((error = HB_GSUB_String_New (font->memory, &out_str)))
|
2006-03-31 14:28:09 +02:00
|
|
|
croak ("HB_GSUB_String_New", error);
|
2000-12-20 05:41:36 +01:00
|
|
|
|
2006-03-31 14:28:09 +02:00
|
|
|
if ((error = HB_GSUB_String_Set_Length (in_str, N_ELEMENTS (arabic_str))))
|
|
|
|
croak ("HB_GSUB_String_Set_Length", error);
|
2000-12-20 05:41:36 +01:00
|
|
|
|
|
|
|
for (i=0; i < N_ELEMENTS (arabic_str); i++)
|
|
|
|
{
|
2007-11-07 10:59:18 +01:00
|
|
|
in_str->string[i] = FT_Get_Char_Index (font, arabic_str[i]);
|
2000-12-20 05:41:36 +01:00
|
|
|
in_str->properties[i] = arabic_props[i];
|
|
|
|
in_str->components[i] = i;
|
|
|
|
in_str->ligIDs[i] = i;
|
|
|
|
}
|
|
|
|
|
2006-03-31 14:28:09 +02:00
|
|
|
if ((error = HB_GSUB_Apply_String (gsub, in_str, out_str)))
|
|
|
|
croak ("HB_GSUB_Apply_String", error);
|
2000-12-20 05:41:36 +01:00
|
|
|
|
|
|
|
dump_string (in_str);
|
|
|
|
dump_string (out_str);
|
|
|
|
|
2006-03-31 14:28:09 +02:00
|
|
|
if ((error = HB_GSUB_String_Done (in_str)))
|
|
|
|
croak ("HB_GSUB_String_New", error);
|
|
|
|
if ((error = HB_GSUB_String_Done (out_str)))
|
|
|
|
croak ("HB_GSUB_String_New", error);
|
2000-12-20 05:41:36 +01:00
|
|
|
}
|
2004-02-29 16:44:50 +01:00
|
|
|
#endif
|
2000-12-20 05:41:36 +01:00
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2007-10-11 02:07:58 +02:00
|
|
|
HB_Error error;
|
2000-12-20 05:41:36 +01:00
|
|
|
FT_Library library;
|
2007-11-07 10:59:18 +01:00
|
|
|
HB_Font font;
|
2006-03-31 14:28:09 +02:00
|
|
|
HB_GSUB gsub;
|
|
|
|
HB_GPOS gpos;
|
2000-12-20 05:41:36 +01:00
|
|
|
|
|
|
|
if (argc != 2)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Usage: ottest MYFONT.TTF\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = FT_Init_FreeType (&library)))
|
|
|
|
croak ("FT_Init_FreeType", error);
|
|
|
|
|
2007-11-07 10:59:18 +01:00
|
|
|
if ((error = FT_New_Face (library, argv[1], 0, &font)))
|
2000-12-20 05:41:36 +01:00
|
|
|
croak ("FT_New_Face", error);
|
|
|
|
|
2005-08-29 12:06:40 +02:00
|
|
|
printf ("<?xml version=\"1.0\"?>\n");
|
|
|
|
printf ("<OpenType>\n");
|
|
|
|
|
2007-11-07 10:59:18 +01:00
|
|
|
if (!(error = HB_Load_GSUB_Table (font, &gsub, NULL)))
|
2000-12-20 05:41:36 +01:00
|
|
|
{
|
2006-03-31 14:28:09 +02:00
|
|
|
HB_Dump_GSUB_Table (gsub, stdout);
|
2000-12-20 05:41:36 +01:00
|
|
|
|
2006-03-31 14:28:09 +02:00
|
|
|
if ((error = HB_Done_GSUB_Table (gsub)))
|
|
|
|
croak ("HB_Done_GSUB_Table", error);
|
2000-12-20 05:41:36 +01:00
|
|
|
}
|
2007-10-26 01:22:17 +02:00
|
|
|
else if (error != HB_Err_Not_Covered)
|
2007-11-18 23:34:08 +01:00
|
|
|
fprintf (stderr, "HB_Load_GSUB_Table: error 0x%x\n", error);
|
2000-12-20 05:41:36 +01:00
|
|
|
|
2007-11-07 10:59:18 +01:00
|
|
|
if (!(error = HB_Load_GPOS_Table (font, &gpos, NULL)))
|
2000-12-20 05:41:36 +01:00
|
|
|
{
|
2006-03-31 14:28:09 +02:00
|
|
|
HB_Dump_GPOS_Table (gpos, stdout);
|
2000-12-20 05:41:36 +01:00
|
|
|
|
2006-03-31 14:28:09 +02:00
|
|
|
if ((error = HB_Done_GPOS_Table (gpos)))
|
|
|
|
croak ("HB_Done_GPOS_Table", error);
|
2000-12-20 05:41:36 +01:00
|
|
|
}
|
2007-10-26 01:22:17 +02:00
|
|
|
else if (error != HB_Err_Not_Covered)
|
2007-11-18 23:34:08 +01:00
|
|
|
fprintf (stderr, "HB_Load_GPOS_Table: error 0x%x\n", error);
|
2000-12-20 05:41:36 +01:00
|
|
|
|
2005-08-29 12:06:40 +02:00
|
|
|
printf ("</OpenType>\n");
|
|
|
|
|
2000-12-20 05:41:36 +01:00
|
|
|
#if 0
|
2007-11-07 10:59:18 +01:00
|
|
|
select_cmap (font);
|
2000-12-20 05:41:36 +01:00
|
|
|
|
|
|
|
add_features (gsub);
|
2007-11-07 10:59:18 +01:00
|
|
|
try_string (library, font, gsub);
|
2000-12-20 05:41:36 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-11-07 10:59:18 +01:00
|
|
|
if ((error = FT_Done_Face (font)))
|
2000-12-20 05:41:36 +01:00
|
|
|
croak ("FT_Done_Face", error);
|
|
|
|
|
|
|
|
if ((error = FT_Done_FreeType (library)))
|
|
|
|
croak ("FT_Done_FreeType", error);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|