Example #1
0
glyph
poor_bbb_font_rep::get_glyph (string s) {
  glyph gl= base->get_glyph (s);
  if (is_nil (gl)) return gl;
  font_metric fnm;
  font_glyphs fng;
  int c= base->index_glyph (s, fnm, fng);
  if (c < 0) return glyph ();
  return make_bbb (gl, c, wpen, hpen, fat);
}
Example #2
0
string
count_trace (font fn, array<int> cs) {
  array<int> a;
  for (int i= 0; i < N(cs); i++) {
    string s; s << ((char) cs[i]);
    glyph g= fn->get_glyph (s);
    if (is_nil (g)) return "";
    a << pixel_count (g);
  }
  return array_trace (a);
}
Example #3
0
void
analyze_major (font fn, font_metric fnm, array<string>& r) {
  if (range_exists (fnm, 0x41, 0x5a) && range_exists (fnm, 0x61, 0x7a)) {
    metric_struct* x= fnm->get (0x78);
    int ex= max (x->y2 / 256, 1);
    r << (string ("ex=") * as_string (ex));
    metric_struct* M= fnm->get (0x4d);
    int em_rat= (100 * (M->x2 / 256)) / ex;
    r << (string ("em=") * as_string (em_rat));
    
    glyph glo= fn->get_glyph ("o");
    if (!is_nil (glo)) {
      int lvw= (100 * vertical_stroke_width (glo)) / ex;
      int lhw= (100 * horizontal_stroke_width (glo)) / ex;
      r << (string ("lvw=") * as_string (lvw));
      r << (string ("lhw=") * as_string (lhw));
    }
    
    glyph glO= fn->get_glyph ("O");
    if (!is_nil (glO)) {
      int uvw= (100 * vertical_stroke_width (glO)) / ex;
      int uhw= (100 * horizontal_stroke_width (glO)) / ex;
      r << (string ("uvw=") * as_string (uvw));
      r << (string ("uhw=") * as_string (uhw));
    }

    int cnt= 0;
    int totlw= 0;
    double fill= 0.0;
    for (int i= 0x41; i<=0x7a; i++)
      if (i <= 0x5a || i >= 0x61) {
        string s; s << ((char) i);
        glyph g= fn->get_glyph (s);
        if (!is_nil (g)) {
          cnt += pixel_count (g);
          totlw += g->lwidth;
          fill += fill_rate (g);
        }
      }
    int fillp= (int) (100.0 * (fill / 52.0));
    int vcnt= cnt / max (totlw, 1);
    r << (string ("fillp=") * as_string (fillp));
    r << (string ("vcnt=") * as_string (vcnt));

    int lo_lw= 0;
    int lo_pw= 0;
    for (int i= 0x61; i<=0x7a; i++) {
      metric_struct* c= fnm->get (i);
      lo_lw += (c->x2 / 256);
      string s; s << ((char) i);
      glyph g= fn->get_glyph (s);
      if (!is_nil (g)) lo_pw += g->width;
    }
    int lasprat= (100 * lo_lw) / (26 * ex);
    int pasprat= (100 * lo_pw) / (26 * ex);
    r << (string ("lasprat=") * as_string (lasprat));
    r << (string ("pasprat=") * as_string (pasprat));

    //int irreg= irregularity (fnm);
    //r << (string ("irreg=") * as_string (irreg));

    int loasc= (100 * max_ascent (fnm, 0x61, 0x7a)) / ex;
    int lodes= (100 * (ex + max_descent (fnm, 0x61, 0x7a))) / ex;
    r << (string ("loasc=") * as_string (loasc));
    r << (string ("lodes=") * as_string (lodes));
    if (range_exists (fnm, 0x30, 0x39)) {
      int dides= (100 * (ex + max_descent (fnm, 0x30, 0x39))) / ex;
      r << (string ("dides=") * as_string (dides));
    }
  }
}
Example #4
0
void
analyze_special (font fn, font_metric fnm, array<string>& r) {
  if (range_exists (fnm, 0x41, 0x5a) && range_exists (fnm, 0x61, 0x7a)) {
    bool mono= true;
    metric_struct* x= fnm->get (0x41);
    for (int i= 0x42; i<=0x7a; i++)
      if (i <= 0x5a || i >= 0x61) {
        metric_struct* y= fnm->get (i);
        if (y->x2 != x->x2) {
          mono= false;
          break;
        }
      }
    if (mono) r << string ("mono=yes");
    else r << string ("mono=no");
  }

  if (range_exists (fnm, 0x41, 0x5a)) {
    glyph glL= fn->get_glyph ("L");
    if (!is_nil (glL)) {
      bool sans= is_sans_serif (glL);
      if (sans) r << string ("sans=yes");
      else r << string ("sans=no");
    }
  }

  if (range_exists (fnm, 0x5b, 0x5b)) {
    glyph gl= fn->get_glyph ("[");
    if (!is_nil (gl)) {
      int sl= (int) floor (100.0 * get_slant (gl) + 0.5);
      r << (string ("slant=") * as_string (sl));
    }
  }

  if (range_exists (fnm, 0x61, 0x7a)) {
    bool italic= true;
    glyph ga= fn->get_glyph ("a");
    if (is_nil (ga)) italic= false;
    else {
      int status= italic_a_status (ga);
      //r << (string ("italic-a=") * as_string (status));
      italic= (status == 0);
    }
    metric_struct* f= fnm->get (0x66);
    metric_struct* x= fnm->get (0x78);
    italic= italic && (f->y3 < -(x->y2/5));
    if (italic) r << string ("italic=yes");
    else r << string ("italic=no");    
  }

  if (range_exists (fnm, 0x41, 0x5a) && range_exists (fnm, 0x61, 0x7a)) {
    array<int> upr= build_range (0x41, 0x5a);
    array<int> lor= build_range (0x61, 0x7a);
    array<int> uph= decode_trace (height_trace (fnm, upr));
    array<int> loh= decode_trace (height_trace (fnm, lor));
    if (l1_distance (loh, uph) <= N(upr)) {
      metric_struct* A= fnm->get (0x41);
      metric_struct* a= fnm->get (0x61);
      int Ah= A->y4 - A->y3;
      int ah= a->y4 - a->y3;
      if (ah < ((95 * Ah) / 100)) r << string ("case=smallcaps");
      else r << string ("case=caps");
    }
    else r << string ("case=mixed");
  }

  if (range_exists (fnm, 0x61, 0x7a)) {
    bool regular= (irregularity (fnm) <= 6);
    if (regular) r << string ("regular=yes");
    else r << string ("regular=no");
  }
}
Example #5
0
glyph
poor_stretched_font_rep::get_glyph (string s) {
  glyph gl= base->get_glyph (s);
  return stretched (gl, 1.0, factor);
}