⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fontcgwin.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    SelectObject(hdc, font->m_font.hfont());    // Set the correct color.    if (drawIntoBitmap)        SetTextColor(hdc, RGB(0, 0, 0));    else        SetTextColor(hdc, RGB(fillColor.red(), fillColor.green(), fillColor.blue()));    SetBkMode(hdc, TRANSPARENT);    SetTextAlign(hdc, TA_LEFT | TA_BASELINE);    // Uniscribe gives us offsets to help refine the positioning of combining glyphs.    FloatSize translation = glyphBuffer.offsetAt(from);    if (translation.width() || translation.height()) {        XFORM xform;        xform.eM11 = 1.0;        xform.eM12 = 0;        xform.eM21 = 0;        xform.eM22 = 1.0;        xform.eDx = translation.width();        xform.eDy = translation.height();        ModifyWorldTransform(hdc, &xform, MWT_LEFTMULTIPLY);    }    if (drawingMode == cTextFill) {        XFORM xform;        xform.eM11 = 1.0;        xform.eM12 = 0;        xform.eM21 = font->platformData().syntheticOblique() ? -tanf(syntheticObliqueAngle * piFloat / 180.0f) : 0;        xform.eM22 = 1.0;        xform.eDx = point.x();        xform.eDy = point.y();        ModifyWorldTransform(hdc, &xform, MWT_LEFTMULTIPLY);        ExtTextOut(hdc, 0, 0, ETO_GLYPH_INDEX, 0, reinterpret_cast<const WCHAR*>(glyphBuffer.glyphs(from)), numGlyphs, gdiAdvances.data());        if (font->m_syntheticBoldOffset) {            xform.eM21 = 0;            xform.eDx = font->m_syntheticBoldOffset;            xform.eDy = 0;            ModifyWorldTransform(hdc, &xform, MWT_LEFTMULTIPLY);            ExtTextOut(hdc, 0, 0, ETO_GLYPH_INDEX, 0, reinterpret_cast<const WCHAR*>(glyphBuffer.glyphs(from)), numGlyphs, gdiAdvances.data());        }    } else {        RetainPtr<CGMutablePathRef> path(AdoptCF, CGPathCreateMutable());        XFORM xform;        GetWorldTransform(hdc, &xform);        TransformationMatrix hdcTransform(xform.eM11, xform.eM21, xform.eM12, xform.eM22, xform.eDx, xform.eDy);        CGAffineTransform initialGlyphTransform = hdcTransform.isInvertible() ? hdcTransform.inverse() : CGAffineTransformIdentity;        if (font->platformData().syntheticOblique())            initialGlyphTransform = CGAffineTransformConcat(initialGlyphTransform, CGAffineTransformMake(1, 0, tanf(syntheticObliqueAngle * piFloat / 180.0f), 1, 0, 0));        initialGlyphTransform.tx = 0;        initialGlyphTransform.ty = 0;        CGAffineTransform glyphTranslation = CGAffineTransformIdentity;        for (unsigned i = 0; i < numGlyphs; ++i) {            RetainPtr<CGPathRef> glyphPath(AdoptCF, createPathForGlyph(hdc, glyphBuffer.glyphAt(from + i)));            CGAffineTransform glyphTransform = CGAffineTransformConcat(initialGlyphTransform, glyphTranslation);            CGPathAddPath(path.get(), &glyphTransform, glyphPath.get());            glyphTranslation = CGAffineTransformTranslate(glyphTranslation, gdiAdvances[i], 0);        }        CGContextRef cgContext = graphicsContext->platformContext();        CGContextSaveGState(cgContext);        BOOL fontSmoothingEnabled = false;        SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &fontSmoothingEnabled, 0);        CGContextSetShouldAntialias(cgContext, fontSmoothingEnabled);        CGContextScaleCTM(cgContext, 1.0, -1.0);        CGContextTranslateCTM(cgContext, point.x() + glyphBuffer.offsetAt(from).width(), -(point.y() + glyphBuffer.offsetAt(from).height()));        if (drawingMode & cTextFill) {            CGContextAddPath(cgContext, path.get());            CGContextFillPath(cgContext);            if (font->m_syntheticBoldOffset) {                CGContextTranslateCTM(cgContext, font->m_syntheticBoldOffset, 0);                CGContextAddPath(cgContext, path.get());                CGContextFillPath(cgContext);                CGContextTranslateCTM(cgContext, -font->m_syntheticBoldOffset, 0);            }        }        if (drawingMode & cTextStroke) {            CGContextAddPath(cgContext, path.get());            CGContextStrokePath(cgContext);            if (font->m_syntheticBoldOffset) {                CGContextTranslateCTM(cgContext, font->m_syntheticBoldOffset, 0);                CGContextAddPath(cgContext, path.get());                CGContextStrokePath(cgContext);                CGContextTranslateCTM(cgContext, -font->m_syntheticBoldOffset, 0);            }        }        CGContextRestoreGState(cgContext);    }    if (drawIntoBitmap) {        UInt8* buffer = bitmap->buffer();        unsigned bufferLength = bitmap->bufferLength();        for (unsigned i = 0; i < bufferLength; i += 4) {            // Use green, which is always in the middle.            UInt8 alpha = (255 - buffer[i + 1]) * fillColor.alpha() / 255;            buffer[i] = fillColor.blue();            buffer[i + 1] = fillColor.green();            buffer[i + 2] = fillColor.red();            buffer[i + 3] = alpha;        }        graphicsContext->drawWindowsBitmap(bitmap.get(), textRect.topLeft());    } else        graphicsContext->releaseWindowsContext(hdc, textRect, true, false);}void Font::drawGlyphs(GraphicsContext* graphicsContext, const SimpleFontData* font, const GlyphBuffer& glyphBuffer,                       int from, int numGlyphs, const FloatPoint& point) const{    CGContextRef cgContext = graphicsContext->platformContext();    bool shouldUseFontSmoothing = WebCoreShouldUseFontSmoothing();    if (font->platformData().useGDI()) {        if (!shouldUseFontSmoothing || (graphicsContext->textDrawingMode() & cTextStroke)) {            drawGDIGlyphs(graphicsContext, font, glyphBuffer, from, numGlyphs, point);            return;        }    }    uint32_t oldFontSmoothingStyle = wkSetFontSmoothingStyle(cgContext, shouldUseFontSmoothing);    const FontPlatformData& platformData = font->platformData();    CGContextSetFont(cgContext, platformData.cgFont());    CGAffineTransform matrix = CGAffineTransformIdentity;    matrix.b = -matrix.b;    matrix.d = -matrix.d;    if (platformData.syntheticOblique()) {        static float skew = -tanf(syntheticObliqueAngle * piFloat / 180.0f);        matrix = CGAffineTransformConcat(matrix, CGAffineTransformMake(1, 0, skew, 1, 0, 0));    }    CGContextSetTextMatrix(cgContext, matrix);    // Uniscribe gives us offsets to help refine the positioning of combining glyphs.    FloatSize translation = glyphBuffer.offsetAt(from);    CGContextSetFontSize(cgContext, platformData.size());    wkSetCGContextFontRenderingStyle(cgContext, font->isSystemFont(), false, font->platformData().useGDI());    IntSize shadowSize;    int shadowBlur;    Color shadowColor;    graphicsContext->getShadow(shadowSize, shadowBlur, shadowColor);    bool hasSimpleShadow = graphicsContext->textDrawingMode() == cTextFill && shadowColor.isValid() && !shadowBlur;    if (hasSimpleShadow) {        // Paint simple shadows ourselves instead of relying on CG shadows, to avoid losing subpixel antialiasing.        graphicsContext->clearShadow();        Color fillColor = graphicsContext->fillColor();        Color shadowFillColor(shadowColor.red(), shadowColor.green(), shadowColor.blue(), shadowColor.alpha() * fillColor.alpha() / 255);        graphicsContext->setFillColor(shadowFillColor);        CGContextSetTextPosition(cgContext, point.x() + translation.width() + shadowSize.width(), point.y() + translation.height() + shadowSize.height());        CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);        if (font->m_syntheticBoldOffset) {            CGContextSetTextPosition(cgContext, point.x() + translation.width() + shadowSize.width() + font->m_syntheticBoldOffset, point.y() + translation.height() + shadowSize.height());            CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);        }        graphicsContext->setFillColor(fillColor);    }    CGContextSetTextPosition(cgContext, point.x() + translation.width(), point.y() + translation.height());    CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);    if (font->m_syntheticBoldOffset) {        CGContextSetTextPosition(cgContext, point.x() + translation.width() + font->m_syntheticBoldOffset, point.y() + translation.height());        CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);    }    if (hasSimpleShadow)        graphicsContext->setShadow(shadowSize, shadowBlur, shadowColor);    wkRestoreFontSmoothingStyle(cgContext, oldFontSmoothingStyle);}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -