• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************************
2  *
3  * afindic.c
4  *
5  *   Auto-fitter hinting routines for Indic writing system (body).
6  *
7  * Copyright (C) 2007-2023 by
8  * Rahul Bhalerao <rahul.bhalerao@redhat.com>, <b.rahul.pm@gmail.com>.
9  *
10  * This file is part of the FreeType project, and may only be used,
11  * modified, and distributed under the terms of the FreeType project
12  * license, LICENSE.TXT.  By continuing to use, modify, or distribute
13  * this file you indicate that you have read the license and
14  * understand and accept it fully.
15  *
16  */
17 
18 
19 #include "aftypes.h"
20 #include "aflatin.h"
21 #include "afcjk.h"
22 
23 
24 #ifdef AF_CONFIG_OPTION_INDIC
25 
26 #include "afindic.h"
27 #include "aferrors.h"
28 
29 
30   static FT_Error
af_indic_metrics_init(AF_CJKMetrics metrics,FT_Face face)31   af_indic_metrics_init( AF_CJKMetrics  metrics,
32                          FT_Face        face )
33   {
34     /* skip blue zone init in CJK routines */
35     FT_CharMap  oldmap = face->charmap;
36 
37 
38     metrics->units_per_em = face->units_per_EM;
39 
40     if ( FT_Select_Charmap( face, FT_ENCODING_UNICODE ) )
41       face->charmap = NULL;
42     else
43     {
44       af_cjk_metrics_init_widths( metrics, face );
45 #if 0
46       /* either need indic specific blue_chars[] or just skip blue zones */
47       af_cjk_metrics_init_blues( metrics, face, af_cjk_blue_chars );
48 #endif
49       af_cjk_metrics_check_digits( metrics, face );
50     }
51 
52     face->charmap = oldmap;
53     return FT_Err_Ok;
54   }
55 
56 
57   static void
af_indic_metrics_scale(AF_CJKMetrics metrics,AF_Scaler scaler)58   af_indic_metrics_scale( AF_CJKMetrics  metrics,
59                           AF_Scaler      scaler )
60   {
61     /* use CJK routines */
62     af_cjk_metrics_scale( metrics, scaler );
63   }
64 
65 
66   static FT_Error
af_indic_hints_init(AF_GlyphHints hints,AF_CJKMetrics metrics)67   af_indic_hints_init( AF_GlyphHints  hints,
68                        AF_CJKMetrics  metrics )
69   {
70     /* use CJK routines */
71     return af_cjk_hints_init( hints, metrics );
72   }
73 
74 
75   static FT_Error
af_indic_hints_apply(FT_UInt glyph_index,AF_GlyphHints hints,FT_Outline * outline,AF_CJKMetrics metrics)76   af_indic_hints_apply( FT_UInt        glyph_index,
77                         AF_GlyphHints  hints,
78                         FT_Outline*    outline,
79                         AF_CJKMetrics  metrics )
80   {
81     /* use CJK routines */
82     return af_cjk_hints_apply( glyph_index, hints, outline, metrics );
83   }
84 
85 
86   /* Extract standard_width from writing system/script specific */
87   /* metrics class.                                             */
88 
89   static void
af_indic_get_standard_widths(AF_CJKMetrics metrics,FT_Pos * stdHW,FT_Pos * stdVW)90   af_indic_get_standard_widths( AF_CJKMetrics  metrics,
91                                 FT_Pos*        stdHW,
92                                 FT_Pos*        stdVW )
93   {
94     if ( stdHW )
95       *stdHW = metrics->axis[AF_DIMENSION_VERT].standard_width;
96 
97     if ( stdVW )
98       *stdVW = metrics->axis[AF_DIMENSION_HORZ].standard_width;
99   }
100 
101 
102   /*************************************************************************/
103   /*************************************************************************/
104   /*****                                                               *****/
105   /*****                I N D I C   S C R I P T   C L A S S            *****/
106   /*****                                                               *****/
107   /*************************************************************************/
108   /*************************************************************************/
109 
110 
111   AF_DEFINE_WRITING_SYSTEM_CLASS(
112     af_indic_writing_system_class,
113 
114     AF_WRITING_SYSTEM_INDIC,
115 
116     sizeof ( AF_CJKMetricsRec ),
117 
118     (AF_WritingSystem_InitMetricsFunc) af_indic_metrics_init,        /* style_metrics_init    */
119     (AF_WritingSystem_ScaleMetricsFunc)af_indic_metrics_scale,       /* style_metrics_scale   */
120     (AF_WritingSystem_DoneMetricsFunc) NULL,                         /* style_metrics_done    */
121     (AF_WritingSystem_GetStdWidthsFunc)af_indic_get_standard_widths, /* style_metrics_getstdw */
122 
123     (AF_WritingSystem_InitHintsFunc)   af_indic_hints_init,          /* style_hints_init      */
124     (AF_WritingSystem_ApplyHintsFunc)  af_indic_hints_apply          /* style_hints_apply     */
125   )
126 
127 
128 #else /* !AF_CONFIG_OPTION_INDIC */
129 
130 
131   AF_DEFINE_WRITING_SYSTEM_CLASS(
132     af_indic_writing_system_class,
133 
134     AF_WRITING_SYSTEM_INDIC,
135 
136     sizeof ( AF_CJKMetricsRec ),
137 
138     (AF_WritingSystem_InitMetricsFunc) NULL, /* style_metrics_init    */
139     (AF_WritingSystem_ScaleMetricsFunc)NULL, /* style_metrics_scale   */
140     (AF_WritingSystem_DoneMetricsFunc) NULL, /* style_metrics_done    */
141     (AF_WritingSystem_GetStdWidthsFunc)NULL, /* style_metrics_getstdw */
142 
143     (AF_WritingSystem_InitHintsFunc)   NULL, /* style_hints_init      */
144     (AF_WritingSystem_ApplyHintsFunc)  NULL  /* style_hints_apply     */
145   )
146 
147 
148 #endif /* !AF_CONFIG_OPTION_INDIC */
149 
150 
151 /* END */
152