Fixed gfxQtFont according to changes in bug 437356 Set up unified font entry object

Added empty gfxQtNativeRenderer and fixed nsObjectFrame for MOZ_WIDGET_QT
This commit is contained in:
Oleg Romashin 2008-08-09 16:43:08 +03:00
parent 75fc2387ae
commit 1afed1eab7
10 changed files with 343 additions and 39 deletions

View File

@ -78,7 +78,7 @@ endif
ifeq ($(MOZ_WIDGET_TOOLKIT),qt)
EXPORTS += gfxQtPlatform.h gfxQPainterSurface.h
EXPORTS += gfxXlibSurface.h gfxXlibNativeRenderer.h
EXPORTS += gfxXlibSurface.h gfxQtNativeRenderer.h
EXPORTS += gfxQtFonts.h
ifdef MOZ_ENABLE_GLITZ
REQUIRES += glitzglx

View File

@ -53,29 +53,29 @@ typedef struct FT_FaceRec_* FT_Face;
* and character map info.
*/
class FontEntry;
class FontFamily
class FontFamily : public gfxFontFamily
{
public:
THEBES_INLINE_DECL_REFCOUNTING(FontFamily)
FontFamily(const nsAString& aName) :
mName(aName) { }
gfxFontFamily(aName) { }
FontEntry *FindFontEntry(const gfxFontStyle& aFontStyle);
public:
nsTArray<nsRefPtr<FontEntry> > mFaces;
nsString mName;
};
class FontEntry
class FontEntry : public gfxFontEntry
{
public:
THEBES_INLINE_DECL_REFCOUNTING(FontEntry)
FontEntry(const nsString& aFaceName) :
mFontFace(nsnull), mFaceName(aFaceName), mFTFontIndex(0), mUnicodeFont(PR_FALSE), mSymbolFont(PR_FALSE)
{ }
FontEntry(const nsAString& aFaceName) :
gfxFontEntry(aFaceName)
{
mFontFace = nsnull;
mFTFontIndex = 0;
mUnicodeFont = PR_FALSE;
mSymbolFont = PR_FALSE;
}
FontEntry(const FontEntry& aFontEntry);
~FontEntry();
@ -92,14 +92,8 @@ public:
nsCString mFilename;
PRUint8 mFTFontIndex;
PRPackedBool mUnicodeFont : 1;
PRPackedBool mSymbolFont : 1;
PRPackedBool mTrueType : 1;
PRPackedBool mIsType1 : 1;
PRPackedBool mItalic : 1;
PRUint16 mWeight;
gfxSparseBitSet mCharacterMap;
};
@ -119,7 +113,7 @@ public: // new functions
virtual nsString GetUniqueName();
virtual PRUint32 GetSpaceGlyph();
FontEntry *GetFontEntry() { return mFontEntry; }
FontEntry *GetFontEntry();
private:
cairo_scaled_font_t *mScaledFont;
@ -129,7 +123,6 @@ private:
Metrics mMetrics;
gfxFloat mAdjustedSize;
nsRefPtr<FontEntry> mFontEntry;
};
class THEBES_API gfxQtFontGroup : public gfxFontGroup {

View File

@ -0,0 +1,112 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Novell code.
*
* The Initial Developer of the Original Code is Novell.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* rocallahan@novell.com
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef GFXQTNATIVERENDER_H_
#define GFXQTNATIVERENDER_H_
#include "gfxColor.h"
class gfxASurface;
class gfxContext;
class QWidget;
class QRect;
/**
* This class lets us take code that draws into an Qt drawable and lets us
* use it to draw into any Thebes context. The user should subclass this class,
* override NativeDraw, and then call Draw(). The drawing will be subjected
* to all Thebes transformations, clipping etc.
*/
class THEBES_API gfxQtNativeRenderer {
public:
/**
* Perform the native drawing.
* @param offsetX draw at this offset into the given drawable
* @param offsetY draw at this offset into the given drawable
* @param clipRects an array of rects; clip to the union
* @param numClipRects the number of rects in the array, or zero if
* no clipping is required
*/
virtual nsresult NativeDraw(QWidget * drawable, short offsetX,
short offsetY, QRect * clipRects, PRUint32 numClipRects) = 0;
enum {
// If set, then Draw() is opaque, i.e., every pixel in the intersection
// of the clipRect and (offset.x,offset.y,bounds.width,bounds.height)
// will be set and there is no dependence on what the existing pixels
// in the drawable are set to.
DRAW_IS_OPAQUE = 0x01,
// If set, then offset may be non-zero; if not set, then Draw() can
// only be called with offset==(0,0)
DRAW_SUPPORTS_OFFSET = 0x02,
// If set, then numClipRects can be zero or one
DRAW_SUPPORTS_CLIP_RECT = 0x04,
// If set, then numClipRects can be any value. If neither this
// nor CLIP_RECT are set, then numClipRects will be zero
DRAW_SUPPORTS_CLIP_LIST = 0x08,
// If set, then the visual passed in can be any visual, otherwise the
// visual passed in must be the default visual for dpy's default screen
DRAW_SUPPORTS_NONDEFAULT_VISUAL = 0x10,
// If set, then the Screen 'screen' in the callback can be different
// from the default Screen of the display passed to 'Draw' and can be
// on a different display.
DRAW_SUPPORTS_ALTERNATE_SCREEN = 0x20
};
struct DrawOutput {
nsRefPtr<gfxASurface> mSurface;
PRPackedBool mUniformAlpha;
PRPackedBool mUniformColor;
gfxRGBA mColor;
};
/**
* @param flags see above
* @param bounds Draw()'s drawing is guaranteed to be restricted to
* the rectangle (offset.x,offset.y,bounds.width,bounds.height)
* @param dpy a display to use for the drawing if ctx doesn't have one
* @param resultSurface if non-null, we will try to capture a copy of the
* rendered image into a surface similar to the surface of ctx; if
* successful, a pointer to the new gfxASurface is stored in *resultSurface,
* otherwise *resultSurface is set to nsnull.
*/
nsresult Draw(gfxContext* ctx, int width, int height,
PRUint32 flags, DrawOutput* output);
};
#endif /*GFXQTNATIVERENDER_H_*/

View File

@ -113,11 +113,11 @@ endif
ifeq ($(MOZ_WIDGET_TOOLKIT),qt)
CPPSRCS += gfxQtPlatform.cpp gfxQPainterSurface.cpp
CPPSRCS += gfxXlibSurface.cpp gfxXlibNativeRenderer.cpp
CPPSRCS += gfxXlibSurface.cpp gfxQtNativeRenderer.cpp
CPPSRCS += gfxQtFonts.cpp
CPPSRCS += gfxFontconfigUtils.cpp
CPPSRCS += nsUnicodeRange.cpp
CSRCS = cairo-xlib-utils.c
#CSRCS = cairo-xlib-utils.c
EXTRA_DSO_LDOPTS += $(ZLIB_LIBS) $(MOZ_XFT_LIBS) $(XLDFLAGS) $(XLIBS) $(CAIRO_FT_LIBS)
endif

View File

@ -49,12 +49,7 @@
*/
FontEntry::FontEntry(const FontEntry& aFontEntry) :
mFaceName(aFontEntry.mFaceName),
mUnicodeFont(aFontEntry.mUnicodeFont),
mSymbolFont(aFontEntry.mSymbolFont),
mItalic(aFontEntry.mItalic),
mWeight(aFontEntry.mWeight),
mCharacterMap(aFontEntry.mCharacterMap)
gfxFontEntry(aFontEntry)
{
if (aFontEntry.mFontFace)
mFontFace = cairo_font_face_reference(aFontEntry.mFontFace);
@ -707,14 +702,15 @@ gfxQtFontGroup::AddRange(gfxTextRun *aTextRun, gfxQtFont *font, const PRUnichar
*/
gfxQtFont::gfxQtFont(FontEntry *aFontEntry,
const gfxFontStyle *aFontStyle)
: gfxFont(aFontEntry->GetName(), aFontStyle),
: gfxFont(aFontEntry, aFontStyle),
mScaledFont(nsnull),
mHasSpaceGlyph(PR_FALSE),
mSpaceGlyph(0),
mHasMetrics(PR_FALSE),
mAdjustedSize(0),
mFontEntry(aFontEntry)
mAdjustedSize(0)
{
mFontEntry = aFontEntry;
NS_ASSERTION(mFontEntry, "Unable to find font entry for font. Something is whack.");
}
gfxQtFont::~gfxQtFont()
@ -866,7 +862,7 @@ gfxQtFont::GetMetrics()
nsString
gfxQtFont::GetUniqueName()
{
return mName;
return GetFontEntry()->Name();
}
PRUint32
@ -888,13 +884,19 @@ gfxQtFont::GetSpaceGlyph()
return mSpaceGlyph;
}
FontEntry*
gfxQtFont::GetFontEntry()
{
return static_cast<FontEntry*> (mFontEntry.get());
}
cairo_font_face_t *
gfxQtFont::CairoFontFace()
{
// XXX we need to handle fake bold here (or by having a sepaerate font entry)
if (mStyle.weight >= 600 && mFontEntry->mWeight < 600)
if (mStyle.weight >= 600 && GetFontEntry()->mWeight < 600)
printf("** We want fake weight\n");
return mFontEntry->CairoFontFace();
return GetFontEntry()->CairoFontFace();
}
cairo_scaled_font_t *
@ -909,7 +911,7 @@ gfxQtFont::CairoScaledFont()
cairo_matrix_init_identity(&identityMatrix);
// synthetic oblique by skewing via the font matrix
PRBool needsOblique = (!mFontEntry->mItalic && (mStyle.style & (FONT_STYLE_ITALIC | FONT_STYLE_OBLIQUE)));
PRBool needsOblique = (!GetFontEntry()->mItalic && (mStyle.style & (FONT_STYLE_ITALIC | FONT_STYLE_OBLIQUE)));
if (needsOblique) {
const double kSkewFactor = 0.25;

View File

@ -0,0 +1,135 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Novell code.
*
* The Initial Developer of the Original Code is Novell.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* romaxa@gmail.com
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "gfxQtNativeRenderer.h"
#include "gfxContext.h"
#include "gfxQtPlatform.h"
#include "cairo.h"
#include <QWidget>
typedef struct {
gfxQtNativeRenderer* mRenderer;
nsresult mRV;
} NativeRenderingClosure;
static cairo_bool_t
NativeRendering(void *closure,
QWidget * drawable,
short offset_x, short offset_y,
QRect * rectangles, unsigned int num_rects)
{
NativeRenderingClosure* cl = (NativeRenderingClosure*)closure;
nsresult rv = cl->mRenderer->
NativeDraw(drawable, offset_x, offset_y,
rectangles, num_rects);
cl->mRV = rv;
return NS_SUCCEEDED(rv);
}
nsresult
gfxQtNativeRenderer::Draw(gfxContext* ctx, int width, int height,
PRUint32 flags, DrawOutput* output)
{
NativeRenderingClosure closure = { this, NS_OK };
if (output) {
output->mSurface = NULL;
output->mUniformAlpha = PR_FALSE;
output->mUniformColor = PR_FALSE;
}
#if 0 // FIXME
cairo_gdk_drawing_result_t result;
// Make sure result.surface is null to start with; we rely on it
// being non-null meaning that a surface actually got allocated.
result.surface = NULL;
int cairoFlags = 0;
if (flags & DRAW_SUPPORTS_OFFSET) {
cairoFlags |= CAIRO_GDK_DRAWING_SUPPORTS_OFFSET;
}
if (flags & DRAW_SUPPORTS_CLIP_RECT) {
cairoFlags |= CAIRO_GDK_DRAWING_SUPPORTS_CLIP_RECT;
}
if (flags & DRAW_SUPPORTS_CLIP_LIST) {
cairoFlags |= CAIRO_GDK_DRAWING_SUPPORTS_CLIP_LIST;
}
if (flags & DRAW_SUPPORTS_ALTERNATE_SCREEN) {
cairoFlags |= CAIRO_GDK_DRAWING_SUPPORTS_ALTERNATE_SCREEN;
}
if (flags & DRAW_SUPPORTS_NONDEFAULT_VISUAL) {
cairoFlags |= CAIRO_GDK_DRAWING_SUPPORTS_NONDEFAULT_VISUAL;
}
cairo_draw_with_gdk(ctx->GetCairo(),
gfxPlatformGtk::GetPlatform()->GetGdkDrawable(ctx->OriginalSurface()),
NativeRendering,
&closure, width, height,
(flags & DRAW_IS_OPAQUE) ? CAIRO_GDK_DRAWING_OPAQUE : CAIRO_GDK_DRAWING_TRANSPARENT,
(cairo_gdk_drawing_support_t)cairoFlags,
output ? &result : NULL);
if (NS_FAILED(closure.mRV)) {
if (result.surface) {
NS_ASSERTION(output, "How did that happen?");
cairo_surface_destroy (result.surface);
}
return closure.mRV;
}
if (output) {
if (result.surface) {
output->mSurface = gfxASurface::Wrap(result.surface);
if (!output->mSurface) {
cairo_surface_destroy (result.surface);
return NS_ERROR_OUT_OF_MEMORY;
}
}
output->mUniformAlpha = result.uniform_alpha;
output->mUniformColor = result.uniform_color;
output->mColor = gfxRGBA(result.r, result.g, result.b, result.alpha);
}
#endif
return NS_OK;
}

View File

@ -170,7 +170,7 @@ gfxQtPlatform::UpdateFontList()
gPlatformFonts->Put(key, ff);
}
nsRefPtr<FontEntry> fe = new FontEntry(ff->mName);
nsRefPtr<FontEntry> fe = new FontEntry(ff->Name());
ff->mFaces.AppendElement(fe);
if (FcPatternGetString(fs->fonts[i], FC_FILE, 0, (FcChar8 **) &str) == FcResultMatch) {
@ -262,7 +262,7 @@ gfxQtPlatform::ResolveFontName(const nsAString& aFontName,
nsRefPtr<FontFamily> ff;
if (gPlatformFonts->Get(name, &ff) ||
gPlatformFontAliases->Get(name, &ff)) {
aAborted = !(*aCallback)(ff->mName, aClosure);
aAborted = !(*aCallback)(ff->Name(), aClosure);
return NS_OK;
}

View File

@ -241,6 +241,11 @@ EXTRA_DSO_LDOPTS += $(MOZ_GTK2_LIBS) \
$(NULL)
endif
ifdef MOZ_ENABLE_QT
EXTRA_DSO_LDOPTS += $(MOZ_QT_LIBS) \
$(NULL)
endif
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
EXTRA_DSO_LDOPTS += \
$(TK_LIBS) \

View File

@ -201,6 +201,10 @@ ifdef MOZ_ENABLE_GTK2
CXXFLAGS += $(MOZ_GTK2_CFLAGS)
endif
ifdef MOZ_ENABLE_QT
CXXFLAGS += $(MOZ_QT_CFLAGS)
endif
libs::
$(INSTALL) $(RESOURCES_HTML) $(DIST)/bin/res/html
$(INSTALL) $(RESOURCES) $(DIST)/bin/res

View File

@ -54,6 +54,12 @@
#include "nsIView.h"
#include "nsIViewManager.h"
#include "nsIDOMKeyListener.h"
#ifdef MOZ_X11
#ifdef MOZ_WIDGET_QT
#include <QWidget>
#include <QX11Info>
#endif
#endif
#include "nsIPluginHost.h"
#include "nsplugin.h"
#include "nsString.h"
@ -169,6 +175,10 @@ enum { XKeyPress = KeyPress };
#include "gfxGdkNativeRenderer.h"
#endif
#ifdef MOZ_WIDGET_QT
#include "gfxQtNativeRenderer.h"
#endif
#ifdef XP_WIN
#include <wtypes.h>
#include <winuser.h>
@ -480,7 +490,7 @@ private:
nsresult EnsureCachedAttrParamArrays();
#ifdef MOZ_WIDGET_GTK2
#if defined(MOZ_WIDGET_GTK2)
class Renderer : public gfxGdkNativeRenderer {
public:
Renderer(nsPluginWindow* aWindow, nsIPluginInstance* aInstance,
@ -496,6 +506,22 @@ private:
const nsIntSize& mPluginSize;
const nsIntRect& mDirtyRect;
};
#elif defined(MOZ_WIDGET_QT)
class Renderer : public gfxQtNativeRenderer {
public:
Renderer(nsPluginWindow* aWindow, nsIPluginInstance* aInstance,
const nsIntSize& aPluginSize, const nsIntRect& aDirtyRect)
: mWindow(aWindow), mInstance(aInstance),
mPluginSize(aPluginSize), mDirtyRect(aDirtyRect)
{}
virtual nsresult NativeDraw(QWidget * drawable, short offsetX,
short offsetY, QRect * clipRects, PRUint32 numClipRects);
private:
nsPluginWindow* mWindow;
nsIPluginInstance* mInstance;
const nsIntSize& mPluginSize;
const nsIntRect& mDirtyRect;
};
#endif
};
@ -4129,6 +4155,7 @@ DepthOfVisual(const Screen* screen, const Visual* visual)
}
#endif
#if defined(MOZ_WIDGET_GTK2)
nsresult
nsPluginInstanceOwner::Renderer::NativeDraw(GdkDrawable * drawable,
short offsetX, short offsetY,
@ -4140,6 +4167,20 @@ nsPluginInstanceOwner::Renderer::NativeDraw(GdkDrawable * drawable,
Visual * visual = GDK_VISUAL_XVISUAL(gdk_drawable_get_visual(drawable));
Colormap colormap = GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(drawable));
Screen * screen = GDK_SCREEN_XSCREEN (gdk_drawable_get_screen(drawable));
#endif
#elif defined(MOZ_WIDGET_QT)
nsresult
nsPluginInstanceOwner::Renderer::NativeDraw(QWidget * drawable,
short offsetX, short offsetY,
QRect * clipRects,
PRUint32 numClipRects)
{
#ifdef MOZ_X11
QX11Info xinfo = drawable->x11Info();
Visual * visual = (Visual*) xinfo.visual();
Colormap colormap = xinfo.colormap();
Screen * screen = (Screen*) xinfo.screen();
#endif
#endif
// See if the plugin must be notified of new window parameters.
PRBool doupdatewindow = PR_FALSE;
@ -4160,10 +4201,17 @@ nsPluginInstanceOwner::Renderer::NativeDraw(GdkDrawable * drawable,
NS_ASSERTION(numClipRects <= 1, "We don't support multiple clip rectangles!");
nsIntRect clipRect;
if (numClipRects) {
#if defined(MOZ_WIDGET_GTK2)
clipRect.x = clipRects[0].x;
clipRect.y = clipRects[0].y;
clipRect.width = clipRects[0].width;
clipRect.height = clipRects[0].height;
#elif defined(MOZ_WIDGET_QT)
clipRect.x = clipRects[0].x();
clipRect.y = clipRects[0].y();
clipRect.width = clipRects[0].width();
clipRect.height = clipRects[0].height();
#endif
}
else {
// nsPluginRect members are unsigned, but
@ -4216,7 +4264,12 @@ nsPluginInstanceOwner::Renderer::NativeDraw(GdkDrawable * drawable,
// set the drawing info
exposeEvent.type = GraphicsExpose;
exposeEvent.display = DisplayOfScreen(screen);
exposeEvent.drawable = GDK_DRAWABLE_XID(drawable);
exposeEvent.drawable =
#if defined(MOZ_WIDGET_GTK2)
GDK_DRAWABLE_XID(drawable);
#elif defined(MOZ_WIDGET_QT)
drawable->x11PictureHandle();
#endif
exposeEvent.x = mDirtyRect.x + offsetX;
exposeEvent.y = mDirtyRect.y + offsetY;
exposeEvent.width = mDirtyRect.width;