~ubuntu-branches/ubuntu/saucy/m17n-lib/saucy

« back to all changes in this revision

Viewing changes to src/m17n-flt.c

  • Committer: Bazaar Package Importer
  • Author(s): Harshula Jayasuriya
  • Date: 2010-11-23 01:39:29 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20101123013929-rs3kpqgu4kr3qx32
Tags: 1.6.2-1
* New upstream release 1.6.2.
* Update Standards-Version to Debian Policy 3.9.1. (No changes)
* debian/control: Depends: m17n-db and m17n-contrib. (Closes: #599643)
* PATCH: (make_locale): Don't call setlocale.  Just parse the arg NAME.
         (Closes: #601858)

Show diffs side-by-side

added added

removed removed

Lines of Context:
742
742
  buf[i] = 0;
743
743
}
744
744
 
 
745
/* SYMBOL's name        features[0]             for checking    for applying
 
746
                               features[1]      GSUB     GPOS   GSUB    GPOS
 
747
   -------------        ------------------      -------------   ------------
 
748
   SCRIPT               [-1,0]      [-1,0]         any | any       all  all
 
749
   SCRIPT=              NULL        [-1,0]        none & 1        none  all
 
750
   SCRIPT+              [-1,0]        NULL           1 & none      all  none
 
751
   SCRIPT=+             NULL          NULL        none & none     none  none
 
752
   SCRIPT=F1            [F1,0]      [-1,0]          F1 & 1          F1  all
 
753
   SCRIPT+F1            [-1][0]     [F1,0]           1 & F1       none  F1
 
754
   SCRIPT=F1+           [F1,0]        NULL          F1 & none       F1  none
 
755
   SCRIPT=~F2           [-1,F2,0]   [-1,0]         ~F2 & 1      all~F2  all
 
756
   SCRIPT=F1,~F2        [F1,-1,F2,0][-1,0]      F1&~F2 & 1      F1 (*1) all
 
757
 
 
758
   (*1) Invalid specification
 
759
 */
 
760
 
745
761
static int
746
762
parse_otf_command (MSymbol symbol, MFLTOtfSpec *spec)
747
763
{
748
764
  char *str = MSYMBOL_NAME (symbol);
749
765
  char *end = str + MSYMBOL_NAMELEN (symbol);
750
766
  unsigned int script, langsys;
751
 
  char *gsub, *gpos;
752
 
  int gsub_count = 0, gpos_count = 0;
 
767
  char *features[3];
 
768
  int feature_count[2];         /* [0]:GSUB, [1]:GPOS */
 
769
  int i;
753
770
  char *p;
754
771
 
755
772
  memset (spec, 0, sizeof (MFLTOtfSpec));
765
782
        /* This is a spec to reset category codes.  */
766
783
        return 0;
767
784
    }
768
 
  script = gen_otf_tag (str, 8);
 
785
  spec->script = gen_otf_tag (str, 8);
769
786
  str += 4;
770
787
  if (*str == '/')
771
788
    {
772
 
      langsys = gen_otf_tag (str, 8);
 
789
      spec->langsys = gen_otf_tag (str, 8);
773
790
      str += 4;
774
791
    }
775
792
  else
776
 
    langsys = 0;
777
 
  gsub = str;
 
793
    spec->langsys = 0;
 
794
  features[0] = str;
778
795
  if (*str != '=')
779
796
    /* Apply all GSUB features.  */
780
 
      gsub_count = 1;
 
797
      feature_count[0] = -1;
781
798
  else
782
799
    {
783
800
      p = str + 1;
784
 
      str = otf_count_features (p, end, '+', &gsub_count);
 
801
      str = otf_count_features (p, end, '+', feature_count);
785
802
      if (! str)
786
803
        MERROR (MERROR_FLT, -1);
787
804
    }
788
 
  gpos = str;
 
805
  features[1] = str;
789
806
  if (*str != '+')
790
807
    /* Apply all GPOS features.  */
791
 
    gpos_count = 1;
 
808
    feature_count[1] = -1;
792
809
  else
793
810
    {
794
811
      p = str + 1;
795
 
      str = otf_count_features (p, end, '\0', &gpos_count);
 
812
      str = otf_count_features (p, end, '\0', feature_count + 1);
796
813
      if (! str)
797
814
        MERROR (MERROR_FLT, -1);
798
815
    }
799
 
 
800
 
  spec->script = script;
801
 
  spec->langsys = langsys;
802
 
  if (gsub_count > 0)
803
 
    {
804
 
      spec->features[0] = malloc (sizeof (int) * (gsub_count + 1));
805
 
      if (! spec->features[0])
806
 
        return -2;
807
 
      if (*gsub == '=')
808
 
        otf_store_features (gsub + 1, gpos, spec->features[0]);
809
 
      else
810
 
        spec->features[0][0] = 0xFFFFFFFF, spec->features[0][1] = 0;
811
 
    }
812
 
  if (gpos_count > 0)
813
 
    {
814
 
      spec->features[1] = malloc (sizeof (int) * (gpos_count + 1));
815
 
      if (! spec->features[1])
816
 
        {
817
 
          if (spec->features[0])
818
 
            free (spec->features[0]);
 
816
  features[2] = str;
 
817
  for (i = 0; i < 2; i++)
 
818
    if (feature_count[i])
 
819
      {
 
820
        spec->features[i] = malloc (sizeof (int)
 
821
                                    * (feature_count[i] < 0 ? 2
 
822
                                       : feature_count[i] + 1));
 
823
        if (! spec->features[i])
819
824
          return -2;
820
 
        }
821
 
      if (*gpos == '+')
822
 
        otf_store_features (gpos + 1, str, spec->features[1]);
823
 
      else
824
 
        spec->features[1][0] = 0xFFFFFFFF, spec->features[1][1] = 0;
825
 
    }
 
825
        if (feature_count[i] > 0)
 
826
          otf_store_features (features[i] + 1, features[i + 1],
 
827
                              spec->features[i]);
 
828
        else
 
829
          spec->features[i][0] = 0xFFFFFFFF, spec->features[i][1] = 0;
 
830
      }
 
831
 
826
832
  return 0;
827
833
}
828
834
 
1882
1888
          SET_CATEGORY_CODE (g, 0);
1883
1889
          continue;
1884
1890
        }
 
1891
      enc = '\0';
1885
1892
      if (tag & 0xFFFFF80)
1886
1893
        {
1887
1894
          int i;
1888
1895
 
1889
1896
          /* Clear the feature tag code.  */
1890
1897
          g->internal &= ~0xFFFFFFF;
1891
 
          for (i = 0, enc = '\0'; i < category->feature_table.size; i++)
 
1898
          for (i = 0; i < category->feature_table.size; i++)
1892
1899
            if (category->feature_table.tag[i] == tag)
1893
1900
              {
1894
1901
                enc = category->feature_table.code[i];
1897
1904
                break;
1898
1905
              }
1899
1906
        }
1900
 
      else
1901
 
        enc = '\0';
1902
1907
      if (! enc)
1903
 
        enc = g->c > 0 ? (int) mchartable_lookup (category->table, g->c) : 1;
 
1908
        enc = (g->c > 0 ? (int) mchartable_lookup (category->table, g->c)
 
1909
               : g->c == 0 ? 1 : ' ');
1904
1910
      SET_CATEGORY_CODE (g, enc);
1905
1911
    }
1906
1912
}
2018
2024
         FontLayoutContext *ctx)
2019
2025
{
2020
2026
  MFLTFont *font = ctx->font;
2021
 
  int from_idx = ctx->out->used;
2022
2027
 
2023
2028
  if (MDEBUG_FLAG () > 2)
2024
2029
    MDEBUG_PRINT3 ("\n [FLT] %*s%s", depth, "", MSYMBOL_NAME (otf_spec->sym));
2054
2059
  font->get_glyph_id (font, ctx->in, from, to);
2055
2060
  if (mflt_try_otf)
2056
2061
    {
2057
 
      int out_len;
2058
 
      int i;
2059
 
 
2060
2062
      to = mflt_try_otf (font, otf_spec, ctx->in, from, to);
2061
2063
      if (to < 0)
2062
2064
        return from;
2237
2239
      {
2238
2240
        int i;
2239
2241
 
 
2242
        if (MDEBUG_FLAG () > 2)
 
2243
          MDEBUG_PRINT2 ("\n [FLT] %*s|", depth, "");
2240
2244
        i = from < to ? from : from - 1;
2241
2245
        GDUP (ctx, i);
2242
2246
        g = GREF (ctx->out, ctx->out->used - 1);
2243
2247
        g->c = -1, g->code = 0;
2244
2248
        g->xadv = g->yadv = 0;
2245
 
        SET_ENCODED (g, 0);
 
2249
        SET_ENCODED (g, 1);
2246
2250
        SET_MEASURED (g, 0);
2247
2251
        SET_CATEGORY_CODE (g, ' ');
2248
2252
        return from;
2676
2680
  mflt_font_id = NULL;
2677
2681
  mflt_try_otf = NULL;
2678
2682
 
2679
 
  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize the flt modules."));
 
2683
  MDEBUG_PRINT_TIME ("INIT", (mdebug__output, " to initialize the flt modules."));
2680
2684
  MDEBUG_POP_TIME ();
2681
2685
}
2682
2686
 
2691
2695
 
2692
2696
  MDEBUG_PUSH_TIME ();
2693
2697
  free_flt_list ();
2694
 
  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize the flt modules."));
 
2698
  MDEBUG_PRINT_TIME ("FINI", (mdebug__output, " to finalize the flt modules."));
2695
2699
  MDEBUG_POP_TIME ();
2696
2700
  m17n_fini_core ();
2697
2701
}
3057
3061
        {
3058
3062
          MDEBUG_PRINT ("\n [FLT]   (RESULT");
3059
3063
          if (MDEBUG_FLAG () > 1)
3060
 
            for (i = 0; this_from < this_to; this_from++, i++)
3061
 
              {
3062
 
                if (i > 0 && i % 4 == 0)
3063
 
                  MDEBUG_PRINT ("\n [FLT]          ");
3064
 
                g = GREF (gstring, this_from);
3065
 
                MDEBUG_PRINT4 (" (%04X %d %d %d)",
3066
 
                               g->code, g->xadv, g->xoff, g->yoff);
3067
 
              }
 
3064
            {
 
3065
              int idx = -1;
 
3066
              for (i = 0; this_from < this_to; i++, this_from++)
 
3067
                {
 
3068
                  g = GREF (gstring, this_from);
 
3069
                  if (g->from != idx)
 
3070
                    {
 
3071
                      if (i > 0)
 
3072
                        MDEBUG_PRINT2 ("\n [FLT]           %02d-%02d",
 
3073
                                       g->from, g->to);
 
3074
                      else
 
3075
                        MDEBUG_PRINT2 (" %02d-%02d", g->from, g->to);
 
3076
                      idx = g->from;
 
3077
                    }
 
3078
                  MDEBUG_PRINT4 (" (%04X %d %d %d)",
 
3079
                                 g->code, g->xadv, g->xoff, g->yoff);
 
3080
                }
 
3081
            }
3068
3082
          else
3069
3083
            for (; this_from < this_to; this_from++)
3070
3084
              MDEBUG_PRINT1 (" %04X", GREF (gstring, this_from)->code);
3117
3131
  prefix[indent] = 0;
3118
3132
 
3119
3133
  if (id >= 0)
3120
 
    fprintf (stderr, "0x%02X", id);
 
3134
    fprintf (mdebug__output, "0x%02X", id);
3121
3135
  else if (id <= CMD_ID_OFFSET_INDEX)
3122
3136
    {
3123
3137
      int idx = CMD_ID_TO_INDEX (id);
3128
3142
          FontLayoutCmdRule *rule = &cmd->body.rule;
3129
3143
          int i;
3130
3144
 
3131
 
          fprintf (stderr, "(rule ");
 
3145
          fprintf (mdebug__output, "(rule ");
3132
3146
          if (rule->src_type == SRC_REGEX)
3133
 
            fprintf (stderr, "\"%s\"", rule->src.re.pattern);
 
3147
            fprintf (mdebug__output, "\"%s\"", rule->src.re.pattern);
3134
3148
          else if (rule->src_type == SRC_INDEX)
3135
 
            fprintf (stderr, "%d", rule->src.match_idx);
 
3149
            fprintf (mdebug__output, "%d", rule->src.match_idx);
3136
3150
          else if (rule->src_type == SRC_SEQ)
3137
 
            fprintf (stderr, "(seq)");
 
3151
            fprintf (mdebug__output, "(seq)");
3138
3152
          else if (rule->src_type == SRC_RANGE)
3139
 
            fprintf (stderr, "(range)");
 
3153
            fprintf (mdebug__output, "(range)");
3140
3154
          else
3141
 
            fprintf (stderr, "(invalid src)");
 
3155
            fprintf (mdebug__output, "(invalid src)");
3142
3156
 
3143
3157
          for (i = 0; i < rule->n_cmds; i++)
3144
3158
            {
3145
 
              fprintf (stderr, "\n%s  ", prefix);
 
3159
              fprintf (mdebug__output, "\n%s  ", prefix);
3146
3160
              dump_flt_cmd (stage, rule->cmd_ids[i], indent + 2);
3147
3161
            }
3148
 
          fprintf (stderr, ")");
 
3162
          fprintf (mdebug__output, ")");
3149
3163
        }
3150
3164
      else if (cmd->type == FontLayoutCmdTypeCond)
3151
3165
        {
3152
3166
          FontLayoutCmdCond *cond = &cmd->body.cond;
3153
3167
          int i;
3154
3168
 
3155
 
          fprintf (stderr, "(cond");
 
3169
          fprintf (mdebug__output, "(cond");
3156
3170
          for (i = 0; i < cond->n_cmds; i++)
3157
3171
            {
3158
 
              fprintf (stderr, "\n%s  ", prefix);
 
3172
              fprintf (mdebug__output, "\n%s  ", prefix);
3159
3173
              dump_flt_cmd (stage, cond->cmd_ids[i], indent + 2);
3160
3174
            }
3161
 
          fprintf (stderr, ")");
 
3175
          fprintf (mdebug__output, ")");
3162
3176
        }
3163
3177
      else if (cmd->type == FontLayoutCmdTypeOTF)
3164
3178
        {
3165
 
          fprintf (stderr, "(otf)");
 
3179
          fprintf (mdebug__output, "(otf)");
3166
3180
        }
3167
3181
      else
3168
 
        fprintf (stderr, "(error-command)");
 
3182
        fprintf (mdebug__output, "(error-command)");
3169
3183
    }
3170
3184
  else if (id <= CMD_ID_OFFSET_COMBINING)
3171
 
    fprintf (stderr, "cominging-code");
 
3185
    fprintf (mdebug__output, "cominging-code");
3172
3186
  else
3173
 
    fprintf (stderr, "(predefiend %d)", id);
 
3187
    fprintf (mdebug__output, "(predefiend %d)", id);
3174
3188
}
3175
3189
 
3176
3190
/***en
3177
3191
    @brief Dump a Font Layout Table.
3178
3192
 
3179
3193
    The mdebug_dump_flt () function prints the Font Layout Table $FLT
3180
 
    in a human readable way to the stderr.  $INDENT specifies how many
3181
 
    columns to indent the lines but the first one.
 
3194
    in a human readable way to the stderr or to what specified by the
 
3195
    environment variable MDEBUG_OUTPUT_FILE.  $INDENT specifies how
 
3196
    many columns to indent the lines but the first one.
3182
3197
 
3183
3198
    @return
3184
3199
    This function returns $FLT.  */
3192
3207
 
3193
3208
  memset (prefix, 32, indent);
3194
3209
  prefix[indent] = 0;
3195
 
  fprintf (stderr, "(flt");
 
3210
  fprintf (mdebug__output, "(flt");
3196
3211
  MPLIST_DO (plist, flt->stages)
3197
3212
    {
3198
3213
      FontLayoutStage *stage = (FontLayoutStage *) MPLIST_VAL (plist);
3199
3214
      int i;
3200
3215
 
3201
 
      fprintf (stderr, "\n%s  (stage %d", prefix, stage_idx);
 
3216
      fprintf (mdebug__output, "\n%s  (stage %d", prefix, stage_idx);
3202
3217
      for (i = 0; i < stage->used; i++)
3203
3218
        {
3204
 
          fprintf (stderr, "\n%s    ", prefix);
 
3219
          fprintf (mdebug__output, "\n%s    ", prefix);
3205
3220
          dump_flt_cmd (stage, INDEX_TO_CMD_ID (i), indent + 4);
3206
3221
        }
3207
 
      fprintf (stderr, ")");
 
3222
      fprintf (mdebug__output, ")");
3208
3223
      stage_idx++;
3209
3224
    }
3210
 
  fprintf (stderr, ")");
 
3225
  fprintf (mdebug__output, ")");
3211
3226
  return flt;
3212
3227
}
3213
3228
 
3216
3231
{
3217
3232
  int i;
3218
3233
 
3219
 
  fprintf (stderr, "(flt-gstring");
 
3234
  fprintf (mdebug__output, "(flt-gstring");
3220
3235
  for (i = 0; i < gstring->used; i++)
3221
3236
    {
3222
3237
      MFLTGlyph *g = GREF (gstring, i);
3223
 
      fprintf (stderr, "\n  (%02d pos:%d-%d c:%04X code:%04X cat:%c)",
 
3238
      fprintf (mdebug__output, "\n  (%02d pos:%d-%d c:%04X code:%04X cat:%c)",
3224
3239
               i, g->from, g->to, g->c, g->code, GET_CATEGORY_CODE (g));
3225
3240
    }
3226
 
  fprintf (stderr, ")\n");
 
3241
  fprintf (mdebug__output, ")\n");
3227
3242
}
3228
3243
 
3229
3244
/*** @} */