mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-31 22:25:30 +00:00
Added new postscript fontmetric code, and update the Device and Rendering context to use them
This commit is contained in:
parent
cabf7ef087
commit
91a37ba797
@ -19,6 +19,7 @@
|
||||
#include "nsDeviceContextPS.h"
|
||||
#include "nsRenderingContextPS.h"
|
||||
#include "nsString.h"
|
||||
#include "nsFontMetricsPS.h"
|
||||
|
||||
#include "prprf.h"
|
||||
#include "nsPSUtil.h"
|
||||
@ -27,6 +28,8 @@
|
||||
|
||||
static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID);
|
||||
|
||||
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
@ -46,6 +49,16 @@ nsDeviceContextPS :: nsDeviceContextPS()
|
||||
*/
|
||||
nsDeviceContextPS :: ~nsDeviceContextPS()
|
||||
{
|
||||
PRInt32 i, n;
|
||||
|
||||
// get rid of the fonts in our mFontMetrics cache
|
||||
n= mFontMetrics.Count();
|
||||
for (i = 0; i < n; i++){
|
||||
nsIFontMetrics* fm = (nsIFontMetrics*) mFontMetrics.ElementAt(i);
|
||||
fm->Destroy();
|
||||
NS_RELEASE(fm);
|
||||
}
|
||||
mFontMetrics.Clear();
|
||||
}
|
||||
|
||||
NS_IMPL_QUERY_INTERFACE(nsDeviceContextPS, kDeviceContextIID)
|
||||
@ -56,10 +69,28 @@ NS_IMPL_RELEASE(nsDeviceContextPS)
|
||||
* See documentation in nsDeviceContextPS.h
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS :: Init(nsIDeviceContext *aCreatingDeviceContext)
|
||||
NS_IMETHODIMP nsDeviceContextPS :: Init(nsIDeviceContext *aCreatingDeviceContext,nsIDeviceContext *aPrinterContext, HDC aTheDC)
|
||||
{
|
||||
float origscale, newscale;
|
||||
float t2d, a2d;
|
||||
|
||||
mDepth = 1;
|
||||
mDelContext = aCreatingDeviceContext;
|
||||
|
||||
mDC = aTheDC;
|
||||
|
||||
mTwipsToPixels = (float)72.0/(float)NSIntPointsToTwips(72);
|
||||
mPixelsToTwips = 1.0f / mTwipsToPixels;
|
||||
|
||||
GetTwipsToDevUnits(newscale);
|
||||
aPrinterContext->GetTwipsToDevUnits(origscale);
|
||||
mPixelScale = newscale / origscale;
|
||||
|
||||
aPrinterContext->GetTwipsToDevUnits(t2d);
|
||||
aPrinterContext->GetAppUnitsToDevUnits(a2d);
|
||||
|
||||
mAppUnitsToDevUnits = (a2d / t2d) * mTwipsToPixels;
|
||||
mDevUnitsToAppUnits = 1.0f / mAppUnitsToDevUnits;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -105,9 +136,8 @@ nsresult rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_IMETHODIMP nsDeviceContextPS :: SupportsNativeWidgets(PRBool &aSupportsWidgets)
|
||||
{
|
||||
|
||||
return (mDelContext->SupportsNativeWidgets(aSupportsWidgets));
|
||||
//aSupportsWidgets = PR_FALSE;
|
||||
//return NS_OK;
|
||||
aSupportsWidgets = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
@ -117,12 +147,12 @@ NS_IMETHODIMP nsDeviceContextPS :: SupportsNativeWidgets(PRBool &aSupportsWidget
|
||||
NS_IMETHODIMP nsDeviceContextPS :: GetScrollBarDimensions(float &aWidth, float &aHeight) const
|
||||
{
|
||||
|
||||
return (mDelContext->GetScrollBarDimensions(aWidth, aHeight));
|
||||
aWidth = ::GetSystemMetrics(SM_CXVSCROLL) * mDevUnitsToAppUnits;
|
||||
aHeight = ::GetSystemMetrics(SM_CXHSCROLL) * mDevUnitsToAppUnits;
|
||||
aWidth = 0;
|
||||
aHeight = 0;
|
||||
return NS_OK;
|
||||
|
||||
// XXX Should we push this to widget library
|
||||
//aWidth = 320.0;
|
||||
//aHeight = 320.0;
|
||||
//return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
@ -133,8 +163,6 @@ NS_IMETHODIMP nsDeviceContextPS :: GetDrawingSurface(nsIRenderingContext &aConte
|
||||
{
|
||||
|
||||
return(mDelContext->GetDrawingSurface(aContext,aSurface));
|
||||
//aContext.CreateDrawingSurface(nsnull, 0, aSurface);
|
||||
//return nsnull == aSurface ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
@ -143,10 +171,8 @@ NS_IMETHODIMP nsDeviceContextPS :: GetDrawingSurface(nsIRenderingContext &aConte
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS::GetDepth(PRUint32& aDepth)
|
||||
{
|
||||
return(mDelContext->GetDepth(aDepth));
|
||||
return(1); // postscript is 1 bit
|
||||
|
||||
//aDepth = mDepth;
|
||||
//return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
@ -165,33 +191,7 @@ NS_IMETHODIMP nsDeviceContextPS::CreateILColorSpace(IL_ColorSpace*& aColorSpace)
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS::GetILColorSpace(IL_ColorSpace*& aColorSpace)
|
||||
{
|
||||
|
||||
return (mDelContext->GetILColorSpace(aColorSpace));
|
||||
|
||||
#ifdef NOTNOW
|
||||
if (nsnull == mColorSpace) {
|
||||
IL_RGBBits colorRGBBits;
|
||||
|
||||
// Default is to create a 32-bit color space
|
||||
colorRGBBits.red_shift = 16;
|
||||
colorRGBBits.red_bits = 8;
|
||||
colorRGBBits.green_shift = 8;
|
||||
colorRGBBits.green_bits = 8;
|
||||
colorRGBBits.blue_shift = 0;
|
||||
colorRGBBits.blue_bits = 8;
|
||||
|
||||
//mColorSpace = IL_CreateTrueColorSpace(&colorRGBBits, 32);
|
||||
if (nsnull == mColorSpace) {
|
||||
aColorSpace = nsnull;
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
//NS_POSTCONDITION(nsnull != mColorSpace, "null color space");
|
||||
//aColorSpace = mColorSpace;
|
||||
//IL_AddRefToColorSpace(aColorSpace);
|
||||
return NS_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -201,15 +201,10 @@ NS_IMETHODIMP nsDeviceContextPS::GetILColorSpace(IL_ColorSpace*& aColorSpace)
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS :: CheckFontExistence(const nsString& aFontName)
|
||||
{
|
||||
#ifdef NEVER
|
||||
short fontNum;
|
||||
if (GetMacFontNumber(aFontName, fontNum))
|
||||
return NS_OK;
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
return (mDelContext->CheckFontExistence(aFontName));
|
||||
|
||||
//return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
@ -218,10 +213,11 @@ NS_IMETHODIMP nsDeviceContextPS :: CheckFontExistence(const nsString& aFontName)
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight)
|
||||
{
|
||||
aWidth = 1;
|
||||
aHeight = 1;
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
aWidth = NSToIntRound((72.0f*8.0f) * mDevUnitsToAppUnits);
|
||||
aHeight = NSToIntRound((72.0f*10.0f) * mDevUnitsToAppUnits);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
@ -230,7 +226,6 @@ NS_IMETHODIMP nsDeviceContextPS::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRI
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS::GetDeviceContextFor(nsIDeviceContextSpec *aDevice,nsIDeviceContext *&aContext)
|
||||
{
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -368,10 +363,6 @@ NS_IMETHODIMP nsDeviceContextPS::EndDocument(void)
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS::BeginPage(void)
|
||||
{
|
||||
#ifdef NEVER
|
||||
if(((nsDeviceContextSpecPS*)(this->mSpec))->mPrintManagerOpen)
|
||||
::PrOpenPage(((nsDeviceContextSpecPS*)(this->mSpec))->mPrinterPort,nsnull);
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -382,17 +373,9 @@ NS_IMETHODIMP nsDeviceContextPS::BeginPage(void)
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS::EndPage(void)
|
||||
{
|
||||
#ifdef NEVER
|
||||
if(((nsDeviceContextSpecPS*)(this->mSpec))->mPrintManagerOpen) {
|
||||
::SetPort((GrafPtr)(((nsDeviceContextSpecPS*)(this->mSpec))->mPrinterPort));
|
||||
::PrClosePage(((nsDeviceContextSpecPS*)(this->mSpec))->mPrinterPort);
|
||||
}
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
@ -403,3 +386,51 @@ NS_IMETHODIMP nsDeviceContextPS :: ConvertPixel(nscolor aColor, PRUint32 & aPixe
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextPS::GetMetricsFor(const nsFont& aFont, nsIFontMetrics *&aMetrics)
|
||||
{
|
||||
PRInt32 n,cnt;
|
||||
nsresult rv;
|
||||
|
||||
// First check our cache
|
||||
n = mFontMetrics.Count();
|
||||
|
||||
for (cnt = 0; cnt < n; cnt++){
|
||||
aMetrics = (nsIFontMetrics*) mFontMetrics.ElementAt(cnt);
|
||||
|
||||
const nsFont *font;
|
||||
aMetrics->GetFont(font);
|
||||
if (aFont.Equals(*font)){
|
||||
NS_ADDREF(aMetrics);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// It's not in the cache. Get font metrics and then cache them.
|
||||
nsIFontMetrics* fm = new nsFontMetricsPS();
|
||||
if (nsnull == fm) {
|
||||
aMetrics = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
rv = fm->Init(aFont, this);
|
||||
|
||||
if (NS_OK != rv) {
|
||||
aMetrics = nsnull;
|
||||
return rv;
|
||||
}
|
||||
|
||||
mFontMetrics.AppendElement(fm);
|
||||
NS_ADDREF(fm); // this is for the cache
|
||||
|
||||
|
||||
for (cnt = 0; cnt < n; cnt++){
|
||||
aMetrics = (nsIFontMetrics*) mFontMetrics.ElementAt(cnt);
|
||||
const nsFont *font;
|
||||
aMetrics->GetFont(font);
|
||||
}
|
||||
|
||||
NS_ADDREF(fm); // this is for the routine that needs this font
|
||||
aMetrics = fm;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "nsIView.h"
|
||||
#include "nsIRenderingContext.h"
|
||||
#include "nsPrintManager.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
|
||||
class nsDeviceContextWin; // need to be a friend of the class using us.
|
||||
|
||||
@ -40,7 +42,7 @@ public:
|
||||
* with a NativeWidget.
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
NS_IMETHOD Init(nsIDeviceContext *aCreatingDeviceContext);
|
||||
NS_IMETHOD Init(nsIDeviceContext *aCreatingDeviceContext,nsIDeviceContext *aPrinterContext, HDC aTheDC);
|
||||
|
||||
NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext);
|
||||
NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets);
|
||||
@ -51,24 +53,24 @@ public:
|
||||
NS_IMETHOD GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface);
|
||||
|
||||
|
||||
NS_IMETHOD CheckFontExistence(const nsString& aFontName);
|
||||
NS_IMETHOD CreateILColorSpace(IL_ColorSpace*& aColorSpace);
|
||||
NS_IMETHOD CheckFontExistence(const nsString& aFontName);
|
||||
NS_IMETHOD CreateILColorSpace(IL_ColorSpace*& aColorSpace);
|
||||
NS_IMETHODIMP GetILColorSpace(IL_ColorSpace*& aColorSpace);
|
||||
NS_IMETHOD GetDepth(PRUint32& aDepth);
|
||||
NS_IMETHOD ConvertPixel(nscolor aColor, PRUint32 & aPixel);
|
||||
NS_IMETHOD GetDepth(PRUint32& aDepth);
|
||||
NS_IMETHOD ConvertPixel(nscolor aColor, PRUint32 & aPixel);
|
||||
|
||||
NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight);
|
||||
|
||||
NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
|
||||
nsIDeviceContext *&aContext);
|
||||
|
||||
NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIFontMetrics*& aMetrics);
|
||||
NS_IMETHOD BeginDocument(void);
|
||||
NS_IMETHOD EndDocument(void);
|
||||
|
||||
NS_IMETHOD BeginPage(void);
|
||||
NS_IMETHOD EndPage(void);
|
||||
|
||||
|
||||
protected:
|
||||
virtual ~nsDeviceContextPS();
|
||||
|
||||
@ -78,6 +80,8 @@ protected:
|
||||
nsIDeviceContextSpec *mSpec;
|
||||
nsIDeviceContext *mDelContext; // since this is not really a device context, we ned a deligate
|
||||
PrintSetup *mPrintSetup;
|
||||
float mPixelScale;
|
||||
nsVoidArray mFontMetrics; // we are not using the normal font cache, this is special for PostScript.
|
||||
|
||||
|
||||
|
||||
@ -85,6 +89,9 @@ public:
|
||||
//static bool GetMacFontNumber(const nsString& aFontName, short &fontNum);
|
||||
MWContext* GetPrintContext() { return mPrintContext; }
|
||||
|
||||
public:
|
||||
HDC mDC;
|
||||
|
||||
friend nsDeviceContextWin; // need to be a friend of the class using us.
|
||||
};
|
||||
|
||||
|
355
gfx/src/ps/nsFontMetricsPS.cpp
Normal file
355
gfx/src/ps/nsFontMetricsPS.cpp
Normal file
@ -0,0 +1,355 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsFontMetricsPS.h"
|
||||
|
||||
static NS_DEFINE_IID(kIFontMetricsIID, NS_IFONT_METRICS_IID);
|
||||
|
||||
nsFontMetricsPS :: nsFontMetricsPS()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsFontMetricsPS :: ~nsFontMetricsPS()
|
||||
{
|
||||
if (nsnull != mFont){
|
||||
delete mFont;
|
||||
mFont = nsnull;
|
||||
}
|
||||
|
||||
if (NULL != mFontHandle){
|
||||
::DeleteObject(mFontHandle);
|
||||
mFontHandle = NULL;
|
||||
}
|
||||
|
||||
mDeviceContext = nsnull;
|
||||
}
|
||||
|
||||
#ifdef LEAK_DEBUG
|
||||
nsrefcnt
|
||||
nsFontMetricsPS :: AddRef()
|
||||
{
|
||||
NS_PRECONDITION(mRefCnt != 0, "resurrecting a dead object");
|
||||
return ++mRefCnt;
|
||||
}
|
||||
|
||||
nsrefcnt
|
||||
nsFontMetricsPS :: Release()
|
||||
{
|
||||
NS_PRECONDITION(mRefCnt != 0, "too many release's");
|
||||
if (--mRefCnt == 0) {
|
||||
delete this;
|
||||
}
|
||||
return mRefCnt;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsFontMetricsPS :: QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kClassIID, kIFontMetricsIID);
|
||||
if (aIID.Equals(kClassIID)) {
|
||||
*aInstancePtr = (void*) this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*) ((nsISupports*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
#else
|
||||
NS_IMPL_ISUPPORTS(nsFontMetricsPS, kIFontMetricsIID)
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsPS :: Init(const nsFont& aFont, nsIDeviceContext *aContext)
|
||||
{
|
||||
mFont = new nsFont(aFont);
|
||||
//don't addref this to avoid circular refs
|
||||
mDeviceContext = (nsDeviceContextPS *)aContext;
|
||||
RealizeFont();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsPS :: Destroy()
|
||||
{
|
||||
mDeviceContext = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static void
|
||||
MapGenericFamilyToFont(const nsString& aGenericFamily,
|
||||
nsIDeviceContext* aDC,
|
||||
nsString& aFontFace)
|
||||
{
|
||||
// the CSS generic names (conversions from Nav for now)
|
||||
// XXX this need to check availability with the dc
|
||||
PRBool aliased;
|
||||
if (aGenericFamily.EqualsIgnoreCase("serif")) {
|
||||
aDC->GetLocalFontName(nsString("Times New Roman"), aFontFace, aliased);
|
||||
}
|
||||
else if (aGenericFamily.EqualsIgnoreCase("sans-serif")) {
|
||||
aDC->GetLocalFontName(nsString("Arial"), aFontFace, aliased);
|
||||
}
|
||||
else if (aGenericFamily.EqualsIgnoreCase("cursive")) {
|
||||
aDC->GetLocalFontName(nsString("Script"), aFontFace, aliased);
|
||||
}
|
||||
else if (aGenericFamily.EqualsIgnoreCase("fantasy")) {
|
||||
aDC->GetLocalFontName(nsString("Arial"), aFontFace, aliased);
|
||||
}
|
||||
else if (aGenericFamily.EqualsIgnoreCase("monospace")) {
|
||||
aDC->GetLocalFontName(nsString("Courier New"), aFontFace, aliased);
|
||||
}
|
||||
else {
|
||||
aFontFace.Truncate();
|
||||
}
|
||||
}
|
||||
|
||||
struct FontEnumData {
|
||||
FontEnumData(nsIDeviceContext* aContext, TCHAR* aFaceName)
|
||||
{
|
||||
mContext = aContext;
|
||||
mFaceName = aFaceName;
|
||||
}
|
||||
nsIDeviceContext* mContext;
|
||||
TCHAR* mFaceName;
|
||||
};
|
||||
|
||||
static PRBool
|
||||
FontEnumCallback(const nsString& aFamily, PRBool aGeneric, void *aData)
|
||||
{
|
||||
FontEnumData* data = (FontEnumData*)aData;
|
||||
if (aGeneric) {
|
||||
nsAutoString realFace;
|
||||
MapGenericFamilyToFont(aFamily, data->mContext, realFace);
|
||||
realFace.ToCString(data->mFaceName, LF_FACESIZE);
|
||||
return PR_FALSE; // stop
|
||||
}
|
||||
else {
|
||||
nsAutoString realFace;
|
||||
PRBool aliased;
|
||||
data->mContext->GetLocalFontName(aFamily, realFace, aliased);
|
||||
if (aliased || (NS_OK == data->mContext->CheckFontExistence(realFace))) {
|
||||
realFace.ToCString(data->mFaceName, LF_FACESIZE);
|
||||
return PR_FALSE; // stop
|
||||
}
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
nsFontMetricsPS::RealizeFont()
|
||||
{
|
||||
// Fill in logFont structure; stolen from awt
|
||||
LOGFONT logFont;
|
||||
logFont.lfWidth = 0;
|
||||
logFont.lfEscapement = 0;
|
||||
logFont.lfOrientation = 0;
|
||||
logFont.lfUnderline =
|
||||
(mFont->decorations & NS_FONT_DECORATION_UNDERLINE)
|
||||
? TRUE : FALSE;
|
||||
logFont.lfStrikeOut =
|
||||
(mFont->decorations & NS_FONT_DECORATION_LINE_THROUGH)
|
||||
? TRUE : FALSE;
|
||||
logFont.lfCharSet = DEFAULT_CHARSET;
|
||||
logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
|
||||
logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
|
||||
logFont.lfQuality = DEFAULT_QUALITY;
|
||||
logFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
|
||||
logFont.lfWeight = ((400 < mFont->weight) ? FW_BOLD : FW_NORMAL); // XXX could be smarter
|
||||
logFont.lfItalic = (mFont->style & (NS_FONT_STYLE_ITALIC | NS_FONT_STYLE_OBLIQUE))
|
||||
? TRUE : FALSE; // XXX need better oblique support
|
||||
float app2dev, app2twip, scale;
|
||||
mDeviceContext->GetAppUnitsToDevUnits(app2dev);
|
||||
mDeviceContext->GetDevUnitsToTwips(app2twip);
|
||||
mDeviceContext->GetCanonicalPixelScale(scale);
|
||||
app2twip *= app2dev * scale;
|
||||
|
||||
float rounded = ((float)NSIntPointsToTwips(NSTwipsToFloorIntPoints(nscoord(mFont->size * app2twip)))) / app2twip;
|
||||
|
||||
// round font size off to floor point size to be windows compatible
|
||||
// logFont.lfHeight = - NSToIntRound(rounded * app2dev); // this is proper (windows) rounding
|
||||
logFont.lfHeight = - LONG(rounded * app2dev); // this floor rounding is to make ours compatible with Nav 4.0
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
// Make Purify happy
|
||||
memset(logFont.lfFaceName, 0, sizeof(logFont.lfFaceName));
|
||||
#endif
|
||||
logFont.lfFaceName[0] = '\0';
|
||||
|
||||
FontEnumData data(mDeviceContext, logFont.lfFaceName);
|
||||
mFont->EnumerateFamilies(FontEnumCallback, &data);
|
||||
|
||||
// Create font handle from font spec
|
||||
mFontHandle = ::CreateFontIndirect(&logFont);
|
||||
|
||||
HWND win = NULL;
|
||||
HDC dc = NULL;
|
||||
|
||||
if (NULL != mDeviceContext->mDC)
|
||||
dc = mDeviceContext->mDC;
|
||||
else
|
||||
{
|
||||
// Find font metrics and character widths
|
||||
win = (HWND)mDeviceContext->mWidget;
|
||||
dc = ::GetDC(win);
|
||||
}
|
||||
|
||||
HFONT oldfont = (HFONT)::SelectObject(dc, (HGDIOBJ) mFontHandle);
|
||||
|
||||
// Get font metrics
|
||||
float dev2app;
|
||||
mDeviceContext->GetDevUnitsToAppUnits(dev2app);
|
||||
OUTLINETEXTMETRIC oMetrics;
|
||||
TEXTMETRIC& metrics = oMetrics.otmTextMetrics;
|
||||
nscoord onePixel = NSToCoordRound(1 * dev2app);
|
||||
|
||||
if (0 < ::GetOutlineTextMetrics(dc, sizeof(oMetrics), &oMetrics)) {
|
||||
// mXHeight = NSToCoordRound(oMetrics.otmsXHeight * dev2app); XXX not really supported on windows
|
||||
mXHeight = NSToCoordRound((float)metrics.tmAscent * dev2app * 0.50f); // 50% of ascent, best guess for true type
|
||||
mSuperscriptOffset = NSToCoordRound(oMetrics.otmptSuperscriptOffset.y * dev2app);
|
||||
mSubscriptOffset = NSToCoordRound(oMetrics.otmptSubscriptOffset.y * dev2app);
|
||||
|
||||
mStrikeoutSize = MAX(onePixel, NSToCoordRound(oMetrics.otmsStrikeoutSize * dev2app));
|
||||
mStrikeoutOffset = NSToCoordRound(oMetrics.otmsStrikeoutPosition * dev2app);
|
||||
mUnderlineSize = MAX(onePixel, NSToCoordRound(oMetrics.otmsUnderscoreSize * dev2app));
|
||||
mUnderlineOffset = NSToCoordRound(oMetrics.otmsUnderscorePosition * dev2app);
|
||||
}
|
||||
else {
|
||||
// Make a best-effort guess at extended metrics
|
||||
// this is based on general typographic guidelines
|
||||
::GetTextMetrics(dc, &metrics);
|
||||
mXHeight = NSToCoordRound((float)metrics.tmAscent * dev2app * 0.56f); // 56% of ascent, best guess for non-true type
|
||||
mSuperscriptOffset = mXHeight; // XXX temporary code!
|
||||
mSubscriptOffset = mXHeight; // XXX temporary code!
|
||||
|
||||
mStrikeoutSize = onePixel; // XXX this is a guess
|
||||
mStrikeoutOffset = NSToCoordRound(mXHeight / 2.0f); // 50% of xHeight
|
||||
mUnderlineSize = onePixel; // XXX this is a guess
|
||||
mUnderlineOffset = -NSToCoordRound((float)metrics.tmDescent * dev2app * 0.30f); // 30% of descent
|
||||
}
|
||||
|
||||
mHeight = NSToCoordRound(metrics.tmHeight * dev2app);
|
||||
mAscent = NSToCoordRound(metrics.tmAscent * dev2app);
|
||||
mDescent = NSToCoordRound(metrics.tmDescent * dev2app);
|
||||
mLeading = NSToCoordRound(metrics.tmInternalLeading * dev2app);
|
||||
mMaxAscent = NSToCoordRound(metrics.tmAscent * dev2app);
|
||||
mMaxDescent = NSToCoordRound(metrics.tmDescent * dev2app);
|
||||
mMaxAdvance = NSToCoordRound(metrics.tmMaxCharWidth * dev2app);
|
||||
|
||||
::SelectObject(dc, oldfont);
|
||||
|
||||
if (NULL == mDeviceContext->mDC)
|
||||
::ReleaseDC(win, dc);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsPS :: GetXHeight(nscoord& aResult)
|
||||
{
|
||||
aResult = mXHeight;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsPS :: GetSuperscriptOffset(nscoord& aResult)
|
||||
{
|
||||
aResult = mSuperscriptOffset;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsPS :: GetSubscriptOffset(nscoord& aResult)
|
||||
{
|
||||
aResult = mSubscriptOffset;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsPS :: GetStrikeout(nscoord& aOffset, nscoord& aSize)
|
||||
{
|
||||
aOffset = mStrikeoutOffset;
|
||||
aSize = mStrikeoutSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsPS :: GetUnderline(nscoord& aOffset, nscoord& aSize)
|
||||
{
|
||||
aOffset = mUnderlineOffset;
|
||||
aSize = mUnderlineSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsPS :: GetHeight(nscoord &aHeight)
|
||||
{
|
||||
aHeight = mHeight;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsPS :: GetLeading(nscoord &aLeading)
|
||||
{
|
||||
aLeading = mLeading;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsPS :: GetMaxAscent(nscoord &aAscent)
|
||||
{
|
||||
aAscent = mMaxAscent;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsPS :: GetMaxDescent(nscoord &aDescent)
|
||||
{
|
||||
aDescent = mMaxDescent;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsPS :: GetMaxAdvance(nscoord &aAdvance)
|
||||
{
|
||||
aAdvance = mMaxAdvance;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsPS :: GetFont(const nsFont *&aFont)
|
||||
{
|
||||
aFont = mFont;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsPS::GetFontHandle(nsFontHandle &aHandle)
|
||||
{
|
||||
aHandle = mFontHandle;
|
||||
return NS_OK;
|
||||
}
|
85
gfx/src/ps/nsFontMetricsPS.h
Normal file
85
gfx/src/ps/nsFontMetricsPS.h
Normal file
@ -0,0 +1,85 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsFontMetricsPS_h__
|
||||
#define nsFontMetricsPS_h__
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include "nsIFontMetrics.h"
|
||||
#include "nsFont.h"
|
||||
#include "nsString.h"
|
||||
#include "nsUnitConversion.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsDeviceContextPS.h"
|
||||
|
||||
class nsFontMetricsPS : public nsIFontMetrics
|
||||
{
|
||||
public:
|
||||
nsFontMetricsPS();
|
||||
~nsFontMetricsPS();
|
||||
|
||||
void* operator new(size_t sz) {
|
||||
void* rv = new char[sz];
|
||||
nsCRT::zero(rv, sz);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Init(const nsFont& aFont, nsIDeviceContext* aContext);
|
||||
NS_IMETHOD Destroy();
|
||||
|
||||
NS_IMETHOD GetXHeight(nscoord& aResult);
|
||||
NS_IMETHOD GetSuperscriptOffset(nscoord& aResult);
|
||||
NS_IMETHOD GetSubscriptOffset(nscoord& aResult);
|
||||
NS_IMETHOD GetStrikeout(nscoord& aOffset, nscoord& aSize);
|
||||
NS_IMETHOD GetUnderline(nscoord& aOffset, nscoord& aSize);
|
||||
|
||||
NS_IMETHOD GetHeight(nscoord &aHeight);
|
||||
NS_IMETHOD GetLeading(nscoord &aLeading);
|
||||
NS_IMETHOD GetMaxAscent(nscoord &aAscent);
|
||||
NS_IMETHOD GetMaxDescent(nscoord &aDescent);
|
||||
NS_IMETHOD GetMaxAdvance(nscoord &aAdvance);
|
||||
NS_IMETHOD GetFont(const nsFont *&aFont);
|
||||
NS_IMETHOD GetFontHandle(nsFontHandle &aHandle);
|
||||
|
||||
protected:
|
||||
void RealizeFont();
|
||||
|
||||
nsDeviceContextPS *mDeviceContext;
|
||||
nsFont *mFont;
|
||||
nscoord mHeight;
|
||||
nscoord mAscent;
|
||||
nscoord mDescent;
|
||||
nscoord mLeading;
|
||||
nscoord mMaxAscent;
|
||||
nscoord mMaxDescent;
|
||||
nscoord mMaxAdvance;
|
||||
nscoord mXHeight;
|
||||
nscoord mSuperscriptOffset;
|
||||
nscoord mSubscriptOffset;
|
||||
nscoord mStrikeoutSize;
|
||||
nscoord mStrikeoutOffset;
|
||||
nscoord mUnderlineSize;
|
||||
nscoord mUnderlineOffset;
|
||||
HFONT mFontHandle;
|
||||
};
|
||||
|
||||
#endif
|
@ -740,6 +740,8 @@ nsTransform2D *theMatrix;
|
||||
FillRect(aX, aY, aWidth, size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
@ -749,9 +751,10 @@ NS_IMETHODIMP nsRenderingContextPS :: DrawString(const PRUnichar *aString, PRUin
|
||||
nscoord aX, nscoord aY, nscoord aWidth,
|
||||
const nscoord* aSpacing)
|
||||
{
|
||||
PRInt32 x = aX;
|
||||
PRInt32 y = aY;
|
||||
nsTransform2D *theMatrix;
|
||||
nsTransform2D *theMatrix;
|
||||
PRInt32 x = aX;
|
||||
PRInt32 y = aY;
|
||||
nsIFontMetrics *fMetrics;
|
||||
|
||||
SetupFontAndColor();
|
||||
mDelRenderingContext->GetCurrentTransform(theMatrix);
|
||||
@ -764,39 +767,33 @@ nsTransform2D *theMatrix;
|
||||
// Slow, but accurate rendering
|
||||
const PRUnichar* end = aString + aLength;
|
||||
while (aString < end){
|
||||
// XXX can shave some cycles by inlining a version of transform
|
||||
// coord where y is constant and transformed once
|
||||
x = aX;
|
||||
y = aY;
|
||||
|
||||
theMatrix->TransformCoord(&x, &y);
|
||||
//::ExtTextOutW(mDC, x, y, 0, NULL, aString, 1, NULL);
|
||||
//XXX:Remove ::ExtTextOutW above
|
||||
//PostscriptTextOut((const char *)aString, 1, NS_PIXELS_TO_POINTS(x), NS_PIXELS_TO_POINTS(y), aWidth, aSpacing, PR_TRUE);
|
||||
PostscriptTextOut((const char *)aString, 1, NS_PIXELS_TO_POINTS(x), NS_PIXELS_TO_POINTS(y), aWidth, aSpacing, PR_TRUE);
|
||||
aX += *aSpacing++;
|
||||
aString++;
|
||||
}
|
||||
} else {
|
||||
theMatrix->TransformCoord(&x, &y);
|
||||
//::ExtTextOutW(mDC, x, y, 0, NULL, aString, aLength, NULL);
|
||||
//XXX: Remove ::ExtTextOutW above
|
||||
//PostscriptTextOut((const char *)aString, aLength, NS_PIXELS_TO_POINTS(x), NS_PIXELS_TO_POINTS(y), aWidth, aSpacing, PR_TRUE);
|
||||
PostscriptTextOut((const char *)aString, aLength, NS_PIXELS_TO_POINTS(x), NS_PIXELS_TO_POINTS(y), aWidth, aSpacing, PR_TRUE);
|
||||
}
|
||||
|
||||
#ifdef NOTNOW
|
||||
if (nsnull != mFontMetrics){
|
||||
|
||||
mDelRenderingContext->GetFontMetrics(fMetrics);
|
||||
|
||||
if (nsnull != fMetrics){
|
||||
nsFont *font;
|
||||
//mFontMetrics->GetFont(font);
|
||||
fMetrics->GetFont(font);
|
||||
PRUint8 decorations = font->decorations;
|
||||
|
||||
if (decorations & NS_FONT_DECORATION_OVERLINE){
|
||||
nscoord offset;
|
||||
nscoord size;
|
||||
mFontMetrics->GetUnderline(offset, size);
|
||||
fMetrics->GetUnderline(offset, size);
|
||||
FillRect(aX, aY, aWidth, size);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -935,7 +932,15 @@ NS_IMETHODIMP nsRenderingContextPS :: CopyOffScreenBits(nsDrawingSurface aSrcSur
|
||||
|
||||
void nsRenderingContextPS :: SetupFontAndColor(void)
|
||||
{
|
||||
nscoord fontHeight = 0;
|
||||
nsFont *font;
|
||||
nsIFontMetrics *fMetrics;
|
||||
|
||||
mDelRenderingContext->GetFontMetrics(fMetrics);
|
||||
fMetrics->GetHeight(fontHeight);
|
||||
fMetrics->GetFont(font);
|
||||
|
||||
PostscriptFont(fontHeight,font->style,font->variant,font->weight,font->decorations);
|
||||
}
|
||||
|
||||
#ifdef NOTNOW
|
||||
|
Loading…
Reference in New Issue
Block a user