//---------------------------------------------------------------------------------------
GmoShapeArticulation* ArticulationEngraver::create_shape(ImoArticulation* pArticulation,
                                                         UPoint pos, Color color,
                                                         GmoShape* pParentShape)
{
    m_pArticulation = pArticulation;
    m_placement = pArticulation->get_placement();
    m_pParentShape = pParentShape;
    m_fAbove = determine_if_above();

    int iGlyph = find_glyph();
    double fontSize = determine_font_size();
    UPoint position = compute_location(pos);
    ShapeId idx = 0;
    m_pArticulationShape =
        LOMSE_NEW GmoShapeArticulation(pArticulation, idx, iGlyph, position,
                                       color, m_libraryScope, fontSize);
    add_voice();

    if (m_pArticulation->is_articulation_symbol()
        && m_pArticulation->get_articulation_type() != k_articulation_breath_mark
        && m_pArticulation->get_articulation_type() != k_articulation_caesura
       )
    {
        center_on_parent();
    }

    return m_pArticulationShape;
}
Exemple #2
0
    inline point text_extents(Font const& fnt, std::string const& x, size_t maxx)
    {
        typedef typename Font::glyph_type glyph;

        BOOST_ASSERT(maxx != 0);

        point result(0, 0);
        size_t i = 0;

        while (i != x.size())
        {
            int w = 0;

            if (x[i] == ' ')
            {
                w = average_char_width(fnt);
            }
            else
            {
                glyph const& glyph_i = find_glyph(fnt, x[i]);

                w = glyph_i.view.width() + glyph_i.bearing.x;
            }

            ++i;

            for (int j = 0; j != maxx && i != x.size(); ++j, ++i)
            {
                if (x[i] == ' ')
                {
                    w += average_char_width(fnt);
                }
                else
                {
                    glyph const& glyph_j = find_glyph(fnt, x[i]);

                    w += kerning_distance(fnt, x[i - 1], x[i]);
                    w += glyph_j.view.width() + glyph_j.bearing.x;
                }
            }

            result.x = std::max(result.x, w);
            result.y += line_length(fnt);
        }

        return result;
    }
Exemple #3
0
inline void IAtelier_summer::ToggleToolbar(const char* toolbar_name/* = "toolbar"*/)
{
    CToolbar_summer* tb = (CToolbar_summer*)find_glyph(toolbar_name);
    if (tb) tb->toggle_visible();

    //change(GLYPH_CHANGED_CANVAS_BKG | GLYPH_CHANGED_CANVAS);
    redraw_window();
}
// calculate the approx. width of a string of text
// note: no kerning info is currently evaluated
int		bmf__width(bm_font *font, char *text) {
  int	w, l, i;
  float scale = font->scale;
  w = 0;
  l = strlen(text);
  for (i=0;i < l; i++) {
    w += scale * find_glyph(font, text[i])->w;
  }
  return w+l;
}
//---------------------------------------------------------------------------------------
GmoShape* ClefEngraver::create_tool_dragged_shape(int clefType)
{
    Color color(255,0,0);       //TODO: options/configuration
    double fontSize = 21.0;
    ShapeId idx = 0;
    int iGlyph = find_glyph(clefType);
    UPoint pos(0.0, 0.0);

    m_pClefShape = LOMSE_NEW GmoShapeClef(NULL, idx, iGlyph, pos, color, m_libraryScope,
                                          fontSize);
    return m_pClefShape;
}
Exemple #6
0
    inline point text_extents(Font const& fnt, std::string const& x)
    {
        typedef typename Font::glyph_type glyph;

        point result(0, 0);

        if (x.empty())
            return result;

        if (x[0] == ' ')
        {
            result.x = average_char_width(fnt);
        }
        else
        {
            glyph const& first = find_glyph(fnt, x[0]);

            result.x = first.view.width() + first.bearing.x;
        }

        result.y = line_length(fnt);

        for (size_t i = 1; i != x.size(); ++i)
        {
            if (x[i] == ' ')
            {
                result.x += average_char_width(fnt);
            }
            else
            {
                glyph const& g = find_glyph(fnt, x[i]);

                result.x += kerning_distance(fnt, x[i - 1], x[i]);
                result.x += g.view.width() + g.bearing.x;
            }
        }

        return result;
    }
//---------------------------------------------------------------------------------------
GmoShapeCodaSegno* CodaSegnoEngraver::create_shape(ImoSymbolRepetitionMark* pRepetitionMark,
                                                   UPoint pos, Color color,
                                                   GmoShape* pParentShape)
{
    m_pRepetitionMark = pRepetitionMark;
    m_pParentShape = pParentShape;

    int iGlyph = find_glyph();
    double fontSize = determine_font_size();
    UPoint position = compute_location(pos);
    ShapeId idx = 0;
    m_pCodaSegnoShape =
        LOMSE_NEW GmoShapeCodaSegno(pRepetitionMark, idx, iGlyph, position,
                                    color, m_libraryScope, fontSize);
    center_on_parent();

    return m_pCodaSegnoShape;
}
//---------------------------------------------------------------------------------------
GmoShapeFermata* FermataEngraver::create_shape(ImoFermata* pFermata, UPoint pos,
                                               Color color, GmoShape* pParentShape)
{
    m_pFermata = pFermata;
    m_placement = pFermata->get_placement();
    m_pParentShape = pParentShape;
    m_fAbove = determine_if_above();

    int iGlyph = find_glyph();
    double fontSize = determine_font_size();
    UPoint position = compute_location(pos);
    ShapeId idx = 0;
    m_pFermataShape = LOMSE_NEW GmoShapeFermata(pFermata, idx, iGlyph, position,
                                                color, m_libraryScope, fontSize);
    add_voice();
    center_on_parent();
    return m_pFermataShape;
}
//---------------------------------------------------------------------------------------
GmoShape* ClefEngraver::create_shape(ImoClef* pCreatorImo, UPoint uPos, int clefType,
                                     int symbolSize, Color color)
{
    m_nClefType = clefType;
    m_symbolSize = symbolSize;
    m_iGlyph = find_glyph(clefType);

    // get the shift to the staff on which the clef must be drawn
    LUnits y = uPos.y + m_pMeter->tenths_to_logical(get_glyph_offset(), m_iInstr, m_iStaff);

    //Add minimum space before clef change
    LUnits x = uPos.x;
    if (symbolSize == k_size_cue)
        x += m_pMeter->tenths_to_logical(20.0f, m_iInstr, m_iStaff);

    double fontSize = determine_font_size();

    //create the shape object
    ShapeId idx = 0;
    m_pClefShape = LOMSE_NEW GmoShapeClef(pCreatorImo, idx, m_iGlyph, UPoint(x, y),
                                        color, m_libraryScope, fontSize);
    return m_pClefShape;
}
Exemple #10
0
/* Get a glyph corresponding to the codepoint CODE.  Always fill glyph
   information with something, even if no glyph is found.  */
int
grub_font_get_glyph (grub_uint32_t code,
                     grub_font_glyph_t glyph)
{
    struct font *font;
    grub_uint8_t bitmap[32];

    /* FIXME: It is necessary to cache glyphs!  */

restart:
    for (font = font_list; font; font = font->next)
    {
        grub_uint32_t offset;

        offset = find_glyph (font, code);
        if (offset)
        {
            grub_uint32_t w;
            int len;

            /* Make sure we can find glyphs for error messages.  Push active
               error message to error stack and reset error message.  */
            grub_error_push ();

            grub_file_seek (font->file, offset);
            if ((len = grub_file_read (font->file, (char *) &w, sizeof (w)))
                    != sizeof (w))
            {
                remove_font (font);
                goto restart;
            }

            w = grub_le_to_cpu32 (w);
            if (w != 1 && w != 2)
            {
                /* grub_error (GRUB_ERR_BAD_FONT, "invalid width"); */
                remove_font (font);
                goto restart;
            }

            if (grub_file_read (font->file, (char *) bitmap, w * 16)
                    != (grub_ssize_t) w * 16)
            {
                remove_font (font);
                goto restart;
            }

            /* Fill glyph with information.  */
            grub_memcpy (glyph->bitmap, bitmap, w * 16);

            glyph->char_width = w;
            glyph->width = glyph->char_width * 8;
            glyph->height = 16;
            glyph->baseline = (16 * 3) / 4;

            /* Restore old error message.  */
            grub_error_pop ();

            return 1;
        }
    }

    /* Uggh...  No font was found.  */
    fill_with_default_glyph (glyph);
    return 0;
}
Exemple #11
0
/* Get a glyph for the Unicode character CODE in FONT.  The glyph is loaded
   from the font file if has not been loaded yet.
   Returns a pointer to the glyph if found, or 0 if it is not found.  */
static struct grub_font_glyph *
grub_font_get_glyph_internal (grub_font_t font, grub_uint32_t code)
{
  struct char_index_entry *index_entry;

  index_entry = find_glyph (font, code);
  if (index_entry)
    {
      struct grub_font_glyph *glyph = 0;
      grub_uint16_t width;
      grub_uint16_t height;
      grub_int16_t xoff;
      grub_int16_t yoff;
      grub_int16_t dwidth;
      int len;

      if (index_entry->glyph)
	/* Return cached glyph.  */
	return index_entry->glyph;

      if (!font->file)
	/* No open file, can't load any glyphs.  */
	return 0;

      /* Make sure we can find glyphs for error messages.  Push active
         error message to error stack and reset error message.  */
      grub_error_push ();

      grub_file_seek (font->file, index_entry->offset);

      /* Read the glyph width, height, and baseline.  */
      if (read_be_uint16 (font->file, &width) != 0
	  || read_be_uint16 (font->file, &height) != 0
	  || read_be_int16 (font->file, &xoff) != 0
	  || read_be_int16 (font->file, &yoff) != 0
	  || read_be_int16 (font->file, &dwidth) != 0)
	{
	  remove_font (font);
	  return 0;
	}

      len = (width * height + 7) / 8;
      glyph = grub_malloc (sizeof (struct grub_font_glyph) + len);
      if (!glyph)
	{
	  remove_font (font);
	  return 0;
	}

      glyph->font = font;
      glyph->width = width;
      glyph->height = height;
      glyph->offset_x = xoff;
      glyph->offset_y = yoff;
      glyph->device_width = dwidth;

      /* Don't try to read empty bitmaps (e.g., space characters).  */
      if (len != 0)
	{
	  if (grub_file_read (font->file, glyph->bitmap, len) != len)
	    {
	      remove_font (font);
	      return 0;
	    }
	}

      /* Restore old error message.  */
      grub_error_pop ();

      /* Cache the glyph.  */
      index_entry->glyph = glyph;

      return glyph;
    }

  return 0;
}