--- a/gfx/thebes/src/gfxQtFonts.cpp
+++ b/gfx/thebes/src/gfxQtFonts.cpp
@@ -43,18 +43,19 @@
* ***** END LICENSE BLOCK ***** */
#include "gfxPlatformQt.h"
#include "gfxTypes.h"
#include "gfxQtFonts.h"
#include "qdebug.h"
#include "qrect.h"
#include <locale.h>
+#include <cairo.h>
+#include <QFontMetrics>
-#include <cairo.h>
/**
* gfxQtFontGroup
*/
static int
FFRECountHyphens (const nsAString &aFFREName)
{
@@ -106,17 +107,21 @@ GetOrMakeFont(const nsAString& aName, co
}
void
gfxQtFont::RealizeQFont()
{
// already realized?
if (mQFont)
return;
- qDebug("QTFONT NOT_IMPLEMENTED!!!! Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__);
+
+// mQFont = new QFont( "times" );
+ printf( " gfxQtFont::RealizeQFont mQFont %p \n", mQFont );
+
+// qDebug("QTFONT NOT_IMPLEMENTED!!!! Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__);
/*
PangoFontDescription *pangoFontDesc =
NewPangoFontDescription(mName, GetStyle());
PangoContext *pangoCtx = gdk_pango_context_get();
if (!GetStyle()->langGroup.IsEmpty()) {
@@ -469,24 +474,64 @@ gfxQtFont::gfxQtFont(const nsAString &aN
gfxQtFont::~gfxQtFont()
{
}
const gfxFont::Metrics&
gfxQtFont::GetMetrics()
{
- if (mHasMetrics)
+ if (mHasMetrics)
return mMetrics;
- qDebug("QTFONT NOT_IMPLEMENTED!!!! Func:%s::%d, font name: %s %f %f\n", __PRETTY_FUNCTION__, __LINE__, NS_ConvertUTF16toUTF8(mName).get(), GetStyle()->size, mAdjustedSize);
+ QFont font( QString( NS_ConvertUTF16toUTF8(mName).get() ),
+ (int) GetStyle()->size,
+ (int) GetStyle()->weight,
+ bool( GetStyle()->style == FONT_STYLE_ITALIC ) );
+
+ QFontMetrics fontMetrics( font );
+
+ mMetrics.maxAscent = fontMetrics.ascent();
+ mMetrics.maxDescent = fontMetrics.descent();
+ mMetrics.aveCharWidth = fontMetrics.averageCharWidth();
+ mMetrics.underlineOffset = fontMetrics.underlinePos();
+ mMetrics.underlineSize = fontMetrics.lineWidth();
+ mMetrics.strikeoutOffset = fontMetrics.strikeOutPos();
+ mMetrics.strikeoutSize = fontMetrics.lineWidth();
+ mMetrics.maxAdvance = fontMetrics.maxWidth();
+
+ mMetrics.emHeight = mAdjustedSize ? mAdjustedSize : GetStyle()->size;
+ gfxFloat lineHeight = mMetrics.maxAscent + mMetrics.maxDescent;
+ if (lineHeight > mMetrics.emHeight)
+ {
+ mMetrics.externalLeading = lineHeight - mMetrics.emHeight;
+ }
+ else
+ {
+ mMetrics.externalLeading = 0;
+ }
+ mMetrics.internalLeading = 0;
+
+ mMetrics.maxHeight = lineHeight;
+
+ mMetrics.emAscent = lineHeight > 0.0 ?
+ mMetrics.maxAscent * mMetrics.emHeight / lineHeight : 0.0;
+ mMetrics.emDescent = mMetrics.emHeight - mMetrics.emAscent;
+
+ mMetrics.spaceWidth = fontMetrics.width( QChar(' ') );
+ mMetrics.xHeight = fontMetrics.xHeight();
+
+
+ mMetrics.superscriptOffset = mMetrics.xHeight;
+ mMetrics.subscriptOffset = mMetrics.xHeight;
+
+
+
#if 0
- // printf("font name: %s %f %f\n", NS_ConvertUTF16toUTF8(mName).get(), GetStyle()->size, mAdjustedSize);
- // printf ("pango font %s\n", pango_font_description_to_string (pango_font_describe (font)));
fprintf (stderr, "Font: %s\n", NS_ConvertUTF16toUTF8(mName).get());
fprintf (stderr, " emHeight: %f emAscent: %f emDescent: %f\n", mMetrics.emHeight, mMetrics.emAscent, mMetrics.emDescent);
fprintf (stderr, " maxAscent: %f maxDescent: %f\n", mMetrics.maxAscent, mMetrics.maxDescent);
fprintf (stderr, " internalLeading: %f externalLeading: %f\n", mMetrics.externalLeading, mMetrics.internalLeading);
fprintf (stderr, " spaceWidth: %f aveCharWidth: %f xHeight: %f\n", mMetrics.spaceWidth, mMetrics.aveCharWidth, mMetrics.xHeight);
fprintf (stderr, " uOff: %f uSize: %f stOff: %f stSize: %f suOff: %f suSize: %f\n", mMetrics.underlineOffset, mMetrics.underlineSize, mMetrics.strikeoutOffset, mMetrics.strikeoutSize, mMetrics.superscriptOffset, mMetrics.subscriptOffset);
#endif
@@ -508,25 +553,27 @@ gfxQtFont::GetUniqueName()
char *str = pango_font_description_to_string(desc);
pango_font_description_free (desc);
CopyUTF8toUTF16(str, result);
g_free(str);*/
return result;
}
-/* static */ void
-gfxQtFont::Shutdown()
+/* static void
+/*gfxQtFont::Shutdown()
{
qDebug("QTFONT NOT_IMPLEMENTED!!!! Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__);
}
-
+*/
static cairo_scaled_font_t*
CreateScaledFont(cairo_t *aCR, cairo_matrix_t *aCTM, void *aQFont)
{
+printf( "CreateScaledFont\n" );
+
// XXX is this safe really? We should probably check the font type or something.
// XXX does this really create the same font that Pango used for measurement?
// We probably need to work harder here. We should pay particular attention
// to the font options.
/*
PangoFcFont *fcfont = PANGO_FC_FONT(aPangoFont);
cairo_font_face_t *face = cairo_ft_font_face_create_for_pattern(fcfont->font_pattern);
double size;
@@ -550,33 +597,35 @@ CreateScaledFont(cairo_t *aCR, cairo_mat
return scaledFont;
*/
return nsnull;
}
PRBool
gfxQtFont::SetupCairoFont(gfxContext *aContext)
{
+printf("gfxQtFont::SetupCairoFont\n");
+
cairo_t *cr = aContext->GetCairo();
cairo_matrix_t currentCTM;
cairo_get_matrix(cr, ¤tCTM);
if (mCairoFont) {
// Need to validate that its CTM is OK
cairo_matrix_t fontCTM;
cairo_scaled_font_get_ctm(mCairoFont, &fontCTM);
if (fontCTM.xx != currentCTM.xx || fontCTM.yy != currentCTM.yy ||
fontCTM.xy != currentCTM.xy || fontCTM.yx != currentCTM.yx) {
// Just recreate it from scratch, simplest way
cairo_scaled_font_destroy(mCairoFont);
mCairoFont = nsnull;
}
}
if (!mCairoFont) {
- qDebug("QTFONT NOT_IMPLEMENTED!!!! Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__);
+// qDebug("QTFONT NOT_IMPLEMENTED!!!! Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__);
mCairoFont = CreateScaledFont(cr, ¤tCTM, GetQFont());
return PR_FALSE;
}
if (cairo_scaled_font_status(mCairoFont) != CAIRO_STATUS_SUCCESS) {
// Don't cairo_set_scaled_font as that would propagate the error to
// the cairo_t, precluding any further drawing.
return PR_FALSE;
}