remember to specify the bloody font tag in the constructor!

git-svn-id: http://skia.googlecode.com/svn/trunk@118 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@android.com 2009-03-10 04:02:30 +00:00
Родитель 330578d67d
Коммит 590ef3fd3a
2 изменённых файлов: 51 добавлений и 9 удалений

Просмотреть файл

@ -29,6 +29,14 @@ static const struct {
static const int gFaceCount = SK_ARRAY_COUNT(gFaces); static const int gFaceCount = SK_ARRAY_COUNT(gFaces);
static const char* gStrings[] = {
"HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH",
"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",
"......................................",
"11111111111111111111111111111111111111",
"00000000000000000000000000000000000000"
};
class FontScalerTestView : public SkView { class FontScalerTestView : public SkView {
SkTypeface* fFaces[gFaceCount]; SkTypeface* fFaces[gFaceCount];
@ -67,16 +75,29 @@ protected:
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setTypeface(SkTypeface::CreateFromName("Times Roman", SkTypeface::kNormal))->safeUnref(); paint.setTypeface(SkTypeface::CreateFromName("Times Roman", SkTypeface::kNormal))->safeUnref();
const char* text = "HHHaaammmbbbuuurrrgggeeefffooonnnsss"; // const char* text = "abcdefghijklmnopqrstuvwxyz";
const size_t textLen = strlen(text); const char* text = "HnHnHnHnHnHnHnHnH";
size_t textLen = strlen(text);
SkScalar x = SkIntToScalar(10); SkScalar x = SkIntToScalar(10);
SkScalar y = SkIntToScalar(20); SkScalar y = SkIntToScalar(20);
{
SkPaint p;
p.setColor(SK_ColorRED);
SkRect r;
r.set(0, 0, x, y*20);
canvas->drawRect(r, p);
}
int index = 0;
for (int ps = 9; ps <= 24; ps++) { for (int ps = 9; ps <= 24; ps++) {
// text = gStrings[index % SK_ARRAY_COUNT(gStrings)];
textLen = strlen(text);
paint.setTextSize(SkIntToScalar(ps)); paint.setTextSize(SkIntToScalar(ps));
canvas->drawText(text, textLen, x, y, paint); canvas->drawText(text, textLen, x, y, paint);
y += paint.getFontMetrics(NULL); y += paint.getFontMetrics(NULL);
index += 1;
} }
} }

Просмотреть файл

@ -124,11 +124,32 @@ SkScalerContext_Mac::SkScalerContext_Mac(const SkDescriptor* desc)
SkScalarToFloat(m[SkMatrix::kMTransX]), SkScalarToFloat(m[SkMatrix::kMTransX]),
SkScalarToFloat(m[SkMatrix::kMTransY])); SkScalarToFloat(m[SkMatrix::kMTransY]));
ATSStyleRenderingOptions renderOpts = kATSStyleApplyAntiAliasing;
Fixed fixedSize = SK_Fixed1; //SkScalarToFixed(fRec.fTextSize); switch (fRec.fHints) {
static const ATSUAttributeTag tags[] = { kATSUSizeTag, kATSUFontMatrixTag }; case kNo_Hints:
static const ByteCount sizes[] = { sizeof(Fixed), sizeof(fTransform) }; renderOpts |= kATSStyleNoHinting;
const ATSUAttributeValuePtr values[] = { &fixedSize, &fTransform }; break;
case kSubpixel_Hints:
// hmmm, need to support subpixel... from path?
renderOpts |= kATSStyleNoHinting;
break;
case kNormal_Hints:
renderOpts |= kATSStyleApplyHints;
break;
}
ATSUFontID fontID = FMGetFontFromATSFontRef(fRec.fFontID);
// we put everything in the matrix, so our pt size is just 1.0
Fixed fixedSize = SK_Fixed1;
static const ATSUAttributeTag tags[] = {
kATSUFontTag, kATSUSizeTag, kATSUFontMatrixTag, kATSUStyleRenderingOptionsTag
};
static const ByteCount sizes[] = {
sizeof(fontID), sizeof(fixedSize), sizeof(fTransform), sizeof(renderOpts)
};
const ATSUAttributeValuePtr values[] = {
&fontID, &fixedSize, &fTransform, &renderOpts
};
err = ::ATSUSetAttributes(fStyle, SK_ARRAY_COUNT(tags), err = ::ATSUSetAttributes(fStyle, SK_ARRAY_COUNT(tags),
tags, sizes, values); tags, sizes, values);
SkASSERT(0 == err); SkASSERT(0 == err);
@ -199,7 +220,7 @@ void SkScalerContext_Mac::generateMetrics(SkGlyph* glyph) {
set_glyph_metrics_on_error(glyph); set_glyph_metrics_on_error(glyph);
return; return;
} }
if (kNormal_Hints == fRec.fHints) { if (kNormal_Hints == fRec.fHints) {
glyph->fAdvanceX = SkFloatToFixed(screenMetrics.deviceAdvance.x); glyph->fAdvanceX = SkFloatToFixed(screenMetrics.deviceAdvance.x);
glyph->fAdvanceY = -SkFloatToFixed(screenMetrics.deviceAdvance.y); glyph->fAdvanceY = -SkFloatToFixed(screenMetrics.deviceAdvance.y);
@ -234,7 +255,7 @@ void SkScalerContext_Mac::generateImage(const SkGlyph& glyph)
::CGContextSetGrayFillColor(contextRef, 1.0, 1.0); ::CGContextSetGrayFillColor(contextRef, 1.0, 1.0);
::CGContextSetTextDrawingMode(contextRef, kCGTextFill); ::CGContextSetTextDrawingMode(contextRef, kCGTextFill);
CGGlyph glyphID = glyph.getGlyphID(); CGGlyph glyphID = glyph.getGlyphID(fBaseGlyphCount);
CGFontRef fontRef = CGFontCreateWithPlatformFont(&fRec.fFontID); CGFontRef fontRef = CGFontCreateWithPlatformFont(&fRec.fFontID);
CGContextSetFont(contextRef, fontRef); CGContextSetFont(contextRef, fontRef);
CGContextSetFontSize(contextRef, 1); CGContextSetFontSize(contextRef, 1);