зеркало из https://github.com/mozilla/pjs.git
Mostly working impl of font rendering impl with pango. Needs additional code. Not part of the default build.
This commit is contained in:
Родитель
6591b6f4a6
Коммит
36ee7f3e42
|
@ -0,0 +1,85 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/* vim:expandtab:shiftwidth=4:tabstop=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 mozilla.org code.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Christopher Blizzard
|
||||||
|
* <blizzard@mozilla.org>. Portions created by the Initial Developer
|
||||||
|
* are Copyright (C) 2004 the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* 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 "mozilla-decoder.h"
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (MozillaDecoder, mozilla_decoder, MOZILLA_TYPE_DECODER)
|
||||||
|
|
||||||
|
static FcCharSet *mozilla_decoder_get_charset (PangoFcDecoder *decoder,
|
||||||
|
PangoFcFont *fcfont);
|
||||||
|
static PangoGlyph mozilla_decoder_get_glyph (PangoFcDecoder *decoder,
|
||||||
|
PangoFcFont *fcfont,
|
||||||
|
guint32 wc);
|
||||||
|
|
||||||
|
void
|
||||||
|
mozilla_decoder_init (MozillaDecoder *decoder)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mozilla_decoder_class_init (MozillaDecoderClass *klass)
|
||||||
|
{
|
||||||
|
/* GObjectClass *object_class = G_OBJECT_CLASS(klass); */
|
||||||
|
PangoFcDecoderClass *parent_class = PANGO_FC_DECODER_CLASS (klass);
|
||||||
|
|
||||||
|
/* object_class->finalize = test_finalize; */
|
||||||
|
|
||||||
|
parent_class->get_charset = mozilla_decoder_get_charset;
|
||||||
|
parent_class->get_glyph = mozilla_decoder_get_glyph;
|
||||||
|
}
|
||||||
|
|
||||||
|
MozillaDecoder *
|
||||||
|
mozilla_decoder_new(void)
|
||||||
|
{
|
||||||
|
return (MozillaDecoder *)g_object_new (MOZILLA_TYPE_DECODER, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
FcCharSet *
|
||||||
|
mozilla_decoder_get_charset (PangoFcDecoder *decoder,
|
||||||
|
PangoFcFont *fcfont)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
PangoGlyph
|
||||||
|
mozilla_decoder_get_glyph (PangoFcDecoder *decoder,
|
||||||
|
PangoFcFont *fcfont,
|
||||||
|
guint32 wc)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/* vim:expandtab:shiftwidth=4:tabstop=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 mozilla.org code.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Christopher Blizzard
|
||||||
|
* <blizzard@mozilla.org>. Portions created by the Initial Developer
|
||||||
|
* are Copyright (C) 2004 the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* 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 _MOZILLA_DECODER_H
|
||||||
|
#define _MOZILLA_DECODER_H
|
||||||
|
|
||||||
|
#include <pango/pangofc-decoder.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define MOZILLA_TYPE_DECODER (mozilla_decoder_get_type())
|
||||||
|
#define MOZILLA_DECODER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOZILLA_TYPE_DECODER, MozillaDecoder))
|
||||||
|
#define MOZILLA_IS_DECODER(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOZILLA_TYPE_DECODER))
|
||||||
|
|
||||||
|
typedef struct _MozillaDecoder MozillaDecoder;
|
||||||
|
typedef struct _MozillaDecoderClass MozillaDecoderClass;
|
||||||
|
|
||||||
|
#define MOZILLA_DECODER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOZILLA_TYPE_DECODER, MozillaDecoderClass))
|
||||||
|
#define MOZILLA_IS_DECODER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOZILLA_TYPE_DECODER))
|
||||||
|
#define MOZILLA_DECODER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOZILLA_TYPE_DECODER, MozillaDecoderClass))
|
||||||
|
|
||||||
|
struct _MozillaDecoder
|
||||||
|
{
|
||||||
|
PangoFcDecoder parent_instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _MozillaDecoderClass
|
||||||
|
{
|
||||||
|
PangoFcDecoderClass parent_class;
|
||||||
|
};
|
||||||
|
|
||||||
|
GType mozilla_decoder_get_type (void);
|
||||||
|
MozillaDecoder *mozilla_decoder_new (void);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /*_MOZILLA_DECODER_H */
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,266 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/* vim:expandtab:shiftwidth=4:tabstop=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 mozilla.org code.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code Christopher Blizzard
|
||||||
|
* <blizzard@mozilla.org>. Portions created by the Initial Developer
|
||||||
|
* are Copyright (C) 2002 the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* 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 "nsIFontMetrics.h"
|
||||||
|
#include "nsIFontEnumerator.h"
|
||||||
|
#include "nsCRT.h"
|
||||||
|
#include "nsIAtom.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsVoidArray.h"
|
||||||
|
#include "nsIFontMetricsGTK.h"
|
||||||
|
|
||||||
|
#include <pango/pango.h>
|
||||||
|
|
||||||
|
class nsFontMetricsPango : public nsIFontMetricsGTK
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
nsFontMetricsPango();
|
||||||
|
virtual ~nsFontMetricsPango();
|
||||||
|
|
||||||
|
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
|
||||||
|
|
||||||
|
// nsISupports
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
// nsIFontMetrics
|
||||||
|
NS_IMETHOD Init (const nsFont& aFont, nsIAtom* aLangGroup,
|
||||||
|
nsIDeviceContext *aContext);
|
||||||
|
NS_IMETHOD Destroy();
|
||||||
|
NS_IMETHOD GetFont (const nsFont *&aFont);
|
||||||
|
NS_IMETHOD GetLangGroup (nsIAtom** aLangGroup);
|
||||||
|
NS_IMETHOD GetFontHandle (nsFontHandle &aHandle);
|
||||||
|
|
||||||
|
NS_IMETHOD GetXHeight (nscoord& aResult)
|
||||||
|
{ aResult = mXHeight; return NS_OK; };
|
||||||
|
|
||||||
|
NS_IMETHOD GetSuperscriptOffset (nscoord& aResult)
|
||||||
|
{ aResult = mSuperscriptOffset;
|
||||||
|
return NS_OK; };
|
||||||
|
|
||||||
|
NS_IMETHOD GetSubscriptOffset (nscoord& aResult)
|
||||||
|
{ aResult = mSubscriptOffset;
|
||||||
|
return NS_OK; };
|
||||||
|
|
||||||
|
NS_IMETHOD GetStrikeout (nscoord& aOffset, nscoord& aSize)
|
||||||
|
{ aOffset = mStrikeoutOffset;
|
||||||
|
aSize = mStrikeoutSize;
|
||||||
|
return NS_OK; };
|
||||||
|
|
||||||
|
NS_IMETHOD GetUnderline (nscoord& aOffset, nscoord& aSize)
|
||||||
|
{ aOffset = mUnderlineOffset;
|
||||||
|
aSize = mUnderlineSize;
|
||||||
|
return NS_OK; };
|
||||||
|
|
||||||
|
NS_IMETHOD GetHeight (nscoord &aHeight)
|
||||||
|
{ aHeight = mMaxHeight;
|
||||||
|
return NS_OK; };
|
||||||
|
|
||||||
|
NS_IMETHOD GetNormalLineHeight (nscoord &aHeight)
|
||||||
|
{ aHeight = mEmHeight + mLeading;
|
||||||
|
return NS_OK; };
|
||||||
|
|
||||||
|
NS_IMETHOD GetLeading (nscoord &aLeading)
|
||||||
|
{ aLeading = mLeading;
|
||||||
|
return NS_OK; };
|
||||||
|
|
||||||
|
NS_IMETHOD GetEmHeight (nscoord &aHeight)
|
||||||
|
{ aHeight = mEmHeight;
|
||||||
|
return NS_OK; };
|
||||||
|
|
||||||
|
NS_IMETHOD GetEmAscent (nscoord &aAscent)
|
||||||
|
{ aAscent = mEmAscent;
|
||||||
|
return NS_OK; };
|
||||||
|
|
||||||
|
NS_IMETHOD GetEmDescent (nscoord &aDescent)
|
||||||
|
{ aDescent = mEmDescent;
|
||||||
|
return NS_OK; };
|
||||||
|
|
||||||
|
NS_IMETHOD GetMaxHeight (nscoord &aHeight)
|
||||||
|
{ aHeight = mMaxHeight;
|
||||||
|
return NS_OK; };
|
||||||
|
|
||||||
|
NS_IMETHOD GetMaxAscent (nscoord &aAscent)
|
||||||
|
{ aAscent = mMaxAscent;
|
||||||
|
return NS_OK; };
|
||||||
|
|
||||||
|
NS_IMETHOD GetMaxDescent (nscoord &aDescent)
|
||||||
|
{ aDescent = mMaxDescent;
|
||||||
|
return NS_OK; };
|
||||||
|
|
||||||
|
NS_IMETHOD GetMaxAdvance (nscoord &aAdvance)
|
||||||
|
{ aAdvance = mMaxAdvance;
|
||||||
|
return NS_OK; };
|
||||||
|
|
||||||
|
NS_IMETHOD GetSpaceWidth (nscoord &aSpaceCharWidth)
|
||||||
|
{ aSpaceCharWidth = mSpaceWidth;
|
||||||
|
return NS_OK; };
|
||||||
|
|
||||||
|
NS_IMETHOD GetAveCharWidth (nscoord &aAveCharWidth)
|
||||||
|
{ aAveCharWidth = mAveCharWidth;
|
||||||
|
return NS_OK; };
|
||||||
|
|
||||||
|
// nsIFontMetricsGTK (calls from the font rendering layer)
|
||||||
|
virtual nsresult GetWidth(const char* aString, PRUint32 aLength,
|
||||||
|
nscoord& aWidth,
|
||||||
|
nsRenderingContextGTK *aContext);
|
||||||
|
virtual nsresult GetWidth(const PRUnichar* aString, PRUint32 aLength,
|
||||||
|
nscoord& aWidth, PRInt32 *aFontID,
|
||||||
|
nsRenderingContextGTK *aContext);
|
||||||
|
|
||||||
|
virtual nsresult GetTextDimensions(const PRUnichar* aString,
|
||||||
|
PRUint32 aLength,
|
||||||
|
nsTextDimensions& aDimensions,
|
||||||
|
PRInt32* aFontID,
|
||||||
|
nsRenderingContextGTK *aContext);
|
||||||
|
virtual nsresult GetTextDimensions(const char* aString,
|
||||||
|
PRInt32 aLength,
|
||||||
|
PRInt32 aAvailWidth,
|
||||||
|
PRInt32* aBreaks,
|
||||||
|
PRInt32 aNumBreaks,
|
||||||
|
nsTextDimensions& aDimensions,
|
||||||
|
PRInt32& aNumCharsFit,
|
||||||
|
nsTextDimensions& aLastWordDimensions,
|
||||||
|
PRInt32* aFontID,
|
||||||
|
nsRenderingContextGTK *aContext);
|
||||||
|
virtual nsresult GetTextDimensions(const PRUnichar* aString,
|
||||||
|
PRInt32 aLength,
|
||||||
|
PRInt32 aAvailWidth,
|
||||||
|
PRInt32* aBreaks,
|
||||||
|
PRInt32 aNumBreaks,
|
||||||
|
nsTextDimensions& aDimensions,
|
||||||
|
PRInt32& aNumCharsFit,
|
||||||
|
nsTextDimensions& aLastWordDimensions,
|
||||||
|
PRInt32* aFontID,
|
||||||
|
nsRenderingContextGTK *aContext);
|
||||||
|
|
||||||
|
virtual nsresult DrawString(const char *aString, PRUint32 aLength,
|
||||||
|
nscoord aX, nscoord aY,
|
||||||
|
const nscoord* aSpacing,
|
||||||
|
nsRenderingContextGTK *aContext,
|
||||||
|
nsDrawingSurfaceGTK *aSurface);
|
||||||
|
virtual nsresult DrawString(const PRUnichar* aString, PRUint32 aLength,
|
||||||
|
nscoord aX, nscoord aY,
|
||||||
|
PRInt32 aFontID,
|
||||||
|
const nscoord* aSpacing,
|
||||||
|
nsRenderingContextGTK *aContext,
|
||||||
|
nsDrawingSurfaceGTK *aSurface);
|
||||||
|
|
||||||
|
#ifdef MOZ_MATHML
|
||||||
|
virtual nsresult GetBoundingMetrics(const char *aString, PRUint32 aLength,
|
||||||
|
nsBoundingMetrics &aBoundingMetrics,
|
||||||
|
nsRenderingContextGTK *aContext);
|
||||||
|
virtual nsresult GetBoundingMetrics(const PRUnichar *aString,
|
||||||
|
PRUint32 aLength,
|
||||||
|
nsBoundingMetrics &aBoundingMetrics,
|
||||||
|
PRInt32 *aFontID,
|
||||||
|
nsRenderingContextGTK *aContext);
|
||||||
|
#endif /* MOZ_MATHML */
|
||||||
|
|
||||||
|
virtual GdkFont* GetCurrentGDKFont(void);
|
||||||
|
|
||||||
|
virtual nsresult SetRightToLeftText(PRBool aIsRTL);
|
||||||
|
|
||||||
|
// get hints for the font
|
||||||
|
static PRUint32 GetHints (void);
|
||||||
|
|
||||||
|
// drawing surface methods
|
||||||
|
static nsresult FamilyExists (nsIDeviceContext *aDevice,
|
||||||
|
const nsString &aName);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// generic font metrics class bits
|
||||||
|
nsCStringArray mFontList;
|
||||||
|
nsAutoVoidArray mFontIsGeneric;
|
||||||
|
|
||||||
|
nsIDeviceContext *mDeviceContext;
|
||||||
|
nsCOMPtr<nsIAtom> mLangGroup;
|
||||||
|
nsCString *mGenericFont;
|
||||||
|
nsFont *mFont;
|
||||||
|
float mPixelSize;
|
||||||
|
|
||||||
|
nsCAutoString mDefaultFont;
|
||||||
|
|
||||||
|
// Pango-related items
|
||||||
|
PangoFontDescription *mPangoFontDesc;
|
||||||
|
PangoContext *mPangoContext;
|
||||||
|
PangoContext *mLTRPangoContext;
|
||||||
|
PangoContext *mRTLPangoContext;
|
||||||
|
PangoAttrList *mPangoAttrList;
|
||||||
|
PRBool mIsRTL;
|
||||||
|
|
||||||
|
// Cached font metrics
|
||||||
|
nscoord mXHeight;
|
||||||
|
nscoord mSuperscriptOffset;
|
||||||
|
nscoord mSubscriptOffset;
|
||||||
|
nscoord mStrikeoutOffset;
|
||||||
|
nscoord mStrikeoutSize;
|
||||||
|
nscoord mUnderlineOffset;
|
||||||
|
nscoord mUnderlineSize;
|
||||||
|
nscoord mMaxHeight;
|
||||||
|
nscoord mLeading;
|
||||||
|
nscoord mEmHeight;
|
||||||
|
nscoord mEmAscent;
|
||||||
|
nscoord mEmDescent;
|
||||||
|
nscoord mMaxAscent;
|
||||||
|
nscoord mMaxDescent;
|
||||||
|
nscoord mMaxAdvance;
|
||||||
|
nscoord mSpaceWidth;
|
||||||
|
nscoord mAveCharWidth;
|
||||||
|
|
||||||
|
// Private methods
|
||||||
|
nsresult RealizeFont(void);
|
||||||
|
nsresult CacheFontMetrics(void);
|
||||||
|
|
||||||
|
static PRBool EnumFontCallback(const nsString &aFamily,
|
||||||
|
PRBool aIsGeneric, void *aData);
|
||||||
|
|
||||||
|
void DrawStringSlowly(const gchar *aText, PRUint32 aLength,
|
||||||
|
GdkDrawable *aDrawable,
|
||||||
|
GdkGC *aGC, gint aX, gint aY,
|
||||||
|
PangoLayoutLine *aLine,
|
||||||
|
const nscoord *aSpacing);
|
||||||
|
};
|
||||||
|
|
||||||
|
class nsFontEnumeratorPango : public nsIFontEnumerator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
nsFontEnumeratorPango();
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
NS_DECL_NSIFONTENUMERATOR
|
||||||
|
};
|
Загрузка…
Ссылка в новой задаче