Example #1
0
const bitmap* freetype::get_bitmap(unsigned int char_code) const
{
    implement::cache& cache = impl_->get_cache();
    if (cache.find(char_code) != cache.end())
        return &cache[char_code];

    FT_GlyphSlot glyph = impl_->load_glyph(char_code);
    if (!glyph || 0 != FT_Render_Glyph(glyph, impl_->property_.render_mode))
        return nullptr;

    bitmap* bitmap = &cache[char_code];
    unsigned int buffer_length = glyph->bitmap.rows * glyph->bitmap.pitch;

    bitmap->left       = glyph->bitmap_left;
    bitmap->top        = glyph->bitmap_top - ascender();
    bitmap->width      = glyph->bitmap.width;
    bitmap->height     = glyph->bitmap.rows;
    bitmap->advance    = REAL(glyph->linearHoriAdvance, 16);
    bitmap->pitch      = glyph->bitmap.pitch;
    bitmap->pixel_mode = glyph->bitmap.pixel_mode;
    bitmap->buffer     = reinterpret_cast<unsigned char*>(
                                memcpy(new unsigned char [buffer_length],
                                       glyph->bitmap.buffer,
                                       buffer_length));

    return bitmap;
}
Example #2
0
double dsp(int tn) {
  double tx0 = tn / 44100.0;
  double amp = 0.0;
  double pi2 = 2.0 * acos(-1.0);
  int tones = 1 + ((int) tx0) / 16;
  for (int i = 0; i < tones; i++) {
    double tx = tx0 - 16.0 * i;
    double freq = ascender(tx);
    double ax = fader(tx);
    amp += 1.8 * ax * sin(pi2 * (0.1 * i + 20.0 * freq * tx));
  }
  if (amp > 1.0) amp = 1.0;
  if (amp < -1.0) amp = -1.0;
  return amp;
}