making windows font sizes scale based on the CTM. bug 329306. r=vlad

This commit is contained in:
pavlov%pavlov.net 2006-03-04 04:40:07 +00:00
Родитель 17ad69885b
Коммит d099b3735d
5 изменённых файлов: 70 добавлений и 41 удалений

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

@ -241,7 +241,7 @@ public:
/**
* Returns the current transformation matrix.
*/
gfxMatrix CurrentMatrix() const;
const gfxMatrix& CurrentMatrix() const;
/**
* Converts a point from device to user coordinates using the inverse

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

@ -87,6 +87,15 @@ public:
mat = m;
}
bool operator==(const gfxMatrix& m) const {
return ((mat.xx == m.mat.xx) &&
(mat.yx == m.mat.yx) &&
(mat.xy == m.mat.xy) &&
(mat.yy == m.mat.yy) &&
(mat.x0 == m.mat.x0) &&
(mat.y0 == m.mat.y0));
}
gfxMatrix& operator=(const cairo_matrix_t& m) {
mat = m;
return *this;
@ -107,7 +116,7 @@ public:
}
// conversion to other types
cairo_matrix_t ToCairoMatrix() const {
const cairo_matrix_t& ToCairoMatrix() const {
return mat;
}

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

@ -57,8 +57,7 @@ class gfxWindowsFont : public gfxFont {
public:
gfxWindowsFont(const nsAString &aName, const gfxFontGroup *aFontGroup, HDC aHWnd);
gfxWindowsFont(HFONT aFont, const gfxFontGroup *aFontGroup, PRBool aIsMLangFont);
gfxWindowsFont(HFONT aFont, const gfxFontGroup *aFontGroup, PRBool aIsMLangFont, const gfxMatrix& aMatrix);
virtual ~gfxWindowsFont();
virtual const gfxFont::Metrics& GetMetrics();
@ -67,14 +66,17 @@ public:
cairo_scaled_font_t *CairoScaledFont() { return mScaledFont; }
SCRIPT_CACHE *ScriptCache() { return &mScriptCache; }
HFONT GetHFONT() { return mFont; }
void UpdateFonts(cairo_t *cr);
const gfxMatrix& CurrentMatrix() const { return mCTM; }
void UpdateCTM(const gfxMatrix& aMatrix);
protected:
cairo_font_face_t *MakeCairoFontFace();
cairo_scaled_font_t *MakeCairoScaledFont(cairo_t *cr);
cairo_scaled_font_t *MakeCairoScaledFont();
void FillLogFont(PRInt16 weight);
private:
void Init();
void Destroy();
void ComputeMetrics();
HFONT mFont;
@ -88,6 +90,8 @@ private:
LOGFONTW mLogFont;
PRPackedBool mIsMLangFont;
gfxMatrix mCTM;
};

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

@ -234,13 +234,13 @@ void gfxContext::Rotate(gfxFloat angle)
}
void gfxContext::Multiply(const gfxMatrix& matrix)
{
cairo_matrix_t mat = matrix.ToCairoMatrix();
const cairo_matrix_t& mat = matrix.ToCairoMatrix();
cairo_transform(mCairo, &mat);
}
void gfxContext::SetMatrix(const gfxMatrix& matrix)
{
cairo_matrix_t mat = matrix.ToCairoMatrix();
const cairo_matrix_t& mat = matrix.ToCairoMatrix();
cairo_set_matrix(mCairo, &mat);
}
@ -249,7 +249,7 @@ void gfxContext::IdentityMatrix()
cairo_identity_matrix(mCairo);
}
gfxMatrix gfxContext::CurrentMatrix() const
const gfxMatrix& gfxContext::CurrentMatrix() const
{
cairo_matrix_t mat;
cairo_get_matrix(mCairo, &mat);

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

@ -64,28 +64,39 @@ gfxWindowsFont::gfxWindowsFont(const nsAString &aName, const gfxFontGroup *aFont
mGroup = aFontGroup;
mStyle = mGroup->GetStyle();
mFontFace = MakeCairoFontFace();
NS_ASSERTION(mFontFace, "Failed to make font face");
mScaledFont = MakeCairoScaledFont(nsnull);
NS_ASSERTION(mScaledFont, "Failed to make scaled font");
Init();
}
gfxWindowsFont::gfxWindowsFont(HFONT aFont, const gfxFontGroup *aFontGroup, PRBool aIsMLangFont)
: mScriptCache(nsnull), mMetrics(nsnull), mIsMLangFont(aIsMLangFont)
gfxWindowsFont::gfxWindowsFont(HFONT aFont,
const gfxFontGroup *aFontGroup,
PRBool aIsMLangFont,
const gfxMatrix& aMatrix)
: mScriptCache(nsnull), mMetrics(nsnull), mIsMLangFont(aIsMLangFont), mCTM(aMatrix)
{
mFont = aFont;
mGroup = aFontGroup;
mStyle = mGroup->GetStyle();
mFontFace = MakeCairoFontFace();
NS_ASSERTION(mFontFace, "Failed to make font face");
mScaledFont = MakeCairoScaledFont(nsnull);
NS_ASSERTION(mScaledFont, "Failed to make scaled font");
Init();
}
gfxWindowsFont::~gfxWindowsFont()
{
Destroy();
}
void
gfxWindowsFont::Init()
{
mFontFace = MakeCairoFontFace();
NS_ASSERTION(mFontFace, "Failed to make font face");
mScaledFont = MakeCairoScaledFont();
NS_ASSERTION(mScaledFont, "Failed to make scaled font");
}
void
gfxWindowsFont::Destroy()
{
cairo_font_face_destroy(mFontFace);
cairo_scaled_font_destroy(mScaledFont);
@ -107,6 +118,12 @@ gfxWindowsFont::~gfxWindowsFont()
ScriptFreeCache(&mScriptCache);
delete mMetrics;
mFont = nsnull;
mScriptCache = nsnull;
mFontFace = nsnull;
mScaledFont = nsnull;
mMetrics = nsnull;
}
const gfxFont::Metrics&
@ -119,15 +136,16 @@ gfxWindowsFont::GetMetrics()
}
void
gfxWindowsFont::UpdateFonts(cairo_t *cr)
gfxWindowsFont::UpdateCTM(const gfxMatrix& aMatrix)
{
cairo_font_face_destroy(mFontFace);
cairo_scaled_font_destroy(mScaledFont);
mFontFace = MakeCairoFontFace();
NS_ASSERTION(mFontFace, "Failed to make font face");
mScaledFont = MakeCairoScaledFont(nsnull);
NS_ASSERTION(mScaledFont, "Failed to make scaled font");
if (aMatrix.ToCairoMatrix().yy == mCTM.ToCairoMatrix().yy)
return;
Destroy();
mCTM = aMatrix;
Init();
}
cairo_font_face_t *
@ -174,21 +192,16 @@ gfxWindowsFont::MakeCairoFontFace()
}
cairo_scaled_font_t *
gfxWindowsFont::MakeCairoScaledFont(cairo_t *cr)
gfxWindowsFont::MakeCairoScaledFont()
{
cairo_scaled_font_t *font = nsnull;
cairo_matrix_t sizeMatrix, ctm;
if (cr)
cairo_get_matrix(cr, &ctm);
else
cairo_matrix_init_identity(&ctm);
cairo_matrix_t sizeMatrix;
cairo_matrix_init_scale(&sizeMatrix, mStyle->size, mStyle->size);
cairo_font_options_t *fontOptions = cairo_font_options_create();
font = cairo_scaled_font_create(mFontFace, &sizeMatrix, &ctm, fontOptions);
font = cairo_scaled_font_create(mFontFace, &sizeMatrix, &mCTM.ToCairoMatrix(), fontOptions);
cairo_font_options_destroy(fontOptions);
return font;
@ -279,8 +292,10 @@ void
gfxWindowsFont::FillLogFont(PRInt16 currentWeight)
{
#define CLIP_TURNOFF_FONTASSOCIATION 0x40
const double yScale = mCTM.ToCairoMatrix().yy;
mLogFont.lfHeight = -NSToCoordRound(mStyle->size * 32);
mLogFont.lfHeight = -NSToCoordRound(mStyle->size * yScale * 32);
if (mLogFont.lfHeight == 0)
mLogFont.lfHeight = -1;
@ -439,7 +454,7 @@ gfxWindowsTextRun::FindFallbackFont(HDC aDC, const PRUnichar *aString, PRUint32
HFONT retFont;
rv = langFontLink->MapFont(aDC, actualCodePages, aString[0], &retFont);
if (SUCCEEDED(rv))
return new gfxWindowsFont(retFont, mGroup, PR_TRUE);
return new gfxWindowsFont(retFont, mGroup, PR_TRUE, aFont->CurrentMatrix());
}
return nsnull;
@ -486,6 +501,7 @@ gfxWindowsTextRun::MeasureOrDrawFast(gfxContext *aContext,
cairo_t *cr = aContext->GetCairo();
nsRefPtr<gfxWindowsFont> currentFont = mGroup->GetFontAt(0);
currentFont->UpdateCTM(aContext->CurrentMatrix());
cairo_font_face_t *fontFace = currentFont->CairoFontFace();
cairo_scaled_font_t *scaledFont = currentFont->CairoScaledFont();
@ -663,7 +679,7 @@ TRY_AGAIN_HOPE_FOR_THE_BEST:
SaveDC(aDC);
//currentFont->UpdateFonts(cr);
currentFont->UpdateCTM(aContext->CurrentMatrix());
fontFace = currentFont->CairoFontFace();
scaledFont = currentFont->CairoScaledFont();
@ -851,7 +867,7 @@ TRY_AGAIN_JUST_PLACE:
/* Draw using ScriptTextOut() */
SaveDC(aDC);
gfxMatrix m = aContext->CurrentMatrix();
const gfxMatrix& m = aContext->CurrentMatrix();
XFORM xform;
double dm[6];
m.ToValues(&dm[0], &dm[1], &dm[2], &dm[3], &dm[4], &dm[5]);