示例#1
0
bool GrFontScaler::getPackedGlyphDFImage(const SkGlyph& glyph, int width, int height, void* dst) {
    SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width);
    SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height);
    const void* image = fStrike->findImage(glyph);
    if (NULL == image) {
        return false;
    }
    // now generate the distance field
    SkASSERT(dst);
    SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat);
    if (SkMask::kA8_Format == maskFormat) {
        // make the distance field from the image
        SkGenerateDistanceFieldFromA8Image((unsigned char*)dst,
                                           (unsigned char*)image,
                                           glyph.fWidth, glyph.fHeight,
                                           glyph.rowBytes());
    } else if (SkMask::kBW_Format == maskFormat) {
        // make the distance field from the image
        SkGenerateDistanceFieldFromBWImage((unsigned char*)dst,
                                           (unsigned char*)image,
                                           glyph.fWidth, glyph.fHeight,
                                           glyph.rowBytes());
    } else {
        return false;
    }

    return true;
}
static bool get_packed_glyph_df_image(SkGlyphCache* cache, const SkGlyph& glyph,
                                      int width, int height, void* dst) {
    SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width);
    SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height);

#ifndef SK_USE_LEGACY_DISTANCE_FIELDS
    const SkPath* path = cache->findPath(glyph);
    if (nullptr == path) {
        return false;
    }

    SkDEBUGCODE(SkRect glyphBounds = SkRect::MakeXYWH(glyph.fLeft,
                                                      glyph.fTop,
                                                      glyph.fWidth,
                                                      glyph.fHeight));
    SkASSERT(glyphBounds.contains(path->getBounds()));

    // now generate the distance field
    SkASSERT(dst);
    SkMatrix drawMatrix;
    drawMatrix.setTranslate((SkScalar)-glyph.fLeft, (SkScalar)-glyph.fTop);

    // Generate signed distance field directly from SkPath
    bool succeed = GrGenerateDistanceFieldFromPath((unsigned char*)dst,
                                           *path, drawMatrix,
                                           width, height, width * sizeof(unsigned char));

    if (!succeed) {
#endif
        const void* image = cache->findImage(glyph);
        if (nullptr == image) {
            return false;
        }

        // now generate the distance field
        SkASSERT(dst);
        SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat);
        if (SkMask::kA8_Format == maskFormat) {
            // make the distance field from the image
            SkGenerateDistanceFieldFromA8Image((unsigned char*)dst,
                                               (unsigned char*)image,
                                               glyph.fWidth, glyph.fHeight,
                                               glyph.rowBytes());
        } else if (SkMask::kBW_Format == maskFormat) {
            // make the distance field from the image
            SkGenerateDistanceFieldFromBWImage((unsigned char*)dst,
                                               (unsigned char*)image,
                                               glyph.fWidth, glyph.fHeight,
                                               glyph.rowBytes());
        } else {
            return false;
        }
#ifndef SK_USE_LEGACY_DISTANCE_FIELDS
    }
#endif
    return true;
}
示例#3
0
const void* SkGlyphCache::findDistanceField(const SkGlyph& glyph) {
    if (glyph.fWidth > 0 && glyph.fWidth < kMaxGlyphWidth) {
        if (NULL == glyph.fDistanceField) {
            size_t  size = SkComputeDistanceFieldSize(glyph.fWidth, glyph.fHeight);
            if (size == 0) {
                return NULL;
            }
            const void* image = this->findImage(glyph);
            // now generate the distance field
            if (image) {
                const_cast<SkGlyph&>(glyph).fDistanceField = fGlyphAlloc.alloc(size,
                                            SkChunkAlloc::kReturnNil_AllocFailType);
                if (glyph.fDistanceField) {
                    SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat);
                    if (SkMask::kA8_Format == maskFormat) {
                        // make the distance field from the image
                        SkGenerateDistanceFieldFromA8Image((unsigned char*)glyph.fDistanceField,
                                                           (unsigned char*)glyph.fImage,
                                                           glyph.fWidth, glyph.fHeight,
                                                           glyph.rowBytes());
                        fMemoryUsed += size;
                    } else if (SkMask::kBW_Format == maskFormat) {
                        // make the distance field from the image
                        SkGenerateDistanceFieldFromBWImage((unsigned char*)glyph.fDistanceField,
                                                           (unsigned char*)glyph.fImage,
                                                           glyph.fWidth, glyph.fHeight,
                                                           glyph.rowBytes());
                        fMemoryUsed += size;
                    } else {
                        fGlyphAlloc.unalloc(glyph.fDistanceField);
                        const_cast<SkGlyph&>(glyph).fDistanceField = NULL;
                    }
                }
            }
        }
    }
    return glyph.fDistanceField;
}