Fixed up postscript stuff, now prints on Unix

This commit is contained in:
dcone%netscape.com 1999-03-01 16:23:36 +00:00
Родитель 4924b55d49
Коммит 8764cbc65a
8 изменённых файлов: 3058 добавлений и 2980 удалений

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -1,241 +1,336 @@
/* -*- 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 nsAFMObject_h__
#define nsAFMObject_h__
#include "nsIFontMetrics.h"
#include "nsFont.h"
#include "nsString.h"
#include "nsUnitConversion.h"
#include "nsIDeviceContext.h"
#include "nsCRT.h"
class nsDeviceContextPS;
// AFM Key Words
typedef enum
{
kComment,
// File structure.
kStartFontMetrics,
kEndFontMetrics,
kStartCompFontMetrics,
kEndCompFontMetrics,
kStartDescendent,
kEndDescendent,
kStartMasterFontMetrics,
kEndMasterFontMetrics,
// Control information.
kMetricsSets,
kDescendents,
kMasters,
kAxes,
// Global font information.
kFontName,
kFullName,
kFamilyName,
kWeight,
kFontBBox,
kVersion,
kNotice,
kEncodingScheme,
kMappingScheme,
kEscChar,
kCharacterSet,
kCharacters,
kIsBaseFont,
kVVector,
kIsFixedV,
kCapHeight,
kXHeight,
kAscender,
kDescender,
kWeightVector,
kBlendDesignPositions,
kBlendDesignMap,
kBlendAxisTypes,
// Writing direction information.
kStartDirection,
kEndDirection,
kUnderlinePosition,
kUnderlineThickness,
kItalicAngle,
kCharWidth,
kIsFixedPitch,
// Individual character metrics.
kStartCharMetrics,
kEndCharMetrics,
kC,
kCH,
kWX,
kW0X,
kW1X,
kWY,
kW0Y,
kW1Y,
kW,
kW0,
kW1,
kVV,
kN,
kB,
kL,
// Kerning data.
kStartKernData,
kEndKernData,
kStartTrackKern,
kEndTrackKern,
kTrackKern,
kStartKernPairs,
kEndKernPairs,
kKP,
kKPH,
kKPX,
kKPY,
// Composite character data.
kStartComposites,
kEndComposites,
kCC,
kPCC,
// Axis information.
kStartAxis,
kEndAxis,
kAxisType,
kAxisLabel,
// Master Design Information
kStartMaster,
kEndMaster
} AFMKey;
// Single character infor for AFM character.
struct AFM_Single_Char_Metrics
{
PRInt32 mCharacter_Code; // default charcode (-1 if not encoded)
double mW0x; // character width x in writing direction 0
double mW0y; // character width y in writing direction 0
double mW1x; // character width x in writing direction 1
double mW1y; // character width y in writing direction 1
char *mName; // character name
double mVv_x; // local VVector x
double mVv_y; // local VVector y
// character bounding box.
double mLlx;
double mLly;
double mUrx;
double mUry;
double num_ligatures;
//AFMLigature *ligatures;
};
typedef struct AFM_Single_Char_Metrics AFMscm;
// Font information which we get from AFM files, this is needed for the PS output
struct fontInformation
{
double mFontVersion;
char *mFontName;
char *mFullName;
char *mFamilyName;
char *mWeight;
double mFontBBox_llx;
double mFontBBox_lly;
double mFontBBox_urx;
double mFontBBox_ury;
char *mVersion;
char *mNotice;
char *mEncodingScheme;
PRInt32 mMappingScheme;
PRInt32 mEscChar;
char *mCharacterSet;
PRInt32 mCharacters;
PRBool mIsBaseFont;
double mVVector_0;
double mVVector_1;
PRBool mIsFixedV;
double mCapHeight;
double mXHeight;
double mAscender;
double mDescender;
double mUnderlinePosition;
double mUnderlineThickness;
AFMscm *AFMCharMetrics;
};
typedef struct fontInformation AFMFontInformation;
class nsAFMObject
{
public:
nsAFMObject();
virtual ~nsAFMObject();
void Init(char *aFontName,PRInt32 aFontHeight);
void GetStringWidth(const PRUnichar *aString,nscoord& aWidth,nscoord aLength);
void GetStringWidth(const char *aString,nscoord& aWidth,nscoord aLength);
protected:
void AFM_ReadFile(void);
void GetKey(AFMKey *aTheKey);
PRInt32 GetToken(void);
PRInt32 MatchKey(char *aKey);
PRInt32 GetLine(void);
char* GetAFMString (void);
char* GetAFMName (void);
void GetAFMInt (PRInt32 *aInt) {GetToken();*aInt = atoi (mToken);}
void GetAFMNumber (double *aFloat){GetToken();*aFloat = atof (mToken);}
void GetAFMBool (PRBool *aBool);
void ReadCharMetrics (AFMFontInformation *aFontInfo,PRInt32 aNumCharacters);
public:
AFMFontInformation *mPSFontInfo;
protected:
FILE *mAFMFile; // this is the file we are reading for the AFM files
char mToken[256]; // this is where we put the token for reading;
nscoord mFontHeight; // font height in points
};
#define NUM_KEYS (sizeof (keynames) / sizeof (struct keyname_st) - 1)
#endif
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsAFMObject_h__
#define nsAFMObject_h__
#include "nsIFontMetrics.h"
#include "nsFont.h"
#include "nsString.h"
#include "nsUnitConversion.h"
#include "nsIDeviceContext.h"
#include "nsCRT.h"
class nsDeviceContextPS;
// AFM Key Words
typedef enum
{
kComment,
// File structure.
kStartFontMetrics,
kEndFontMetrics,
kStartCompFontMetrics,
kEndCompFontMetrics,
kStartDescendent,
kEndDescendent,
kStartMasterFontMetrics,
kEndMasterFontMetrics,
// Control information.
kMetricsSets,
kDescendents,
kMasters,
kAxes,
// Global font information.
kFontName,
kFullName,
kFamilyName,
kWeight,
kFontBBox,
kVersion,
kNotice,
kEncodingScheme,
kMappingScheme,
kEscChar,
kCharacterSet,
kCharacters,
kIsBaseFont,
kVVector,
kIsFixedV,
kCapHeight,
kXHeight,
kAscender,
kDescender,
kWeightVector,
kBlendDesignPositions,
kBlendDesignMap,
kBlendAxisTypes,
// Writing direction information.
kStartDirection,
kEndDirection,
kUnderlinePosition,
kUnderlineThickness,
kItalicAngle,
kCharWidth,
kIsFixedPitch,
// Individual character metrics.
kStartCharMetrics,
kEndCharMetrics,
kC,
kCH,
kWX,
kW0X,
kW1X,
kWY,
kW0Y,
kW1Y,
kW,
kW0,
kW1,
kVV,
kN,
kB,
kL,
// Kerning data.
kStartKernData,
kEndKernData,
kStartTrackKern,
kEndTrackKern,
kTrackKern,
kStartKernPairs,
kEndKernPairs,
kKP,
kKPH,
kKPX,
kKPY,
// Composite character data.
kStartComposites,
kEndComposites,
kCC,
kPCC,
// Axis information.
kStartAxis,
kEndAxis,
kAxisType,
kAxisLabel,
// Master Design Information
kStartMaster,
kEndMaster
} AFMKey;
// Single character infor for AFM character.
struct AFM_Single_Char_Metrics
{
PRInt32 mCharacter_Code; // default charcode (-1 if not encoded)
double mW0x; // character width x in writing direction 0
double mW0y; // character width y in writing direction 0
double mW1x; // character width x in writing direction 1
double mW1y; // character width y in writing direction 1
char *mName; // character name
double mVv_x; // local VVector x
double mVv_y; // local VVector y
// character bounding box.
double mLlx;
double mLly;
double mUrx;
double mUry;
double num_ligatures;
//AFMLigature *ligatures;
};
typedef struct AFM_Single_Char_Metrics AFMscm;
// Font information which we get from AFM files, this is needed for the PS output
struct fontInformation
{
double mFontVersion;
char *mFontName;
char *mFullName;
char *mFamilyName;
char *mWeight;
double mFontBBox_llx;
double mFontBBox_lly;
double mFontBBox_urx;
double mFontBBox_ury;
char *mVersion;
char *mNotice;
char *mEncodingScheme;
PRInt32 mMappingScheme;
PRInt32 mEscChar;
char *mCharacterSet;
PRInt32 mCharacters;
PRBool mIsBaseFont;
double mVVector_0;
double mVVector_1;
PRBool mIsFixedV;
double mCapHeight;
double mXHeight;
double mAscender;
double mDescender;
double mUnderlinePosition;
double mUnderlineThickness;
AFMscm *AFMCharMetrics;
};
typedef struct fontInformation AFMFontInformation;
class nsAFMObject
{
public:
/** ---------------------------------------------------
* Construct and AFMObject
* @update 2/26/99 dwc
*/
nsAFMObject();
/** ---------------------------------------------------
* delete an AFMObject
* @update 2/26/99 dwc
*/
virtual ~nsAFMObject();
/** ---------------------------------------------------
* Initialize an AFMObject
* @update 2/26/99 dwc
* @param aFontName - A "C" string name of the font this object will get initialized to
* @param aFontHeight -- The font size for this object
*/
void Init(char *aFontName,PRInt32 aFontHeight);
/** ---------------------------------------------------
* Calculate the width of a unicharacter string
* @update 2/26/99 dwc
* @param aString - The unicharacter string to get the width for
* @param aWidth - Where the width of the string will be put.
* @param aLenth - The length of the passed in string
*/
void GetStringWidth(const PRUnichar *aString,nscoord& aWidth,nscoord aLength);
/** ---------------------------------------------------
* Calculate the width of a C style string
* @update 2/26/99 dwc
* @param aString - The C string to get the width for
* @param aWidth - Where the width of the string will be put.
* @param aLenth - The length of the passed in string
*/
void GetStringWidth(const char *aString,nscoord& aWidth,nscoord aLength);
protected:
/** ---------------------------------------------------
* Read in and parse and AFM file
* @update 2/26/99 dwc
*/
void AFM_ReadFile(void);
/** ---------------------------------------------------
* Get a Keyword in the AFM file being parsed
* @update 2/26/99 dwc
*/
void GetKey(AFMKey *aTheKey);
/** ---------------------------------------------------
* Get a token from the AFM file
* @update 2/26/99 dwc
*/
PRInt32 GetToken(void);
/** ---------------------------------------------------
* For a given token, find the keyword it represents
* @update 2/26/99 dwc
*/
PRInt32 MatchKey(char *aKey);
/** ---------------------------------------------------
* Get a line from the currently parsed file
* @update 2/26/99 dwc
*/
PRInt32 GetLine(void);
/** ---------------------------------------------------
* Get a string from the currently parsed file
* @update 2/26/99 dwc
*/
char* GetAFMString (void);
/** ---------------------------------------------------
* Get a word from the currently parsed file
* @update 2/26/99 dwc
*/
char* GetAFMName (void);
/** ---------------------------------------------------
* Get an integer from the currently parsed file
* @update 2/26/99 dwc
*/
void GetAFMInt (PRInt32 *aInt) {GetToken();*aInt = atoi (mToken);}
/** ---------------------------------------------------
* Get a floating point number from the currently parsed file
* @update 2/26/99 dwc
*/
void GetAFMNumber (double *aFloat){GetToken();*aFloat = atof (mToken);}
/** ---------------------------------------------------
* Get a boolean from the currently parsed file
* @update 2/26/99 dwc
*/
void GetAFMBool (PRBool *aBool);
/** ---------------------------------------------------
* Read in the AFMFontInformation from the currently parsed AFM file
* @update 2/26/99 dwc
*/
void ReadCharMetrics (AFMFontInformation *aFontInfo,PRInt32 aNumCharacters);
public:
AFMFontInformation *mPSFontInfo;
protected:
FILE *mAFMFile; // this is the AFM file we are parsing.
char mToken[256]; // Temporary storage for reading and parsing the file
nscoord mFontHeight; // font height in points that we are supporting.
// XXX This should be passed into the GetStringWidth
// so we can have one font family support many sizes
};
#define NUM_KEYS (sizeof (keynames) / sizeof (struct keyname_st) - 1)
#endif

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

@ -1,363 +1,366 @@
/* -*- 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 "nsDeviceContextPS.h"
#include "nsRenderingContextPS.h"
#include "nsString.h"
#include "nsFontMetricsPS.h"
#include "il_util.h"
#include "nsPostScriptObj.h"
static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID);
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
nsDeviceContextPS :: nsDeviceContextPS()
{
NS_INIT_REFCNT();
mSpec = nsnull;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
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_IF_RELEASE(mSpec);
}
void nsDeviceContextPS :: SetSpec(nsIDeviceContextSpec* aSpec)
{
mSpec = aSpec;
NS_ADDREF(aSpec);
}
NS_IMPL_QUERY_INTERFACE(nsDeviceContextPS, kDeviceContextIID)
NS_IMPL_ADDREF(nsDeviceContextPS)
NS_IMPL_RELEASE(nsDeviceContextPS)
/** ---------------------------------------------------
* See documentation in nsDeviceContextPS.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS :: Init(nsIDeviceContext *aCreatingDeviceContext,nsIDeviceContext *aPrinterContext)
{
float origscale, newscale;
float t2d, a2d;
mDepth = 1; // just for arguments sake
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;
}
/** ---------------------------------------------------
* Create a Postscript RenderingContext. This will create a RenderingContext
* from the deligate RenderingContext and intall that into our Postscript RenderingContext.
* @update 12/21/98 dwc
* @param aContext -- our newly created Postscript RenderingContextPS
* @return -- NS_OK if everything succeeded.
*/
NS_IMETHODIMP nsDeviceContextPS :: CreateRenderingContext(nsIRenderingContext *&aContext)
{
nsresult rv = NS_ERROR_OUT_OF_MEMORY;
aContext = new nsRenderingContextPS();
if (nsnull != aContext){
NS_ADDREF(aContext);
rv = ((nsRenderingContextPS*) aContext)->Init(this);
}else{
rv = NS_ERROR_OUT_OF_MEMORY;
}
if (NS_OK != rv){
NS_IF_RELEASE(aContext);
}
return rv;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS :: SupportsNativeWidgets(PRBool &aSupportsWidgets)
{
aSupportsWidgets = PR_FALSE;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS :: GetScrollBarDimensions(float &aWidth, float &aHeight) const
{
//XXX: Hardcoded values for Postscript
aWidth = 20;
aHeight = 20;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS :: GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface)
{
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::GetDepth(PRUint32& aDepth)
{
return(1); // postscript is 1 bit
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::GetILColorSpace(IL_ColorSpace*& aColorSpace)
{
#ifdef NOTNOW
if (nsnull == mColorSpace) {
mColorSpace = IL_CreateGreyScaleColorSpace(1, 1);
if (nsnull == mColorSpace) {
aColorSpace = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
}
// Return the color space
aColorSpace = mColorSpace;
IL_AddRefToColorSpace(aColorSpace);
#endif
if(nsnull==mColorSpace) {
IL_RGBBits colorRGBBits;
// Create a 24-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, 24);
if (nsnull == mColorSpace) {
aColorSpace = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
}
// Return the color space
aColorSpace = mColorSpace;
IL_AddRefToColorSpace(aColorSpace);
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS :: CheckFontExistence(const nsString& aFontName)
{
// XXX this needs to find out if this font is supported for postscript
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextPS :: GetSystemAttribute(nsSystemAttrID anID, SystemAttrStruct * aInfo) const
{
switch (anID) {
case 0:
break;
default:
break;
}
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight)
{
aWidth = NSToIntRound((72.0f*8.0f) * mDevUnitsToAppUnits);
aHeight = NSToIntRound((72.0f*10.0f) * mDevUnitsToAppUnits);
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::GetDeviceContextFor(nsIDeviceContextSpec *aDevice,nsIDeviceContext *&aContext)
{
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::BeginDocument(void)
{
mPSObj = new nsPostScriptObj();
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::EndDocument(void)
{
delete mPSObj;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::BeginPage(void)
{
// begin the page
mPSObj->begin_page();
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::EndPage(void)
{
// end the page
mPSObj->end_page();
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS :: ConvertPixel(nscolor aColor, PRUint32 & aPixel)
{
aPixel = aColor;
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;
}
/* -*- 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 "nsDeviceContextPS.h"
#include "nsRenderingContextPS.h"
#include "nsString.h"
#include "nsFontMetricsPS.h"
#include "il_util.h"
#include "nsPostScriptObj.h"
static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID);
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
nsDeviceContextPS :: nsDeviceContextPS()
{
NS_INIT_REFCNT();
mSpec = nsnull;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
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_IF_RELEASE(mSpec);
}
void nsDeviceContextPS :: SetSpec(nsIDeviceContextSpec* aSpec)
{
mSpec = aSpec;
NS_ADDREF(aSpec);
}
NS_IMPL_QUERY_INTERFACE(nsDeviceContextPS, kDeviceContextIID)
NS_IMPL_ADDREF(nsDeviceContextPS)
NS_IMPL_RELEASE(nsDeviceContextPS)
/** ---------------------------------------------------
* See documentation in nsDeviceContextPS.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS :: Init(nsIDeviceContext *aCreatingDeviceContext,nsIDeviceContext *aPrinterContext)
{
float origscale, newscale;
float t2d, a2d;
mDepth = 1; // just for arguments sake
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;
}
/** ---------------------------------------------------
* Create a Postscript RenderingContext. This will create a RenderingContext
* from the deligate RenderingContext and intall that into our Postscript RenderingContext.
* @update 12/21/98 dwc
* @param aContext -- our newly created Postscript RenderingContextPS
* @return -- NS_OK if everything succeeded.
*/
NS_IMETHODIMP nsDeviceContextPS :: CreateRenderingContext(nsIRenderingContext *&aContext)
{
nsresult rv = NS_ERROR_OUT_OF_MEMORY;
aContext = new nsRenderingContextPS();
if (nsnull != aContext){
NS_ADDREF(aContext);
rv = ((nsRenderingContextPS*) aContext)->Init(this);
}else{
rv = NS_ERROR_OUT_OF_MEMORY;
}
if (NS_OK != rv){
NS_IF_RELEASE(aContext);
}
return rv;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS :: SupportsNativeWidgets(PRBool &aSupportsWidgets)
{
aSupportsWidgets = PR_FALSE;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS :: GetScrollBarDimensions(float &aWidth, float &aHeight) const
{
//XXX: Hardcoded values for Postscript
aWidth = 20;
aHeight = 20;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS :: GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface)
{
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::GetDepth(PRUint32& aDepth)
{
return(1); // postscript is 1 bit
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::GetILColorSpace(IL_ColorSpace*& aColorSpace)
{
#ifdef NOTNOW
if (nsnull == mColorSpace) {
mColorSpace = IL_CreateGreyScaleColorSpace(1, 1);
if (nsnull == mColorSpace) {
aColorSpace = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
}
// Return the color space
aColorSpace = mColorSpace;
IL_AddRefToColorSpace(aColorSpace);
#endif
if(nsnull==mColorSpace) {
IL_RGBBits colorRGBBits;
// Create a 24-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, 24);
if (nsnull == mColorSpace) {
aColorSpace = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
}
// Return the color space
aColorSpace = mColorSpace;
IL_AddRefToColorSpace(aColorSpace);
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS :: CheckFontExistence(const nsString& aFontName)
{
// XXX this needs to find out if this font is supported for postscript
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextPS :: GetSystemAttribute(nsSystemAttrID anID, SystemAttrStruct * aInfo) const
{
switch (anID) {
case 0:
break;
default:
break;
}
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight)
{
aWidth = NSToIntRound((72.0f*8.0f) * mDevUnitsToAppUnits);
aHeight = NSToIntRound((72.0f*10.0f) * mDevUnitsToAppUnits);
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::GetDeviceContextFor(nsIDeviceContextSpec *aDevice,nsIDeviceContext *&aContext)
{
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::BeginDocument(void)
{
mPSObj = new nsPostScriptObj();
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::EndDocument(void)
{
delete mPSObj;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::BeginPage(void)
{
// begin the page
mPSObj->begin_page();
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::EndPage(void)
{
// end the page
mPSObj->end_page();
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS :: ConvertPixel(nscolor aColor, PRUint32 & aPixel)
{
aPixel = aColor;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
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;
}

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

@ -1,88 +1,88 @@
/* -*- 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 nsDeviceContextPS_h___
#define nsDeviceContextPS_h___
#include "nsDeviceContext.h"
#include "nsUnitConversion.h"
#include "nsIWidget.h"
#include "nsIView.h"
#include "nsIRenderingContext.h"
#include "nsVoidArray.h"
class nsPostScriptObj;
class nsDeviceContextWin; // need to be a friend of the class using us.
class nsDeviceContextPS : public DeviceContextImpl
{
public:
nsDeviceContextPS();
NS_DECL_ISUPPORTS
/**
* This method does nothing since a postscript devicecontext will never be created
* with a NativeWidget.
* @update 12/21/98 dwc
*/
NS_IMETHOD Init(nsIDeviceContext *aCreatingDeviceContext,nsIDeviceContext *aPrinterContext);
NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext);
NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets);
NS_IMETHOD GetScrollBarDimensions(float &aWidth, float &aHeight) const;
void SetDrawingSurface(nsDrawingSurface aSurface) { mSurface = aSurface; }
NS_IMETHOD GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface);
NS_IMETHOD CheckFontExistence(const nsString& aFontName);
NS_IMETHODIMP GetILColorSpace(IL_ColorSpace*& aColorSpace);
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 GetSystemAttribute(nsSystemAttrID anID, SystemAttrStruct * aInfo) const;
NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIFontMetrics*& aMetrics);
NS_IMETHOD BeginDocument(void);
NS_IMETHOD EndDocument(void);
NS_IMETHOD BeginPage(void);
NS_IMETHOD EndPage(void);
virtual void SetSpec(nsIDeviceContextSpec *aSpec);
protected:
virtual ~nsDeviceContextPS();
nsDrawingSurface mSurface;
PRUint32 mDepth;
nsIDeviceContextSpec *mSpec;
float mPixelScale;
nsVoidArray mFontMetrics; // we are not using the normal font cache, this is special for PostScript.
nsPostScriptObj *mPSObj;
public:
nsPostScriptObj* GetPrintContext() { return mPSObj; }
};
#endif /* nsDeviceContextPS_h___ */
/* -*- 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 nsDeviceContextPS_h___
#define nsDeviceContextPS_h___
#include "nsDeviceContext.h"
#include "nsUnitConversion.h"
#include "nsIWidget.h"
#include "nsIView.h"
#include "nsIRenderingContext.h"
#include "nsVoidArray.h"
class nsPostScriptObj;
class nsDeviceContextWin; // need to be a friend of the class using us.
class nsDeviceContextPS : public DeviceContextImpl
{
public:
nsDeviceContextPS();
NS_DECL_ISUPPORTS
/**
* This method does nothing since a postscript devicecontext will never be created
* with a NativeWidget.
* @update 12/21/98 dwc
*/
NS_IMETHOD Init(nsIDeviceContext *aCreatingDeviceContext,nsIDeviceContext *aPrinterContext);
NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext);
NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets);
NS_IMETHOD GetScrollBarDimensions(float &aWidth, float &aHeight) const;
void SetDrawingSurface(nsDrawingSurface aSurface) { mSurface = aSurface; }
NS_IMETHOD GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface);
NS_IMETHOD CheckFontExistence(const nsString& aFontName);
NS_IMETHODIMP GetILColorSpace(IL_ColorSpace*& aColorSpace);
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 GetSystemAttribute(nsSystemAttrID anID, SystemAttrStruct * aInfo) const;
NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIFontMetrics*& aMetrics);
NS_IMETHOD BeginDocument(void);
NS_IMETHOD EndDocument(void);
NS_IMETHOD BeginPage(void);
NS_IMETHOD EndPage(void);
virtual void SetSpec(nsIDeviceContextSpec *aSpec);
protected:
virtual ~nsDeviceContextPS();
nsDrawingSurface mSurface;
PRUint32 mDepth;
nsIDeviceContextSpec *mSpec;
float mPixelScale;
nsVoidArray mFontMetrics; // we are not using the normal font cache, this is special for PostScript.
nsPostScriptObj *mPSObj;
public:
nsPostScriptObj* GetPrintContext() { return mPSObj; }
};
#endif /* nsDeviceContextPS_h___ */

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

@ -1,327 +1,327 @@
/* -*- 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"
#include "nsDeviceContextPS.h"
static NS_DEFINE_IID(kIFontMetricsIID, NS_IFONT_METRICS_IID);
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
nsFontMetricsPS :: nsFontMetricsPS()
{
NS_INIT_REFCNT();
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
nsFontMetricsPS :: ~nsFontMetricsPS()
{
if (nsnull != mFont){
delete mFont;
mFont = nsnull;
}
mDeviceContext = nsnull;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
#ifdef LEAK_DEBUG
nsrefcnt
nsFontMetricsPS :: AddRef()
{
NS_PRECONDITION(mRefCnt != 0, "resurrecting a dead object");
return ++mRefCnt;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
nsrefcnt
nsFontMetricsPS :: Release()
{
NS_PRECONDITION(mRefCnt != 0, "too many release's");
if (--mRefCnt == 0) {
delete this;
}
return mRefCnt;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
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
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: Init(const nsFont& aFont, nsIDeviceContext *aContext)
{
mFont = new nsFont(aFont);
//don't addref this to avoid circular refs
mDeviceContext = (nsDeviceContextPS *)aContext;
// get the AFM information
mAFMInfo = new nsAFMObject();
mAFMInfo->Init("Helvetica",mFont->size/20);
RealizeFont();
return NS_OK;
}
NS_IMETHODIMP
nsFontMetricsPS :: Destroy()
{
mDeviceContext = nsnull;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
void
nsFontMetricsPS::RealizeFont()
{
double fontsize;
float dev2app;
mDeviceContext->GetDevUnitsToAppUnits(dev2app);
nscoord onePixel = NSToCoordRound(1 * dev2app);
fontsize = mFont->size/20.0;
mXHeight = NSToCoordRound((float)((fontsize*mAFMInfo->mPSFontInfo->mXHeight)/1000.0)*dev2app);
mSuperscriptOffset = mXHeight;
mSubscriptOffset = mXHeight;
mStrikeoutSize = onePixel;
mStrikeoutOffset = (nscoord)(mXHeight / 2.0f);
mUnderlineSize = onePixel;
mUnderlineOffset = (nscoord)(NSToCoordRound((float)((fabs(fontsize*mAFMInfo->mPSFontInfo->mUnderlinePosition))/1000)*dev2app));
mHeight = NSToCoordRound(fontsize * dev2app);
mAscent = NSToCoordRound((float)((fontsize*mAFMInfo->mPSFontInfo->mAscender)/1000)*dev2app);
mDescent = NSToCoordRound((float)((fabs(fontsize*mAFMInfo->mPSFontInfo->mDescender))/1000)*dev2app);
mLeading = 0;
mMaxAscent = mAscent;
mMaxDescent = mDescent;
mMaxAdvance = mHeight;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetXHeight(nscoord& aResult)
{
aResult = mXHeight;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetSuperscriptOffset(nscoord& aResult)
{
aResult = mSuperscriptOffset;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetSubscriptOffset(nscoord& aResult)
{
aResult = mSubscriptOffset;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetStrikeout(nscoord& aOffset, nscoord& aSize)
{
aOffset = mStrikeoutOffset;
aSize = mStrikeoutSize;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetUnderline(nscoord& aOffset, nscoord& aSize)
{
aOffset = mUnderlineOffset;
aSize = mUnderlineSize;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetHeight(nscoord &aHeight)
{
aHeight = mHeight;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetLeading(nscoord &aLeading)
{
aLeading = mLeading;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetMaxAscent(nscoord &aAscent)
{
aAscent = mMaxAscent;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetMaxDescent(nscoord &aDescent)
{
aDescent = mMaxDescent;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetMaxAdvance(nscoord &aAdvance)
{
aAdvance = mMaxAdvance;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetFont(const nsFont *&aFont)
{
aFont = mFont;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS::GetFontHandle(nsFontHandle &aHandle)
{
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetStringWidth(const char *aString,nscoord& aWidth,nscoord aLength)
{
if(mAFMInfo){
mAFMInfo->GetStringWidth(aString,aWidth,aLength);
}
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetStringWidth(const PRUnichar *aString,nscoord& aWidth,nscoord aLength)
{
if(mAFMInfo){
mAFMInfo->GetStringWidth(aString,aWidth,aLength);
}
return NS_OK;
}
/* -*- 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"
#include "nsDeviceContextPS.h"
static NS_DEFINE_IID(kIFontMetricsIID, NS_IFONT_METRICS_IID);
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
nsFontMetricsPS :: nsFontMetricsPS()
{
NS_INIT_REFCNT();
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
nsFontMetricsPS :: ~nsFontMetricsPS()
{
if (nsnull != mFont){
delete mFont;
mFont = nsnull;
}
mDeviceContext = nsnull;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
#ifdef LEAK_DEBUG
nsrefcnt
nsFontMetricsPS :: AddRef()
{
NS_PRECONDITION(mRefCnt != 0, "resurrecting a dead object");
return ++mRefCnt;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
nsrefcnt
nsFontMetricsPS :: Release()
{
NS_PRECONDITION(mRefCnt != 0, "too many release's");
if (--mRefCnt == 0) {
delete this;
}
return mRefCnt;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
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
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: Init(const nsFont& aFont, nsIDeviceContext *aContext)
{
mFont = new nsFont(aFont);
//don't addref this to avoid circular refs
mDeviceContext = (nsDeviceContextPS *)aContext;
// get the AFM information
mAFMInfo = new nsAFMObject();
mAFMInfo->Init("Helvetica",mFont->size/20);
RealizeFont();
return NS_OK;
}
NS_IMETHODIMP
nsFontMetricsPS :: Destroy()
{
mDeviceContext = nsnull;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
void
nsFontMetricsPS::RealizeFont()
{
float fontsize;
float dev2app;
mDeviceContext->GetDevUnitsToAppUnits(dev2app);
nscoord onePixel = NSToCoordRound(1 * dev2app);
fontsize = mFont->size/20.0f;
mXHeight = NSToCoordRound((float)((fontsize*mAFMInfo->mPSFontInfo->mXHeight)/1000.0)*dev2app);
mSuperscriptOffset = mXHeight;
mSubscriptOffset = mXHeight;
mStrikeoutSize = onePixel;
mStrikeoutOffset = (nscoord)(mXHeight / 2.0f);
mUnderlineSize = onePixel;
mUnderlineOffset = (nscoord)(NSToCoordRound((float)((fabs(fontsize*mAFMInfo->mPSFontInfo->mUnderlinePosition))/1000)*dev2app));
mHeight = NSToCoordRound(fontsize * dev2app);
mAscent = NSToCoordRound((float)((fontsize*mAFMInfo->mPSFontInfo->mAscender)/1000)*dev2app);
mDescent = NSToCoordRound((float)((fabs(fontsize*mAFMInfo->mPSFontInfo->mDescender))/1000)*dev2app);
mLeading = 0;
mMaxAscent = mAscent;
mMaxDescent = mDescent;
mMaxAdvance = mHeight;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetXHeight(nscoord& aResult)
{
aResult = mXHeight;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetSuperscriptOffset(nscoord& aResult)
{
aResult = mSuperscriptOffset;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetSubscriptOffset(nscoord& aResult)
{
aResult = mSubscriptOffset;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetStrikeout(nscoord& aOffset, nscoord& aSize)
{
aOffset = mStrikeoutOffset;
aSize = mStrikeoutSize;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetUnderline(nscoord& aOffset, nscoord& aSize)
{
aOffset = mUnderlineOffset;
aSize = mUnderlineSize;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetHeight(nscoord &aHeight)
{
aHeight = mHeight;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetLeading(nscoord &aLeading)
{
aLeading = mLeading;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetMaxAscent(nscoord &aAscent)
{
aAscent = mMaxAscent;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetMaxDescent(nscoord &aDescent)
{
aDescent = mMaxDescent;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetMaxAdvance(nscoord &aAdvance)
{
aAdvance = mMaxAdvance;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetFont(const nsFont *&aFont)
{
aFont = mFont;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS::GetFontHandle(nsFontHandle &aHandle)
{
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetStringWidth(const char *aString,nscoord& aWidth,nscoord aLength)
{
if(mAFMInfo){
mAFMInfo->GetStringWidth(aString,aWidth,aLength);
}
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc
*/
NS_IMETHODIMP
nsFontMetricsPS :: GetStringWidth(const PRUnichar *aString,nscoord& aWidth,nscoord aLength)
{
if(mAFMInfo){
mAFMInfo->GetStringWidth(aString,aWidth,aLength);
}
return NS_OK;
}

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

@ -1,87 +1,87 @@
/* -*- 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 "nsIFontMetrics.h"
#include "nsAFMObject.h"
#include "nsFont.h"
#include "nsString.h"
#include "nsUnitConversion.h"
#include "nsIDeviceContext.h"
#include "nsCRT.h"
class nsDeviceContextPS;
class nsFontMetricsPS : public nsIFontMetrics
{
public:
nsFontMetricsPS();
virtual ~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);
NS_IMETHOD GetStringWidth(const char *String,nscoord &aWidth,nscoord aLength);
NS_IMETHOD GetStringWidth(const PRUnichar *aString,nscoord &aWidth,nscoord aLength);
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;
nsAFMObject *mAFMInfo;
};
#endif
/* -*- 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 "nsIFontMetrics.h"
#include "nsAFMObject.h"
#include "nsFont.h"
#include "nsString.h"
#include "nsUnitConversion.h"
#include "nsIDeviceContext.h"
#include "nsCRT.h"
class nsDeviceContextPS;
class nsFontMetricsPS : public nsIFontMetrics
{
public:
nsFontMetricsPS();
virtual ~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);
NS_IMETHOD GetStringWidth(const char *String,nscoord &aWidth,nscoord aLength);
NS_IMETHOD GetStringWidth(const PRUnichar *aString,nscoord &aWidth,nscoord aLength);
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;
nsAFMObject *mAFMInfo;
};
#endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -1,391 +1,370 @@
/* -*- Mode: C; tab-width: 4; 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 _PSOBJ_H_
#define _PSOBJ_H_
#include "xp_core.h"
#include "xp_file.h"
#include "ntypes.h"
#include "net.h"
#include "nsColor.h"
#include "nsCoord.h"
class nsIImage;
#define NS_LETTER_SIZE 0
#define NS_LEGAL_SIZE 1
#define NS_EXECUTIVE_SIZE 2
#define PAGE_WIDTH 612 // Points
#define PAGE_HEIGHT 792 //Points
#define N_FONTS 8
#define INCH_TO_PAGE(f) ((int) (.5 + (f)*720))
#define PAGE_TO_POINT_I(f) ((int) ((f) / 10.0))
#define PAGE_TO_POINT_F(f) ((f) / 10.0)
#define POINT_TO_PAGE(p) ((p)*10)
typedef void (*XL_CompletionRoutine)(void*);
typedef struct {
short llx, lly, urx, ury;
} PS_BBox;
typedef struct {
short wx, wy;
PS_BBox charBBox;
} PS_CharInfo;
typedef struct {
char *name;
PS_BBox fontBBox;
short upos, uthick;
PS_CharInfo chars[256];
} PS_FontInfo;
typedef struct page_breaks {
int32 y_top;
int32 y_break;
} PageBreaks;
typedef struct LineRecord_struct LineRecord;
/*
** Used to store state needed while translation is in progress
*/
struct PrintInfo_ {
/*
** BEGIN SPECIAL
** If using the table print code, the following fields must
** be properly set up.
*/
int32 page_height; /* Size of printable area on page */
int32 page_width; /* Size of printable area on page */
int32 page_break; /* Current page bottom */
int32 page_topy; /* Current page top */
int phase;
/*
** CONTINUE SPECIAL
** The table print code maintains these
*/
PageBreaks *pages; /* Contains extents of each page */
int pt_size; /* Size of above table */
int n_pages; /* # of valid entries in above table */
/*
** END SPECIAL
*/
/*
** AAAOOOGAH
**
** These are used to cache values from the originating context's
** function table
*/
void (*scnatt)(MWContext*); /* SetCallNetlibAllTheTime */
void (*ccnatt)(MWContext*); /* CLearCallNetlibAllTheTime */
char* doc_title; /* best guess at title */
int32 doc_width; /* Total document width */
int32 doc_height; /* Total document height */
#ifdef LATER
float scale; /* for shrinking pre areas */
int32 pre_start; /* First y of current pre section */
int32 pre_end; /* Last y of current pre section */
XP_List *interesting; /* List of pre's about which I care */
XP_Bool in_pre; /* True when inside a <pre> section */
#endif
/*
** These fields are used only by the text translator
*/
char *line; /* Pointer to data for the current line */
XP_Bool in_table; /* True when caching lines in a table */
XP_Bool first_line_p; /* true when the first line has not yet been
output - this is a kludge for the mail
citation code. */
int table_top, /* Size of the table being cached */
table_bottom;
LineRecord *saved_lines; /* cached lines for tables */
int last_y; /* Used to track blank lines */
};
typedef struct PrintInfo_ PrintInfo;
/*
** Used to pass info into text and/or postscript translation
*/
struct PrintSetup_ {
int top; /* Margins (PostScript Only) */
int bottom;
int left;
int right;
int width; /* Paper size, # of cols for text xlate */
int height;
char* header;
char* footer;
int *sizes;
XP_Bool reverse; /* Output order */
XP_Bool color; /* Image output */
XP_Bool deep_color; /* 24 bit color output */
XP_Bool landscape; /* Rotated output */
XP_Bool underline; /* underline links */
XP_Bool scale_images; /* Scale unsized images which are too big */
XP_Bool scale_pre; /* do the pre-scaling thing */
float dpi; /* dpi for externally sized items */
float rules; /* Scale factor for rulers */
int n_up; /* cool page combining */
int bigger; /* Used to init sizes if sizesin NULL */
int paper_size; /* Paper Size(letter,legal,exec,a4) */
char* prefix; /* For text xlate, prepended to each line */
char* eol; /* For text translation, line terminator */
char* bullet; /* What char to use for bullets */
struct URL_Struct_ *url; /* url of doc being translated */
XP_File out; /* Where to send the output */
char *filename; /* output file name, if any */
XL_CompletionRoutine completion; /* Called when translation finished */
void* carg; /* Data saved for completion routine */
int status; /* Status of URL on completion */
/* "other" font is for encodings other than iso-8859-1 */
char *otherFontName[N_FONTS];
/* name of "other" PostScript font */
PS_FontInfo *otherFontInfo[N_FONTS];
/* font info parsed from "other" afm file */
int16 otherFontCharSetID; /* charset ID of "other" font */
//MWContext *cx; /* original context, if available */
};
typedef struct PrintSetup_ PrintSetup;
struct PSContext_{
char *url; /* URL of current document */
char * name; /* name of this context */
char * title; /* title (if supplied) of current document */
PrintSetup *prSetup; /* Info about print job */
PrintInfo *prInfo; /* State information for printing process */
};
typedef struct PSContext_ PSContext;
class nsPostScriptObj
{
public:
nsPostScriptObj();
~nsPostScriptObj();
/** ---------------------------------------------------
* Start a postscript page
* @update 2/1/99 dwc
*/
void begin_page();
/** ---------------------------------------------------
* end the current postscript page
* @update 2/1/99 dwc
*/
void end_page();
/** ---------------------------------------------------
* start the current document
* @update 2/1/99 dwc
*/
void begin_document();
/** ---------------------------------------------------
* end the current document
* @update 2/1/99 dwc
*/
void end_document();
/** ---------------------------------------------------
* move the cursor to this location
* @update 2/1/99 dwc
*/
void moveto(int aX, int aY);
/** ---------------------------------------------------
* move the cursor to this location
* @update 2/1/99 dwc
*/
void moveto_loc(int aX, int aY);
/** ---------------------------------------------------
* put down a line from the current cursor to the x and y location
* @update 2/1/99 dwc
*/
void lineto(int aX, int aY);
/** ---------------------------------------------------
* close the current postscript path, basically will return to the starting point
* @update 2/1/99 dwc
*/
void closepath();
/** ---------------------------------------------------
* create an elliptical path
* @update 2/1/99 dwc
* @param aWidth - Width of the ellipse
* @param aHeight - Height of the ellipse
*/
void ellipse(int aWidth, int aHeight);
/** ---------------------------------------------------
* create an elliptical path
* @update 2/1/99 dwc
* @param aWidth - Width of the ellipse
* @param aHeight - Height of the ellipse
*/
void arc(int aWidth, int aHeight,float aStartAngle,float aEndAngle);
/** ---------------------------------------------------
* create a retangular path
* @update 2/1/99 dwc
*/
void box(int aWidth, int aHeight);
/** ---------------------------------------------------
* create a retangular path, but winding the opposite way of a normal path, for clipping
* @update 2/1/99 dwc
*/
void box_subtract(int aWidth, int aHeight);
/** ---------------------------------------------------
* Draw a postscript line
* @update 2/1/99 dwc
*/
void line(int aX1, int aY1, int aX2, int aY2, int aThink);
/** ---------------------------------------------------
* strock the current path
* @update 2/1/99 dwc
*/
void stroke();
/** ---------------------------------------------------
* fill the current path
* @update 2/1/99 dwc
*/
void fill();
/** ---------------------------------------------------
* push the current graphics state onto the postscript stack
* @update 2/1/99 dwc
*/
void graphics_save();
/** ---------------------------------------------------
* pop the graphics state off of the postscript stack
* @update 2/1/99 dwc
*/
void graphics_restore();
/** ---------------------------------------------------
* output a color postscript image
* @update 2/1/99 dwc
*/
void colorimage(nsIImage *aImage,int aX, int aY, int aWidth, int aHeight);
/** ---------------------------------------------------
* ???
* @update 2/1/99 dwc
*/
void begin_squished_text( float aSqeeze);
/** ---------------------------------------------------
* ???
* @update 2/1/99 dwc
*/
void end_squished_text();
/** ---------------------------------------------------
* Get rid of data structures for the postscript
* @update 2/1/99 dwc
*/
void finalize_translation();
/** ---------------------------------------------------
* ???
* @update 2/1/99 dwc
*/
void annotate_page( char*, int, int, int);
/** ---------------------------------------------------
* translate the current coordinate system
* @update 2/1/99 dwc
*/
void translate(int aX, int aY);
/** ---------------------------------------------------
* Issue a PS show command, which causes image to be rastered
* @update 2/1/99 dwc
*/
void show(char* aText, int aLen, char *aAlign);
/** ---------------------------------------------------
* set the clipping path to the current path using the winding rule
* @update 2/1/99 dwc
*/
void clip();
/** ---------------------------------------------------
* set the clipping path to the current path using the even/odd rule
* @update 2/1/99 dwc
*/
void eoclip();
/** ---------------------------------------------------
* start a new path
* @update 2/1/99 dwc
*/
void newpath();
/** ---------------------------------------------------
* reset the current postsript clip path to the page
* @update 2/1/99 dwc
*/
void initclip();
/** ---------------------------------------------------
* make the current postscript path the current postscript clip path
* @update 2/1/99 dwc
*/
void clippath();
/** ---------------------------------------------------
* set the color
* @update 2/1/99 dwc
*/
void setcolor(nscolor aTheColor);
/** ---------------------------------------------------
* Set up the font
* @update 2/1/99 dwc
*/
void setscriptfont(nscoord aHeight, PRUint8 aStyle, PRUint8 aVariant, PRUint16 aWeight, PRUint8 decorations);
/** ---------------------------------------------------
* output a postscript comment
* @update 2/1/99 dwc
*/
void comment(char *aTheComment);
private:
PSContext *mPrintContext;
PrintSetup *mPrintSetup;
PRUint16 mPageNumber;
/** ---------------------------------------------------
* Set up the postscript
* @update 2/1/99 dwc
*/
void initialize_translation(PrintSetup* aPi);
};
#endif
/* -*- Mode: C; tab-width: 4; 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 _PSOBJ_H_
#define _PSOBJ_H_
#include "xp_core.h"
#include "xp_file.h"
#include "ntypes.h"
#include "net.h"
#include "nsColor.h"
#include "nsCoord.h"
class nsIImage;
#define NS_LETTER_SIZE 0
#define NS_LEGAL_SIZE 1
#define NS_EXECUTIVE_SIZE 2
#define PAGE_WIDTH 612 // Points
#define PAGE_HEIGHT 792 //Points
#define N_FONTS 8
#define INCH_TO_PAGE(f) ((int) (.5 + (f)*720))
#define PAGE_TO_POINT_I(f) ((int) ((f) / 10.0))
#define PAGE_TO_POINT_F(f) ((f) / 10.0)
#define POINT_TO_PAGE(p) ((p)*10)
typedef void (*XL_CompletionRoutine)(void*);
typedef struct {
short llx, lly, urx, ury;
} PS_BBox;
typedef struct {
short wx, wy;
PS_BBox charBBox;
} PS_CharInfo;
typedef struct {
char *name;
PS_BBox fontBBox;
short upos, uthick;
PS_CharInfo chars[256];
} PS_FontInfo;
typedef struct page_breaks {
int32 y_top;
int32 y_break;
} PageBreaks;
typedef struct LineRecord_struct LineRecord;
/*
** Used to store state needed while translation is in progress
*/
struct PrintInfo_ {
// for table printing
int32 page_height; // Size of printable area on page
int32 page_width; // Size of printable area on page
int32 page_break; // Current page bottom
int32 page_topy; // Current page top
int phase;
PageBreaks *pages; // Contains extents of each page
int pt_size; // Size of above table
int n_pages; // # of valid entries in above table
void (*scnatt)(MWContext*); // SetCallNetlibAllTheTime
void (*ccnatt)(MWContext*); // CLearCallNetlibAllTheTime
char* doc_title; // best guess at title
int32 doc_width; // Total document width
int32 doc_height; // Total document height
#ifdef LATER
THIS IS GOING TO BE DELETED XXXXX
float scale;
int32 pre_start;
int32 pre_end;
XP_List *interesting;
XP_Bool in_pre;
#endif
// These fields are used only by the text translator
char *line; // Pointer to data for the current line
XP_Bool in_table; // True when caching lines in a table
XP_Bool first_line_p; // delete all this
int table_top,table_bottom;
LineRecord *saved_lines; // cached lines for tables
int last_y; // Used to track blank lines
};
typedef struct PrintInfo_ PrintInfo;
/*
** Used to pass info into text and/or postscript translation
*/
struct PrintSetup_ {
int top; // Margins (PostScript Only)
int bottom;
int left;
int right;
int width; // Paper size, # of cols for text xlate
int height;
char* header;
char* footer;
int *sizes;
XP_Bool reverse; // Output order
XP_Bool color; // Image output
XP_Bool deep_color; // 24 bit color output
XP_Bool landscape; // Rotated output
XP_Bool underline; // underline links
XP_Bool scale_images; // Scale unsized images which are too big
XP_Bool scale_pre; // do the pre-scaling thing
float dpi; // dpi for externally sized items
float rules; // Scale factor for rulers
int n_up; // cool page combining
int bigger; // Used to init sizes if sizesin NULL
int paper_size; // Paper Size(letter,legal,exec,a4)
char* prefix; // For text xlate, prepended to each line
char* eol; // For text translation, line terminator
char* bullet; // What char to use for bullets
struct URL_Struct_ *url; // url of doc being translated
XP_File out; // Where to send the output
char *filename; // output file name, if any
XL_CompletionRoutine completion; // Called when translation finished
void* carg; // Data saved for completion routine
int status; // Status of URL on completion
// "other" font is for encodings other than iso-8859-1
char *otherFontName[N_FONTS];
// name of "other" PostScript font
PS_FontInfo *otherFontInfo[N_FONTS];
// font info parsed from "other" afm file
int16 otherFontCharSetID; // charset ID of "other" font
};
typedef struct PrintSetup_ PrintSetup;
struct PSContext_{
char *url; // URL of current document
char * name; // name of this context
char * title; // title (if supplied) of current document
PrintSetup *prSetup; // Info about print job
PrintInfo *prInfo; // State information for printing process
};
typedef struct PSContext_ PSContext;
class nsPostScriptObj
{
public:
nsPostScriptObj();
~nsPostScriptObj();
/** ---------------------------------------------------
* Start a postscript page
* @update 2/1/99 dwc
*/
void begin_page();
/** ---------------------------------------------------
* end the current postscript page
* @update 2/1/99 dwc
*/
void end_page();
/** ---------------------------------------------------
* start the current document
* @update 2/1/99 dwc
*/
void begin_document();
/** ---------------------------------------------------
* end the current document
* @update 2/1/99 dwc
*/
void end_document();
/** ---------------------------------------------------
* move the cursor to this location
* @update 2/1/99 dwc
*/
void moveto(int aX, int aY);
/** ---------------------------------------------------
* move the cursor to this location
* @update 2/1/99 dwc
*/
void moveto_loc(int aX, int aY);
/** ---------------------------------------------------
* put down a line from the current cursor to the x and y location
* @update 2/1/99 dwc
*/
void lineto(int aX, int aY);
/** ---------------------------------------------------
* close the current postscript path, basically will return to the starting point
* @update 2/1/99 dwc
*/
void closepath();
/** ---------------------------------------------------
* create an elliptical path
* @update 2/1/99 dwc
* @param aWidth - Width of the ellipse
* @param aHeight - Height of the ellipse
*/
void ellipse(int aWidth, int aHeight);
/** ---------------------------------------------------
* create an elliptical path
* @update 2/1/99 dwc
* @param aWidth - Width of the ellipse
* @param aHeight - Height of the ellipse
*/
void arc(int aWidth, int aHeight,float aStartAngle,float aEndAngle);
/** ---------------------------------------------------
* create a retangular path
* @update 2/1/99 dwc
*/
void box(int aWidth, int aHeight);
/** ---------------------------------------------------
* create a retangular path, but winding the opposite way of a normal path, for clipping
* @update 2/1/99 dwc
*/
void box_subtract(int aWidth, int aHeight);
/** ---------------------------------------------------
* Draw a postscript line
* @update 2/1/99 dwc
*/
void line(int aX1, int aY1, int aX2, int aY2, int aThink);
/** ---------------------------------------------------
* strock the current path
* @update 2/1/99 dwc
*/
void stroke();
/** ---------------------------------------------------
* fill the current path
* @update 2/1/99 dwc
*/
void fill();
/** ---------------------------------------------------
* push the current graphics state onto the postscript stack
* @update 2/1/99 dwc
*/
void graphics_save();
/** ---------------------------------------------------
* pop the graphics state off of the postscript stack
* @update 2/1/99 dwc
*/
void graphics_restore();
/** ---------------------------------------------------
* output a color postscript image
* @update 2/1/99 dwc
*/
void colorimage(nsIImage *aImage,int aX, int aY, int aWidth, int aHeight);
/** ---------------------------------------------------
* ???
* @update 2/1/99 dwc
*/
void begin_squished_text( float aSqeeze);
/** ---------------------------------------------------
* ???
* @update 2/1/99 dwc
*/
void end_squished_text();
/** ---------------------------------------------------
* Get rid of data structures for the postscript
* @update 2/1/99 dwc
*/
void finalize_translation();
/** ---------------------------------------------------
* ???
* @update 2/1/99 dwc
*/
void annotate_page( char*, int, int, int);
/** ---------------------------------------------------
* translate the current coordinate system
* @update 2/1/99 dwc
*/
void translate(int aX, int aY);
/** ---------------------------------------------------
* Issue a PS show command, which causes image to be rastered
* @update 2/1/99 dwc
*/
void show(char* aText, int aLen, char *aAlign);
/** ---------------------------------------------------
* set the clipping path to the current path using the winding rule
* @update 2/1/99 dwc
*/
void clip();
/** ---------------------------------------------------
* set the clipping path to the current path using the even/odd rule
* @update 2/1/99 dwc
*/
void eoclip();
/** ---------------------------------------------------
* start a new path
* @update 2/1/99 dwc
*/
void newpath();
/** ---------------------------------------------------
* reset the current postsript clip path to the page
* @update 2/1/99 dwc
*/
void initclip();
/** ---------------------------------------------------
* make the current postscript path the current postscript clip path
* @update 2/1/99 dwc
*/
void clippath();
/** ---------------------------------------------------
* set the color
* @update 2/1/99 dwc
*/
void setcolor(nscolor aTheColor);
/** ---------------------------------------------------
* Set up the font
* @update 2/1/99 dwc
*/
void setscriptfont(nscoord aHeight, PRUint8 aStyle, PRUint8 aVariant, PRUint16 aWeight, PRUint8 decorations);
/** ---------------------------------------------------
* output a postscript comment
* @update 2/1/99 dwc
*/
void comment(char *aTheComment);
private:
PSContext *mPrintContext;
PrintSetup *mPrintSetup;
PRUint16 mPageNumber;
/** ---------------------------------------------------
* Set up the postscript
* @update 2/1/99 dwc
*/
void initialize_translation(PrintSetup* aPi);
};
#endif