当前位置: 首页>>代码示例>>C++>>正文


C++ BitmapPtr::GetBuffer方法代码示例

本文整理汇总了C++中BitmapPtr::GetBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ BitmapPtr::GetBuffer方法的具体用法?C++ BitmapPtr::GetBuffer怎么用?C++ BitmapPtr::GetBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BitmapPtr的用法示例。


在下文中一共展示了BitmapPtr::GetBuffer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetCharacter

// use getBitmap = false to find out glyph x-advance without copying/rendering bitmap
GlyphSet::Character* GetCharacter(FT_Face face, FT_ULong charcode,
                                  const unsigned int fieldSize, const unsigned int fieldPadding,
                                  const Vector2& maxGlyphCell,
                                  const bool renderBitmap, const bool highQuality)
{
  FT_Glyph glyph = GetGlyph(face, charcode, FT_LOAD_DEFAULT|FT_LOAD_NO_AUTOHINT);
  if(glyph == NULL)
  {
    // early out, if glyph is NULL
    return NULL;
  }

  // scale factor for unit scaled glyphs
  const float xScale = 1.0f / (face->size->metrics.x_scale / 65536.0f);
  const float yScale = 1.0f / (face->size->metrics.y_scale / 65536.0f);

  // create a new glyph-metric for the letter
  GlyphMetrics glyphMetrics;
  glyphMetrics.code     = charcode;
  glyphMetrics.quality  = (highQuality ? 1 : 0);
  glyphMetrics.xPosition = 0;
  glyphMetrics.yPosition = 0;

  // Set correct glyph size for underline
  const uint32_t UNDERLINE_CHARACTER( 0x0332 );
  if(charcode == UNDERLINE_CHARACTER)
  {
    float underlineBitmapWidth(64.f);
    float underlineBitmapHeight( 8.f );
    glyphMetrics.left     = 0.f;
    glyphMetrics.top      = 0.f;
    glyphMetrics.width    = xScale * underlineBitmapWidth;
    glyphMetrics.height   = yScale * underlineBitmapHeight;
    glyphMetrics.xAdvance = glyphMetrics.width;
  }
  else
  {
    // Regular glyphs
    glyphMetrics.left     = xScale * face->glyph->metrics.horiBearingX / 64.0f;
    glyphMetrics.top      = yScale * face->glyph->metrics.horiBearingY / 64.0f;
    glyphMetrics.width    = xScale * face->glyph->metrics.width / 64.0f;
    glyphMetrics.height   = yScale * face->glyph->metrics.height / 64.0f;
    glyphMetrics.xAdvance = xScale * face->glyph->metrics.horiAdvance / 64.0f;
  }

  // TODO: Look at generating the distance field directly from the glyph vector outline
  //       instead of FreeType's scaled bitmap
  BitmapPtr bitmapData = NULL;
  // bitmap required?
  if (renderBitmap)
  {
    // convert glyph to bitmap
    if (glyph->format != FT_GLYPH_FORMAT_BITMAP)
    {
      FT_Error retVal = FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 1);
      if(retVal != FT_Err_Ok)
      {
        DALI_LOG_WARNING("FT_Glyph_To_Bitmap failed %d\n", retVal);
        FT_Done_Glyph(glyph);
        return NULL;
      }
    }
    // cast the FT_Glyph to a FT_BitmapGlyph
    FT_BitmapGlyph bitmapGlyph = (FT_BitmapGlyph) glyph;

    // access the underlying bitmap data
    FT_Bitmap bitmap = bitmapGlyph->bitmap;

    DALI_LOG_INFO(gLogFilter, Log::Verbose, "%s(%c %f %f %f %f %f %f) [%.2f %.2f %.2f %.2f %f %f]\n",
                  __FUNCTION__, (int)charcode,
                  glyphMetrics.left, glyphMetrics.top, glyphMetrics.width, glyphMetrics.height,
                  glyphMetrics.xAdvance, face->height/64.0f,
                  xScale * bitmapGlyph->left, yScale * bitmapGlyph->top, xScale * bitmap.width, yScale * bitmap.rows,
                  glyph->advance.x / 65536.0f * xScale, face->ascender / 64.0f);

    // create a new bitmap for the glyph
    if(charcode == UNDERLINE_CHARACTER)
    {
      float underlineBitmapWidth( glyphMetrics.width / xScale );
      float underlineBitmapHeight( glyphMetrics.height / yScale );

      const unsigned int underlineBitmapSize(underlineBitmapWidth*underlineBitmapHeight);
      std::vector<unsigned char> underlineAlphaMap(underlineBitmapSize);
      std::fill(underlineAlphaMap.begin(), underlineAlphaMap.end(), 0xff);

      bitmapData = Integration::Bitmap::New(Bitmap::BITMAP_2D_PACKED_PIXELS, true);
      bitmapData->GetPackedPixelsProfile()->ReserveBuffer(Pixel::A8, fieldSize, fieldSize);
      GenerateDistanceFieldMap( &(*underlineAlphaMap.begin()), Vector2(underlineBitmapWidth, underlineBitmapHeight),
                               bitmapData->GetBuffer(), Vector2(fieldSize, fieldSize),
                               fieldPadding, Vector2( maxGlyphCell.width / xScale, maxGlyphCell.height / yScale ),
                               highQuality );
    }
    else
    {
      if (0 != (bitmap.width * bitmap.rows))
      {
        bitmapData = Integration::Bitmap::New(Bitmap::BITMAP_2D_PACKED_PIXELS, true);
        bitmapData->GetPackedPixelsProfile()->ReserveBuffer(Pixel::A8, fieldSize, fieldSize);

//.........这里部分代码省略.........
开发者ID:Tarnyko,项目名称:dali-adaptor,代码行数:101,代码来源:loader-font.cpp


注:本文中的BitmapPtr::GetBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。