mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-03 20:49:27 +00:00
Took out files no longer needed for ps, updated all the files for postscript support
This commit is contained in:
parent
1f5e2a6a7b
commit
2e243d1ebe
@ -1,55 +0,0 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
/*
|
||||
** The names of the characters in the ISO Latin1 set.
|
||||
** Index into this array is the encoding for that character
|
||||
*/
|
||||
char *isotab[256] = {
|
||||
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
|
||||
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "space",
|
||||
"exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand",
|
||||
"quoteright", "parenleft", "parenright", "asterisk", "plus", "comma",
|
||||
"hyphen", "period", "slash", "zero", "one", "two", "three", "four",
|
||||
"five", "six", "seven", "eight", "nine", "colon", "semicolon", "less",
|
||||
"equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F",
|
||||
"G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
|
||||
"U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash",
|
||||
"bracketright", "asciicircum", "underscore", "quoteleft", "a", "b",
|
||||
"c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p",
|
||||
"q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar",
|
||||
"braceright", "asciitilde", "", "", "", "", "", "", "", "", "", "", "", "",
|
||||
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
|
||||
"", "", "", "space", "exclamdown", "cent", "sterling", "currency",
|
||||
"yen", "brokenbar", "section", "dieresis", "copyright", "ordfeminine",
|
||||
"guillemotleft", "logicalnot", "hyphen", "registered", "macron",
|
||||
"degree", "plusminus", "twosuperior", "threesuperior", "acute", "mu",
|
||||
"paragraph", "periodcentered", "cedilla", "onesuperior",
|
||||
"ordmasculine", "guillemotright", "onequarter", "onehalf",
|
||||
"threequarters", "questiondown", "Agrave", "Aacute", "Acircumflex",
|
||||
"Atilde", "Adieresis", "Aring", "AE", "Ccedilla", "Egrave", "Eacute",
|
||||
"Ecircumflex", "Edieresis", "Igrave", "Iacute", "Icircumflex",
|
||||
"Idieresis", "Eth", "Ntilde", "Ograve", "Oacute", "Ocircumflex",
|
||||
"Otilde", "Odieresis", "multiply", "Oslash", "Ugrave", "Uacute",
|
||||
"Ucircumflex", "Udieresis", "Yacute", "Thorn", "germandbls", "agrave",
|
||||
"aacute", "acircumflex", "atilde", "adieresis", "aring", "ae",
|
||||
"ccedilla", "egrave", "eacute", "ecircumflex", "edieresis", "igrave",
|
||||
"iacute", "icircumflex", "idieresis", "eth", "ntilde", "ograve",
|
||||
"oacute", "ocircumflex", "otilde", "odieresis", "divide", "oslash",
|
||||
"ugrave", "uacute", "ucircumflex", "udieresis", "yacute", "thorn",
|
||||
"ydieresis"
|
||||
};
|
@ -16,432 +16,373 @@
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsDeviceContextWin.h"
|
||||
#include "nsRenderingContextWin.h"
|
||||
#include "nsDeviceContextSpecWin.h"
|
||||
#include "il_util.h"
|
||||
#include "nsDeviceContextPS.h"
|
||||
#include "nsRenderingContextPS.h"
|
||||
#include "nsDeviceContextSpecPS.h"
|
||||
#include "nsString.h"
|
||||
|
||||
// Size of the color cube
|
||||
#define COLOR_CUBE_SIZE 216
|
||||
#include "prprf.h"
|
||||
#include "nsPSUtil.h"
|
||||
#include "nsPrintManager.h"
|
||||
#include "xlate.h"
|
||||
|
||||
nsDeviceContextWin :: nsDeviceContextWin()
|
||||
: DeviceContextImpl()
|
||||
static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID);
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
nsDeviceContextPS :: nsDeviceContextPS()
|
||||
{
|
||||
mSurface = NULL;
|
||||
mPaletteInfo.isPaletteDevice = PR_FALSE;
|
||||
mPaletteInfo.sizePalette = 0;
|
||||
mPaletteInfo.numReserved = 0;
|
||||
mPaletteInfo.palette = NULL;
|
||||
mDC = NULL;
|
||||
mPixelScale = 1.0f;
|
||||
mWidthFloat = 0.0f;
|
||||
mHeightFloat = 0.0f;
|
||||
mWidth = -1;
|
||||
mHeight = -1;
|
||||
|
||||
NS_INIT_REFCNT();
|
||||
mSpec = nsnull;
|
||||
}
|
||||
|
||||
nsDeviceContextWin :: ~nsDeviceContextWin()
|
||||
{
|
||||
nsDrawingSurfaceWin *surf = (nsDrawingSurfaceWin *)mSurface;
|
||||
|
||||
NS_IF_RELEASE(surf); //this clears the surf pointer...
|
||||
mSurface = nsnull;
|
||||
|
||||
if (NULL != mPaletteInfo.palette)
|
||||
::DeleteObject((HPALETTE)mPaletteInfo.palette);
|
||||
|
||||
if (NULL != mDC)
|
||||
{
|
||||
::DeleteDC(mDC);
|
||||
mDC = NULL;
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(mSpec);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextWin :: Init(nsNativeWidget aWidget)
|
||||
{
|
||||
HWND hwnd = (HWND)aWidget;
|
||||
HDC hdc = ::GetDC(hwnd);
|
||||
|
||||
CommonInit(hdc);
|
||||
|
||||
::ReleaseDC(hwnd, hdc);
|
||||
|
||||
return DeviceContextImpl::Init(aWidget);
|
||||
}
|
||||
|
||||
//local method...
|
||||
|
||||
nsresult nsDeviceContextWin :: Init(nsNativeDeviceContext aContext, nsIDeviceContext *aOrigContext)
|
||||
{
|
||||
float origscale, newscale;
|
||||
float t2d, a2d;
|
||||
|
||||
mDC = (HDC)aContext;
|
||||
|
||||
CommonInit(mDC);
|
||||
|
||||
GetTwipsToDevUnits(newscale);
|
||||
aOrigContext->GetTwipsToDevUnits(origscale);
|
||||
|
||||
mPixelScale = newscale / origscale;
|
||||
|
||||
aOrigContext->GetTwipsToDevUnits(t2d);
|
||||
aOrigContext->GetAppUnitsToDevUnits(a2d);
|
||||
|
||||
mAppUnitsToDevUnits = (a2d / t2d) * mTwipsToPixels;
|
||||
mDevUnitsToAppUnits = 1.0f / mAppUnitsToDevUnits;
|
||||
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
nsDeviceContextPS :: ~nsDeviceContextPS()
|
||||
{
|
||||
}
|
||||
|
||||
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(nsNativeWidget aNativeWidget)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsDeviceContextWin :: CommonInit(HDC aDC)
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS :: CreateRenderingContext(nsIRenderingContext *&aContext)
|
||||
{
|
||||
int rasterCaps = ::GetDeviceCaps(aDC, RASTERCAPS);
|
||||
nsIRenderingContext *pContext;
|
||||
nsresult rv;
|
||||
//GrafPtr thePort;
|
||||
|
||||
mTwipsToPixels = ((float)::GetDeviceCaps(aDC, LOGPIXELSY)) / (float)NSIntPointsToTwips(72);
|
||||
mPixelsToTwips = 1.0f / mTwipsToPixels;
|
||||
|
||||
mDepth = (PRUint32)::GetDeviceCaps(aDC, BITSPIXEL);
|
||||
mPaletteInfo.isPaletteDevice = RC_PALETTE == (rasterCaps & RC_PALETTE);
|
||||
mPaletteInfo.sizePalette = (PRUint8)::GetDeviceCaps(aDC, SIZEPALETTE);
|
||||
mPaletteInfo.numReserved = (PRUint8)::GetDeviceCaps(aDC, NUMRESERVED);
|
||||
|
||||
mWidthFloat = (float)::GetDeviceCaps(aDC, HORZRES);
|
||||
mHeightFloat = (float)::GetDeviceCaps(aDC, VERTRES);
|
||||
|
||||
DeviceContextImpl::CommonInit();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextWin :: CreateRenderingContext(nsIRenderingContext *&aContext)
|
||||
{
|
||||
nsIRenderingContext *pContext;
|
||||
nsresult rv;
|
||||
nsDrawingSurfaceWin *surf;
|
||||
|
||||
pContext = new nsRenderingContextWin();
|
||||
|
||||
if (nsnull != pContext)
|
||||
{
|
||||
pContext = new nsRenderingContextPS();
|
||||
if (nsnull != pContext){
|
||||
NS_ADDREF(pContext);
|
||||
|
||||
surf = new nsDrawingSurfaceWin();
|
||||
//::GetPort(&thePort);
|
||||
|
||||
if (nsnull != surf)
|
||||
{
|
||||
rv = surf->Init(mDC);
|
||||
|
||||
if (NS_OK == rv)
|
||||
rv = pContext->Init(this, surf);
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
//if (nsnull != thePort){
|
||||
rv = pContext->Init(this,(nsDrawingSurface)nsnull);
|
||||
//}
|
||||
//else
|
||||
//rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (NS_OK != rv)
|
||||
{
|
||||
if (NS_OK != rv){
|
||||
NS_IF_RELEASE(pContext);
|
||||
}
|
||||
|
||||
aContext = pContext;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextWin :: SupportsNativeWidgets(PRBool &aSupportsWidgets)
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS :: SupportsNativeWidgets(PRBool &aSupportsWidgets)
|
||||
{
|
||||
if (nsnull == mDC)
|
||||
aSupportsWidgets = PR_TRUE;
|
||||
else
|
||||
aSupportsWidgets = PR_FALSE;
|
||||
|
||||
aSupportsWidgets = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextWin :: GetCanonicalPixelScale(float &aScale) const
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS :: GetScrollBarDimensions(float &aWidth, float &aHeight) const
|
||||
{
|
||||
aScale = mPixelScale;
|
||||
// XXX Should we push this to widget library
|
||||
aWidth = 320.0;
|
||||
aHeight = 320.0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextWin :: GetScrollBarDimensions(float &aWidth, float &aHeight) const
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS :: GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface)
|
||||
{
|
||||
aWidth = ::GetSystemMetrics(SM_CXVSCROLL) * mDevUnitsToAppUnits;
|
||||
aHeight = ::GetSystemMetrics(SM_CXHSCROLL) * mDevUnitsToAppUnits;
|
||||
return NS_OK;
|
||||
aContext.CreateDrawingSurface(nsnull, 0, aSurface);
|
||||
return nsnull == aSurface ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextWin :: GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface)
|
||||
{
|
||||
if (NULL == mSurface) {
|
||||
aContext.CreateDrawingSurface(nsnull, 0, mSurface);
|
||||
}
|
||||
|
||||
aSurface = mSurface;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
int CALLBACK fontcallback(ENUMLOGFONT FAR *lpelf, NEWTEXTMETRIC FAR *lpntm,
|
||||
int FontType, LPARAM lParam)
|
||||
{
|
||||
if (NULL != lpelf)
|
||||
*((PRBool *)lParam) = PR_TRUE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextWin :: CheckFontExistence(const nsString& aFontName)
|
||||
{
|
||||
HWND hwnd = (HWND)mWidget;
|
||||
HDC hdc = ::GetDC(hwnd);
|
||||
PRBool isthere = PR_FALSE;
|
||||
|
||||
char fontName[LF_FACESIZE];
|
||||
aFontName.ToCString(fontName, LF_FACESIZE);
|
||||
::EnumFontFamilies(hdc, fontName, (FONTENUMPROC)fontcallback, (LPARAM)&isthere);
|
||||
|
||||
::ReleaseDC(hwnd, hdc);
|
||||
|
||||
if (PR_TRUE == isthere)
|
||||
return NS_OK;
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextWin::GetDepth(PRUint32& aDepth)
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS::GetDepth(PRUint32& aDepth)
|
||||
{
|
||||
aDepth = mDepth;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextWin::GetILColorSpace(IL_ColorSpace*& aColorSpace)
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS::CreateILColorSpace(IL_ColorSpace*& aColorSpace)
|
||||
{
|
||||
if (nsnull == mColorSpace) {
|
||||
// See if we're dealing with an 8-bit palette device
|
||||
if ((8 == mDepth) && mPaletteInfo.isPaletteDevice) {
|
||||
// Create a color cube. We want to use DIB_PAL_COLORS because it's faster
|
||||
// than DIB_RGB_COLORS, so make sure the indexes match that of the
|
||||
// GDI physical palette
|
||||
//
|
||||
// Note: the image library doesn't use the reserved colors, so it doesn't
|
||||
// matter what they're set to...
|
||||
IL_RGB reserved[10];
|
||||
memset(reserved, 0, sizeof(reserved));
|
||||
IL_ColorMap* colorMap = IL_NewCubeColorMap(reserved, 10, COLOR_CUBE_SIZE + 10);
|
||||
if (nsnull == colorMap) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// Create a pseudo color space
|
||||
mColorSpace = IL_CreatePseudoColorSpace(colorMap, 8, 8);
|
||||
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
nsresult result = NS_OK;
|
||||
return result;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS::GetILColorSpace(IL_ColorSpace*& aColorSpace)
|
||||
{
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the color space
|
||||
aColorSpace = mColorSpace;
|
||||
IL_AddRefToColorSpace(aColorSpace);
|
||||
//NS_POSTCONDITION(nsnull != mColorSpace, "null color space");
|
||||
//aColorSpace = mColorSpace;
|
||||
//IL_AddRefToColorSpace(aColorSpace);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextWin::GetPaletteInfo(nsPaletteInfo& aPaletteInfo)
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS :: CheckFontExistence(const nsString& aFontName)
|
||||
{
|
||||
aPaletteInfo.isPaletteDevice = mPaletteInfo.isPaletteDevice;
|
||||
aPaletteInfo.sizePalette = mPaletteInfo.sizePalette;
|
||||
aPaletteInfo.numReserved = mPaletteInfo.numReserved;
|
||||
#ifdef NEVER
|
||||
short fontNum;
|
||||
if (GetMacFontNumber(aFontName, fontNum))
|
||||
return NS_OK;
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
#endif
|
||||
|
||||
if (NULL == mPaletteInfo.palette) {
|
||||
IL_ColorSpace* colorSpace;
|
||||
GetILColorSpace(colorSpace);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (NI_PseudoColor == colorSpace->type) {
|
||||
// Create a logical palette
|
||||
BYTE tmp[sizeof(LOGPALETTE) + ((COLOR_CUBE_SIZE + 20) * sizeof(PALETTEENTRY))];
|
||||
LPLOGPALETTE logPal = (LPLOGPALETTE)tmp;
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight)
|
||||
{
|
||||
aWidth = 1;
|
||||
aHeight = 1;
|
||||
|
||||
logPal->palVersion = 0x300;
|
||||
logPal->palNumEntries = COLOR_CUBE_SIZE + 20;
|
||||
|
||||
// Initialize it from the default Windows palette
|
||||
HPALETTE hDefaultPalette = (HPALETTE)::GetStockObject(DEFAULT_PALETTE);
|
||||
|
||||
// First ten system colors
|
||||
::GetPaletteEntries(hDefaultPalette, 0, 10, logPal->palPalEntry);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Last ten system colors
|
||||
::GetPaletteEntries(hDefaultPalette, 10, 10, &logPal->palPalEntry[COLOR_CUBE_SIZE + 10]);
|
||||
|
||||
// Now set the color cube entries.
|
||||
PALETTEENTRY* entry = &logPal->palPalEntry[10];
|
||||
NI_RGB* map = colorSpace->cmap.map + 10;
|
||||
for (PRInt32 i = 0; i < COLOR_CUBE_SIZE; i++) {
|
||||
entry->peRed = map->red;
|
||||
entry->peGreen = map->green;
|
||||
entry->peBlue = map->blue;
|
||||
entry->peFlags = 0;
|
||||
|
||||
entry++;
|
||||
map++;
|
||||
}
|
||||
|
||||
// Create a GDI palette
|
||||
mPaletteInfo.palette = ::CreatePalette(logPal);
|
||||
}
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS::GetDeviceContextFor(nsIDeviceContextSpec *aDevice,nsIDeviceContext *&aContext)
|
||||
{
|
||||
|
||||
IL_ReleaseColorSpace(colorSpace);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS::BeginDocument(void)
|
||||
{
|
||||
PrintInfo* pi = new PrintInfo();
|
||||
PrintSetup* ps = new PrintSetup();
|
||||
|
||||
//XXX:PS Get rid of the need for a MWContext
|
||||
mPrintContext = new MWContext();
|
||||
memset(mPrintContext, 0, sizeof(struct MWContext_));
|
||||
memset(ps, 0, sizeof(struct PrintSetup_));
|
||||
memset(pi, 0, sizeof(struct PrintInfo_));
|
||||
|
||||
ps->top = 0; /* Margins (PostScript Only) */
|
||||
ps->bottom = 0;
|
||||
ps->left = 0;
|
||||
ps->right = 0;
|
||||
ps->width = PAGE_WIDTH; /* Paper size, # of cols for text xlate */
|
||||
ps->height = PAGE_HEIGHT;
|
||||
ps->header = "header";
|
||||
ps->footer = "footer";
|
||||
ps->sizes = NULL;
|
||||
ps->reverse = 1; /* Output order */
|
||||
ps->color = TRUE; /* Image output */
|
||||
ps->deep_color = TRUE; /* 24 bit color output */
|
||||
ps->landscape = FALSE; /* Rotated output */
|
||||
ps->underline = TRUE; /* underline links */
|
||||
ps->scale_images = TRUE; /* Scale unsized images which are too big */
|
||||
ps->scale_pre = FALSE; /* do the pre-scaling thing */
|
||||
ps->dpi = 72.0f; /* dpi for externally sized items */
|
||||
ps->rules = 1.0f; /* Scale factor for rulers */
|
||||
ps->n_up = 0; /* cool page combining */
|
||||
ps->bigger = 1; /* Used to init sizes if sizesin NULL */
|
||||
ps->paper_size = NS_LEGAL_SIZE; /* Paper Size(letter,legal,exec,a4) */
|
||||
ps->prefix = ""; /* For text xlate, prepended to each line */
|
||||
ps->eol = ""; /* For text translation, line terminator */
|
||||
ps->bullet = "+"; /* What char to use for bullets */
|
||||
|
||||
URL_Struct_* url = new URL_Struct_;
|
||||
memset(url, 0, sizeof(URL_Struct_));
|
||||
ps->url = url; /* url of doc being translated */
|
||||
char filename[30];
|
||||
static char g_nsPostscriptFileCount = 0; //('a');
|
||||
char ext[30];
|
||||
sprintf(ext,"%d",g_nsPostscriptFileCount);
|
||||
sprintf(filename,"file%s.ps", ext);
|
||||
g_nsPostscriptFileCount++;
|
||||
ps->out = fopen(filename , "w"); /* Where to send the output */
|
||||
ps->filename = filename; /* output file name, if any */
|
||||
ps->completion = NULL; /* Called when translation finished */
|
||||
ps->carg = NULL; /* Data saved for completion routine */
|
||||
ps->status = 0; /* Status of URL on completion */
|
||||
/* "other" font is for encodings other than iso-8859-1 */
|
||||
ps->otherFontName[0] = NULL;
|
||||
/* name of "other" PostScript font */
|
||||
ps->otherFontInfo[0] = NULL;
|
||||
/* font info parsed from "other" afm file */
|
||||
ps->otherFontCharSetID = 0; /* charset ID of "other" font */
|
||||
ps->cx = NULL; /* original context, if available */
|
||||
|
||||
pi->page_height = PAGE_HEIGHT * 10; /* Size of printable area on page */
|
||||
pi->page_width = PAGE_WIDTH * 10; /* Size of printable area on page */
|
||||
pi->page_break = 0; /* Current page bottom */
|
||||
pi->page_topy = 0; /* Current page top */
|
||||
pi->phase = 0;
|
||||
/*
|
||||
** CONTINUE SPECIAL
|
||||
** The table print code maintains these
|
||||
*/
|
||||
|
||||
pi->pages=NULL; /* Contains extents of each page */
|
||||
|
||||
pi->pt_size = 0; /* Size of above table */
|
||||
pi->n_pages = 0; /* # of valid entries in above table */
|
||||
/*
|
||||
** END SPECIAL
|
||||
*/
|
||||
|
||||
pi->doc_title="Test Title"; /* best guess at title */
|
||||
pi->doc_width = 0; /* Total document width */
|
||||
pi->doc_height = 0; /* Total document height */
|
||||
|
||||
mPrintContext->prInfo = pi;
|
||||
|
||||
// begin the document
|
||||
xl_initialize_translation(mPrintContext, ps);
|
||||
xl_begin_document(mPrintContext);
|
||||
mPrintSetup = ps;
|
||||
|
||||
// begin the page
|
||||
xl_begin_page(mPrintContext, 1);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS::EndDocument(void)
|
||||
{
|
||||
// end the page
|
||||
xl_end_page(mPrintContext, 1);
|
||||
|
||||
// end the document
|
||||
xl_end_document(mPrintContext);
|
||||
xl_finalize_translation(mPrintContext);
|
||||
|
||||
// Cleanup things allocated along the way
|
||||
if (nsnull != mPrintContext){
|
||||
if (nsnull != mPrintContext->prInfo)
|
||||
delete mPrintContext->prInfo;
|
||||
|
||||
if (nsnull != mPrintContext->prSetup)
|
||||
delete mPrintContext->prSetup;
|
||||
|
||||
delete mPrintContext;
|
||||
}
|
||||
|
||||
aPaletteInfo.palette = mPaletteInfo.palette;
|
||||
if (nsnull != mPrintSetup)
|
||||
delete mPrintSetup;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextWin :: ConvertPixel(nscolor aColor, PRUint32 & aPixel)
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS::BeginPage(void)
|
||||
{
|
||||
#ifdef NEVER
|
||||
if(((nsDeviceContextSpecPS*)(this->mSpec))->mPrintManagerOpen)
|
||||
::PrOpenPage(((nsDeviceContextSpecPS*)(this->mSpec))->mPrinterPort,nsnull);
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
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
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS :: ConvertPixel(nscolor aColor, PRUint32 & aPixel)
|
||||
{
|
||||
aPixel = aColor;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextWin :: GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight)
|
||||
{
|
||||
if (mWidth == -1)
|
||||
mWidth = NSToIntRound(mWidthFloat * mDevUnitsToAppUnits);
|
||||
|
||||
if (mHeight == -1)
|
||||
mHeight = NSToIntRound(mHeightFloat * mDevUnitsToAppUnits);
|
||||
|
||||
aWidth = mWidth;
|
||||
aHeight = mHeight;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
BOOL CALLBACK abortproc( HDC hdc, int iError )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextWin :: GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
|
||||
nsIDeviceContext *&aContext)
|
||||
{
|
||||
char *devicename;
|
||||
char *drivername;
|
||||
HGLOBAL hdevmode;
|
||||
DEVMODE *devmode;
|
||||
|
||||
//XXX this API should take an CID, use the repository and
|
||||
//then QI for the real object rather than casting... MMP
|
||||
|
||||
aContext = new nsDeviceContextWin();
|
||||
|
||||
((nsDeviceContextWin *)aContext)->mSpec = aDevice;
|
||||
NS_ADDREF(aDevice);
|
||||
|
||||
((nsDeviceContextSpecWin *)aDevice)->GetDeviceName(devicename);
|
||||
((nsDeviceContextSpecWin *)aDevice)->GetDriverName(drivername);
|
||||
((nsDeviceContextSpecWin *)aDevice)->GetDEVMODE(hdevmode);
|
||||
|
||||
devmode = (DEVMODE *)::GlobalLock(hdevmode);
|
||||
HDC dc = ::CreateDC(drivername, devicename, NULL, devmode);
|
||||
|
||||
// ::SetAbortProc(dc, (ABORTPROC)abortproc);
|
||||
|
||||
::GlobalUnlock(hdevmode);
|
||||
|
||||
return ((nsDeviceContextWin *)aContext)->Init(dc, this);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextWin :: BeginDocument(void)
|
||||
{
|
||||
if (NULL != mDC)
|
||||
{
|
||||
DOCINFO docinfo;
|
||||
|
||||
docinfo.cbSize = sizeof(docinfo);
|
||||
docinfo.lpszDocName = "New Layout Document";
|
||||
docinfo.lpszOutput = NULL;
|
||||
docinfo.lpszDatatype = NULL;
|
||||
docinfo.fwType = 0;
|
||||
|
||||
HGLOBAL hdevmode;
|
||||
DEVMODE *devmode;
|
||||
|
||||
//XXX need to QI rather than cast... MMP
|
||||
|
||||
((nsDeviceContextSpecWin *)mSpec)->GetDEVMODE(hdevmode);
|
||||
|
||||
devmode = (DEVMODE *)::GlobalLock(hdevmode);
|
||||
|
||||
// ::ResetDC(mDC, devmode);
|
||||
|
||||
::GlobalUnlock(hdevmode);
|
||||
|
||||
if (::StartDoc(mDC, &docinfo) > 0)
|
||||
return NS_OK;
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextWin :: EndDocument(void)
|
||||
{
|
||||
if (NULL != mDC)
|
||||
{
|
||||
if (::EndDoc(mDC) > 0)
|
||||
return NS_OK;
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextWin :: BeginPage(void)
|
||||
{
|
||||
if (NULL != mDC)
|
||||
{
|
||||
if (::StartPage(mDC) > 0)
|
||||
return NS_OK;
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextWin :: EndPage(void)
|
||||
{
|
||||
if (NULL != mDC)
|
||||
{
|
||||
if (::EndPage(mDC) > 0)
|
||||
return NS_OK;
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -16,71 +16,72 @@
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsDeviceContextWin_h___
|
||||
#define nsDeviceContextWin_h___
|
||||
#ifndef nsDeviceContextPS_h___
|
||||
#define nsDeviceContextPS_h___
|
||||
|
||||
#include "nsDeviceContext.h"
|
||||
#include <windows.h>
|
||||
#include "nsUnitConversion.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIView.h"
|
||||
#include "nsIRenderingContext.h"
|
||||
#include "nsPrintManager.h"
|
||||
|
||||
class nsDeviceContextWin : public DeviceContextImpl
|
||||
|
||||
class nsDeviceContextPS : public DeviceContextImpl
|
||||
{
|
||||
public:
|
||||
nsDeviceContextWin();
|
||||
nsDeviceContextPS();
|
||||
|
||||
NS_IMETHOD Init(nsNativeWidget aWidget);
|
||||
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(nsNativeWidget aNativeWidget);
|
||||
|
||||
NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext);
|
||||
|
||||
NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets);
|
||||
|
||||
NS_IMETHOD GetCanonicalPixelScale(float &aScale) const;
|
||||
|
||||
NS_IMETHOD GetScrollBarDimensions(float &aWidth, float &aHeight) const;
|
||||
|
||||
//get a low level drawing surface for rendering. the rendering context
|
||||
//that is passed in is used to create the drawing surface if there isn't
|
||||
//already one in the device context. the drawing surface is then cached
|
||||
//in the device context for re-use.
|
||||
void SetDrawingSurface(nsDrawingSurface aSurface) { mSurface = aSurface; }
|
||||
NS_IMETHOD GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface);
|
||||
|
||||
NS_IMETHOD CheckFontExistence(const nsString& aFontName);
|
||||
|
||||
NS_IMETHOD GetDepth(PRUint32& aDepth);
|
||||
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 GetILColorSpace(IL_ColorSpace*& aColorSpace);
|
||||
NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight);
|
||||
|
||||
NS_IMETHOD GetPaletteInfo(nsPaletteInfo&);
|
||||
|
||||
NS_IMETHOD ConvertPixel(nscolor aColor, PRUint32 & aPixel);
|
||||
|
||||
NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight);
|
||||
|
||||
NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
|
||||
NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
|
||||
nsIDeviceContext *&aContext);
|
||||
|
||||
NS_IMETHOD BeginDocument(void);
|
||||
NS_IMETHOD EndDocument(void);
|
||||
NS_IMETHOD BeginDocument(void);
|
||||
NS_IMETHOD EndDocument(void);
|
||||
|
||||
NS_IMETHOD BeginPage(void);
|
||||
NS_IMETHOD EndPage(void);
|
||||
|
||||
NS_IMETHOD BeginPage(void);
|
||||
NS_IMETHOD EndPage(void);
|
||||
|
||||
protected:
|
||||
virtual ~nsDeviceContextWin();
|
||||
void CommonInit(HDC aDC);
|
||||
nsresult Init(nsNativeDeviceContext aContext, nsIDeviceContext *aOrigContext);
|
||||
|
||||
nsDrawingSurface mSurface;
|
||||
PRUint32 mDepth; // bit depth of device
|
||||
nsPaletteInfo mPaletteInfo;
|
||||
float mPixelScale;
|
||||
float mWidthFloat;
|
||||
float mHeightFloat;
|
||||
PRInt32 mWidth;
|
||||
PRInt32 mHeight;
|
||||
virtual ~nsDeviceContextPS();
|
||||
|
||||
nsDrawingSurface mSurface;
|
||||
PRUint32 mDepth;
|
||||
MWContext *mPrintContext; //XXX: Remove need for MWContext
|
||||
nsIDeviceContextSpec *mSpec;
|
||||
PrintSetup *mPrintSetup;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
HDC mDC;
|
||||
static bool GetMacFontNumber(const nsString& aFontName, short &fontNum);
|
||||
MWContext* GetPrintContext() { return mPrintContext; }
|
||||
};
|
||||
|
||||
#endif /* nsDeviceContextWin_h___ */
|
||||
#endif /* nsDeviceContextMac_h___ */
|
||||
|
@ -16,18 +16,18 @@
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsDeviceContextSpecFactoryWin.h"
|
||||
#include "nsDeviceContextSpecWin.h"
|
||||
#include "nsDeviceContextSpecFactoryPS.h"
|
||||
#include "nsDeviceContextSpecPS.h"
|
||||
#include <windows.h>
|
||||
#include <commdlg.h>
|
||||
#include "nsGfxCIID.h"
|
||||
#include "plstr.h"
|
||||
|
||||
nsDeviceContextSpecFactoryWin :: nsDeviceContextSpecFactoryWin()
|
||||
nsDeviceContextSpecFactoryPS :: nsDeviceContextSpecFactoryPS()
|
||||
{
|
||||
}
|
||||
|
||||
nsDeviceContextSpecFactoryWin :: ~nsDeviceContextSpecFactoryWin()
|
||||
nsDeviceContextSpecFactoryPS :: ~nsDeviceContextSpecFactoryPS()
|
||||
{
|
||||
}
|
||||
|
||||
@ -35,21 +35,22 @@ static NS_DEFINE_IID(kDeviceContextSpecFactoryIID, NS_IDEVICE_CONTEXT_SPEC_FACTO
|
||||
static NS_DEFINE_IID(kIDeviceContextSpecIID, NS_IDEVICE_CONTEXT_SPEC_IID);
|
||||
static NS_DEFINE_IID(kDeviceContextSpecCID, NS_DEVICE_CONTEXT_SPEC_CID);
|
||||
|
||||
NS_IMPL_QUERY_INTERFACE(nsDeviceContextSpecFactoryWin, kDeviceContextSpecFactoryIID)
|
||||
NS_IMPL_ADDREF(nsDeviceContextSpecFactoryWin)
|
||||
NS_IMPL_RELEASE(nsDeviceContextSpecFactoryWin)
|
||||
NS_IMPL_QUERY_INTERFACE(nsDeviceContextSpecFactoryPS, kDeviceContextSpecFactoryIID)
|
||||
NS_IMPL_ADDREF(nsDeviceContextSpecFactoryPS)
|
||||
NS_IMPL_RELEASE(nsDeviceContextSpecFactoryPS)
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecFactoryWin :: Init(void)
|
||||
NS_IMETHODIMP nsDeviceContextSpecFactoryPS :: Init(void)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//XXX this method needs to do what the API says...
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecFactoryWin :: CreateDeviceContextSpec(nsIDeviceContextSpec *aOldSpec,
|
||||
NS_IMETHODIMP nsDeviceContextSpecFactoryPS :: CreateDeviceContextSpec(nsIDeviceContextSpec *aOldSpec,
|
||||
nsIDeviceContextSpec *&aNewSpec,
|
||||
PRBool aQuiet)
|
||||
{
|
||||
#ifdef DC
|
||||
PRINTDLG prntdlg;
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
@ -108,6 +109,6 @@ printf("printer: driver %s, device %s\n", driver, device);
|
||||
::GlobalUnlock(prntdlg.hDevNames);
|
||||
::GlobalFree(prntdlg.hDevNames);
|
||||
}
|
||||
|
||||
return rv;
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -16,16 +16,16 @@
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsDeviceContextSpecFactoryWin_h___
|
||||
#define nsDeviceContextSpecFactoryWin_h___
|
||||
#ifndef nsDeviceContextSpecFactoryPS_h___
|
||||
#define nsDeviceContextSpecFactoryPS_h___
|
||||
|
||||
#include "nsIDeviceContextSpecFactory.h"
|
||||
#include "nsIDeviceContextSpec.h"
|
||||
|
||||
class nsDeviceContextSpecFactoryWin : public nsIDeviceContextSpecFactory
|
||||
class nsDeviceContextSpecFactoryPS : public nsIDeviceContextSpecFactory
|
||||
{
|
||||
public:
|
||||
nsDeviceContextSpecFactoryWin();
|
||||
nsDeviceContextSpecFactoryPS();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
@ -35,7 +35,7 @@ public:
|
||||
PRBool aQuiet);
|
||||
|
||||
protected:
|
||||
~nsDeviceContextSpecFactoryWin();
|
||||
~nsDeviceContextSpecFactoryPS();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -16,77 +16,24 @@
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsDeviceContextSpecWin.h"
|
||||
#include "prmem.h"
|
||||
#include "plstr.h"
|
||||
#include "nsDeviceContextSpecPS.h"
|
||||
|
||||
nsDeviceContextSpecWin :: nsDeviceContextSpecWin()
|
||||
nsDeviceContextSpecPS :: nsDeviceContextSpecPS()
|
||||
{
|
||||
mDriverName = nsnull;
|
||||
mDeviceName = nsnull;
|
||||
mDEVMODE = NULL;
|
||||
}
|
||||
|
||||
nsDeviceContextSpecWin :: ~nsDeviceContextSpecWin()
|
||||
nsDeviceContextSpecPS :: ~nsDeviceContextSpecPS()
|
||||
{
|
||||
if (nsnull != mDriverName)
|
||||
{
|
||||
PR_Free(mDriverName);
|
||||
mDriverName = nsnull;
|
||||
}
|
||||
|
||||
if (nsnull != mDeviceName)
|
||||
{
|
||||
PR_Free(mDeviceName);
|
||||
mDeviceName = nsnull;
|
||||
}
|
||||
|
||||
if (NULL != mDEVMODE)
|
||||
{
|
||||
::GlobalFree(mDEVMODE);
|
||||
mDEVMODE = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kDeviceContextSpecIID, NS_IDEVICE_CONTEXT_SPEC_IID);
|
||||
|
||||
NS_IMPL_QUERY_INTERFACE(nsDeviceContextSpecWin, kDeviceContextSpecIID)
|
||||
NS_IMPL_ADDREF(nsDeviceContextSpecWin)
|
||||
NS_IMPL_RELEASE(nsDeviceContextSpecWin)
|
||||
NS_IMPL_QUERY_INTERFACE(nsDeviceContextSpecPS, kDeviceContextSpecIID)
|
||||
NS_IMPL_ADDREF(nsDeviceContextSpecPS)
|
||||
NS_IMPL_RELEASE(nsDeviceContextSpecPS)
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecWin :: Init(char *aDriverName, char *aDeviceName, HGLOBAL aDEVMODE)
|
||||
NS_IMETHODIMP nsDeviceContextSpecPS :: Init(char *aDriverName)
|
||||
{
|
||||
if (nsnull != aDriverName)
|
||||
{
|
||||
mDriverName = (char *)PR_Malloc(PL_strlen(aDriverName) + 1);
|
||||
PL_strcpy(mDriverName, aDriverName);
|
||||
}
|
||||
|
||||
if (nsnull != aDeviceName)
|
||||
{
|
||||
mDeviceName = (char *)PR_Malloc(PL_strlen(aDeviceName) + 1);
|
||||
PL_strcpy(mDeviceName, aDeviceName);
|
||||
}
|
||||
|
||||
mDEVMODE = aDEVMODE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecWin :: GetDriverName(char *&aDriverName) const
|
||||
{
|
||||
aDriverName = mDriverName;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecWin :: GetDeviceName(char *&aDeviceName) const
|
||||
{
|
||||
aDeviceName = mDeviceName;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecWin :: GetDEVMODE(HGLOBAL &aDEVMODE) const
|
||||
{
|
||||
aDEVMODE = mDEVMODE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -16,30 +16,23 @@
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsDeviceContextSpecWin_h___
|
||||
#define nsDeviceContextSpecWin_h___
|
||||
#ifndef nsDeviceContextSpecPS_h___
|
||||
#define nsDeviceContextSpecPS_h___
|
||||
|
||||
#include "nsIDeviceContextSpec.h"
|
||||
#include <windows.h>
|
||||
|
||||
class nsDeviceContextSpecWin : public nsIDeviceContextSpec
|
||||
class nsDeviceContextSpecPS : public nsIDeviceContextSpec
|
||||
{
|
||||
public:
|
||||
nsDeviceContextSpecWin();
|
||||
nsDeviceContextSpecPS();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Init(char *aDriverName, char *aDeviceName, HGLOBAL aDEVMODE);
|
||||
NS_IMETHOD GetDriverName(char *&aDriverName) const;
|
||||
NS_IMETHOD GetDeviceName(char *&aDeviceName) const;
|
||||
NS_IMETHOD GetDEVMODE(HGLOBAL &aDevMode) const;
|
||||
NS_IMETHOD Init(char *aDriverName);
|
||||
|
||||
protected:
|
||||
virtual ~nsDeviceContextSpecWin();
|
||||
virtual ~nsDeviceContextSpecPS();
|
||||
|
||||
char *mDriverName;
|
||||
char *mDeviceName;
|
||||
HGLOBAL mDEVMODE;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -16,8 +16,8 @@
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsRenderingContextWin_h___
|
||||
#define nsRenderingContextWin_h___
|
||||
#ifndef nsRenderingContextPS_h___
|
||||
#define nsRenderingContextPS_h___
|
||||
|
||||
#include "nsIRenderingContext.h"
|
||||
#include "nsUnitConversion.h"
|
||||
@ -30,28 +30,18 @@
|
||||
#include "nsIViewManager.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsRect.h"
|
||||
#include "nsImageWin.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIDOMRenderingContext.h"
|
||||
|
||||
#include "nsPrintManager.h"
|
||||
|
||||
class GraphicsState;
|
||||
class nsDrawingSurfaceWin;
|
||||
class GraphicState;
|
||||
typedef void* nsDrawingSurfacePS;
|
||||
|
||||
#ifdef NGLAYOUT_DDRAW
|
||||
#include "ddraw.h"
|
||||
#endif
|
||||
|
||||
class nsRenderingContextWin : public nsIRenderingContext,
|
||||
nsIDOMRenderingContext,
|
||||
nsIScriptObjectOwner
|
||||
class nsRenderingContextPS : public nsIRenderingContext
|
||||
{
|
||||
public:
|
||||
nsRenderingContextWin();
|
||||
~nsRenderingContextWin();
|
||||
nsRenderingContextPS();
|
||||
~nsRenderingContextPS();
|
||||
|
||||
void* operator new(size_t sz) {
|
||||
void* rv = new char[sz];
|
||||
@ -63,14 +53,6 @@ public:
|
||||
|
||||
// nsIPrinterRenderingContext methods
|
||||
|
||||
NS_IMETHODIMP BeginDocument(PrintSetup *aPrintInfo);
|
||||
|
||||
NS_IMETHODIMP EndDocument();
|
||||
|
||||
NS_IMETHODIMP BeginPage();
|
||||
|
||||
NS_IMETHODIMP EndPage();
|
||||
|
||||
// Postscript utilities
|
||||
void PostscriptColor(nscolor aColor);
|
||||
void PostscriptFillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
@ -81,20 +63,11 @@ public:
|
||||
nscoord aX, nscoord aY, nscoord aWidth,
|
||||
const nscoord* aSpacing, PRBool aIsUnicode);
|
||||
|
||||
//XXX:PS Test methods, remove when fully implemented
|
||||
virtual void TestInitialize();
|
||||
virtual void TestFinalize();
|
||||
|
||||
protected:
|
||||
MWContext *mPrintContext; //XXX: Remove need for MWContext
|
||||
PrintSetup *mPrintSetup;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
// nsIRenderingContext
|
||||
|
||||
|
||||
NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWindow);
|
||||
NS_IMETHOD Init(nsIDeviceContext* aContext, nsDrawingSurface aSurface);
|
||||
|
||||
@ -187,105 +160,55 @@ public:
|
||||
NS_IMETHOD CopyOffScreenBits(nsDrawingSurface aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY,
|
||||
const nsRect &aDestBounds, PRUint32 aCopyFlags);
|
||||
|
||||
// nsIScriptObjectOwner
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
// nsIDOMRenderingContext
|
||||
NS_DECL_IDOMRENDERINGCONTEXT
|
||||
|
||||
// locals
|
||||
#ifdef NGLAYOUT_DDRAW
|
||||
nsresult GetDDraw(IDirectDraw2 **aDDraw);
|
||||
#endif
|
||||
|
||||
private:
|
||||
nsresult CommonInit(void);
|
||||
nsresult SetupDC(HDC aOldDC, HDC aNewDC);
|
||||
HBRUSH SetupSolidBrush(void);
|
||||
HPEN SetupPen(void);
|
||||
HPEN SetupSolidPen(void);
|
||||
HPEN SetupDashedPen(void);
|
||||
HPEN SetupDottedPen(void);
|
||||
void SetupFontAndColor(void);
|
||||
void PushClipState(void);
|
||||
#ifdef NGLAYOUT_DDRAW
|
||||
nsresult CreateDDraw(void);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
nscolor mCurrentColor;
|
||||
nsTransform2D *mTMatrix; // transform that all the graphics drawn here will obey
|
||||
nsIFontMetrics *mFontMetrics;
|
||||
HDC mDC;
|
||||
HDC mMainDC;
|
||||
nsDrawingSurfaceWin *mSurface;
|
||||
nsDrawingSurfaceWin *mMainSurface;
|
||||
COLORREF mColor;
|
||||
nsIWidget *mDCOwner;
|
||||
// int mOldMapMode;
|
||||
nsIDeviceContext *mContext;
|
||||
float mP2T;
|
||||
HRGN mClipRegion;
|
||||
nscolor mCurrentColor;
|
||||
nsTransform2D *mTMatrix; // transform that all the graphics drawn here will obey
|
||||
nsIFontMetrics *mFontMetrics;
|
||||
//HDC mDC;
|
||||
//HDC mMainDC;
|
||||
nsDrawingSurfacePS *mSurface;
|
||||
//nsDrawingSurfaceWin *mMainSurface;
|
||||
COLORREF mColor;
|
||||
//nsIWidget *mDCOwner;
|
||||
nsIDeviceContext *mContext;
|
||||
float mP2T;
|
||||
HRGN mClipRegion;
|
||||
//default objects
|
||||
HBRUSH mOrigSolidBrush;
|
||||
HBRUSH mBlackBrush;
|
||||
HFONT mOrigFont;
|
||||
HFONT mDefFont;
|
||||
HPEN mOrigSolidPen;
|
||||
HPEN mBlackPen;
|
||||
HPALETTE mOrigPalette;
|
||||
HBRUSH mOrigSolidBrush;
|
||||
HBRUSH mBlackBrush;
|
||||
HFONT mOrigFont;
|
||||
HFONT mDefFont;
|
||||
HPEN mOrigSolidPen;
|
||||
HPEN mBlackPen;
|
||||
HPALETTE mOrigPalette;
|
||||
|
||||
//state management
|
||||
GraphicsState *mStates;
|
||||
nsVoidArray *mStateCache;
|
||||
nscolor mCurrBrushColor;
|
||||
HBRUSH mCurrBrush;
|
||||
nsIFontMetrics *mCurrFontMetrics;
|
||||
HFONT mCurrFont;
|
||||
nscolor mCurrPenColor;
|
||||
HPEN mCurrPen;
|
||||
HPEN mNullPen;
|
||||
PRUint8 *mGammaTable;
|
||||
COLORREF mCurrTextColor;
|
||||
nsLineStyle mCurrLineStyle;
|
||||
nsVoidArray *mStateCache;
|
||||
nscolor mCurrBrushColor;
|
||||
HBRUSH mCurrBrush;
|
||||
nsIFontMetrics *mCurrFontMetrics;
|
||||
HFONT mCurrFont;
|
||||
nscolor mCurrPenColor;
|
||||
HPEN mCurrPen;
|
||||
HPEN mNullPen;
|
||||
PRUint8 *mGammaTable;
|
||||
COLORREF mCurrTextColor;
|
||||
nsLineStyle mCurrLineStyle;
|
||||
PRBool mGetNearestColor;
|
||||
MWContext *mPrintContext; //XXX: Remove need for MWContext
|
||||
nsDrawingSurfacePS mFrontBuffer; // screen port
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
PRBool mInitialized;
|
||||
#endif
|
||||
// graphic state management
|
||||
GraphicState * mStates; // Pointer to the current graphic state, top of stack
|
||||
nsVoidArray * mGSArray;
|
||||
|
||||
#ifdef NGLAYOUT_DDRAW
|
||||
static IDirectDraw *mDDraw;
|
||||
static IDirectDraw2 *mDDraw2;
|
||||
static nsresult mDDrawResult;
|
||||
#endif
|
||||
|
||||
void* mScriptObject;
|
||||
};
|
||||
|
||||
class nsDrawingSurfaceWin : public nsISupports
|
||||
{
|
||||
public:
|
||||
nsDrawingSurfaceWin();
|
||||
~nsDrawingSurfaceWin();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsresult Init(HDC aDC);
|
||||
nsresult Init(nsIWidget *aOwner);
|
||||
#ifdef NGLAYOUT_DDRAW
|
||||
nsresult Init(LPDIRECTDRAWSURFACE aSurface);
|
||||
nsresult GetDC();
|
||||
nsresult ReleaseDC();
|
||||
#endif
|
||||
|
||||
nsIWidget *mDCOwner;
|
||||
HDC mDC;
|
||||
HBITMAP mOrigBitmap;
|
||||
HBITMAP mSelectedBitmap;
|
||||
|
||||
#ifdef NGLAYOUT_DDRAW
|
||||
IDirectDrawSurface *mSurface;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /* nsRenderingContextWin_h___ */
|
||||
#endif /* nsRenderingContextPS_h___ */
|
||||
|
@ -1,496 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* (C) 1988, 1989, 1990 by Adobe Systems Incorporated. All rights reserved.
|
||||
*
|
||||
* This file may be freely copied and redistributed as long as:
|
||||
* 1) This entire notice continues to be included in the file,
|
||||
* 2) If the file has been modified in any way, a notice of such
|
||||
* modification is conspicuously indicated.
|
||||
*
|
||||
* PostScript, Display PostScript, and Adobe are registered trademarks of
|
||||
* Adobe Systems Incorporated.
|
||||
*
|
||||
* ************************************************************************
|
||||
* THE INFORMATION BELOW IS FURNISHED AS IS, IS SUBJECT TO CHANGE WITHOUT
|
||||
* NOTICE, AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY ADOBE SYSTEMS
|
||||
* INCORPORATED. ADOBE SYSTEMS INCORPORATED ASSUMES NO RESPONSIBILITY OR
|
||||
* LIABILITY FOR ANY ERRORS OR INACCURACIES, MAKES NO WARRANTY OF ANY
|
||||
* KIND (EXPRESS, IMPLIED OR STATUTORY) WITH RESPECT TO THIS INFORMATION,
|
||||
* AND EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR PARTICULAR PURPOSES AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
* ************************************************************************
|
||||
*/
|
||||
|
||||
/* parseAFM.c
|
||||
*
|
||||
* This file is used in conjuction with the parseAFM.h header file.
|
||||
* This file contains several procedures that are used to parse AFM
|
||||
* files. It is intended to work with an application program that needs
|
||||
* font metric information. The program can be used as is by making a
|
||||
* procedure call to "parseFile" (passing in the expected parameters)
|
||||
* and having it fill in a data structure with the data from the
|
||||
* AFM file, or an application developer may wish to customize this
|
||||
* code.
|
||||
*
|
||||
* There is also a file, parseAFMclient.c, that is a sample application
|
||||
* showing how to call the "parseFile" procedure and how to use the data
|
||||
* after "parseFile" has returned.
|
||||
*
|
||||
* Please read the comments in parseAFM.h and parseAFMclient.c.
|
||||
*
|
||||
* History:
|
||||
* original: DSM Thu Oct 20 17:39:59 PDT 1988
|
||||
* modified: DSM Mon Jul 3 14:17:50 PDT 1989
|
||||
* - added 'storageProblem' return code
|
||||
* - fixed bug of not allocating extra byte for string duplication
|
||||
* - fixed typos
|
||||
* modified: DSM Tue Apr 3 11:18:34 PDT 1990
|
||||
* - added free(ident) at end of parseFile routine
|
||||
* modified: DSM Tue Jun 19 10:16:29 PDT 1990
|
||||
* - changed (width == 250) to (width = 250) in initializeArray
|
||||
* modified: liuhai Wed Jun 11 13:53:35 PDT 1997
|
||||
* - customized for Netscape's runtime AFM file parsing
|
||||
* - only 'necessary' parsings are kept, others were thrown away
|
||||
* - PS_FontInfo is used instead of FontInfo
|
||||
*/
|
||||
|
||||
/*
|
||||
* Mozilla modifications:
|
||||
* - Include xlate_i.h for PS_FontInfo struct definition.
|
||||
* - Minor compiler warning cleanup.
|
||||
*/
|
||||
|
||||
#include "xlate_i.h"
|
||||
#include <errno.h>
|
||||
#include <sys/file.h>
|
||||
#include <math.h>
|
||||
#include "parseAFM.h"
|
||||
/*
|
||||
#include "sunos.h"
|
||||
*/
|
||||
#define lineterm EOL /* line terminating character */
|
||||
#define normalEOF 1 /* return code from parsing routines used only */
|
||||
/* in this module */
|
||||
#define Space "space" /* used in string comparison to look for the width */
|
||||
/* of the space character to init the widths array */
|
||||
#define False "false" /* used in string comparison to check the value of */
|
||||
/* boolean keys (e.g. IsFixedPitch) */
|
||||
|
||||
#define MATCH(A,B) (strncmp((A),(B), MAX_NAME) == 0)
|
||||
|
||||
|
||||
|
||||
/*************************** GLOBALS ***********************/
|
||||
|
||||
static char *ident = NULL; /* storage buffer for keywords */
|
||||
|
||||
|
||||
/* "shorts" for fast case statement
|
||||
* The values of each of these enumerated items correspond to an entry in the
|
||||
* table of strings defined below. Therefore, if you add a new string as
|
||||
* new keyword into the keyStrings table, you must also add a corresponding
|
||||
* parseKey AND it MUST be in the same position!
|
||||
*
|
||||
* IMPORTANT: since the sorting algorithm is a binary search, the strings of
|
||||
* keywords must be placed in lexicographical order, below. [Therefore, the
|
||||
* enumerated items are not necessarily in lexicographical order, depending
|
||||
* on the name chosen. BUT, they must be placed in the same position as the
|
||||
* corresponding key string.] The NOPE shall remain in the last position,
|
||||
* since it does not correspond to any key string, and it is used in the
|
||||
* "recognize" procedure to calculate how many possible keys there are.
|
||||
*/
|
||||
|
||||
static enum parseKey {
|
||||
ASCENDER, CHARBBOX, CODE, COMPCHAR, CAPHEIGHT, COMMENT,
|
||||
DESCENDER, ENCODINGSCHEME, ENDCHARMETRICS, ENDCOMPOSITES,
|
||||
ENDFONTMETRICS, ENDKERNDATA, ENDKERNPAIRS, ENDTRACKKERN,
|
||||
FAMILYNAME, FONTBBOX, FONTNAME, FULLNAME, ISFIXEDPITCH,
|
||||
ITALICANGLE, KERNPAIR, KERNPAIRXAMT, LIGATURE, CHARNAME,
|
||||
NOTICE, COMPCHARPIECE, STARTCHARMETRICS, STARTCOMPOSITES,
|
||||
STARTFONTMETRICS, STARTKERNDATA, STARTKERNPAIRS,
|
||||
STARTTRACKKERN, TRACKKERN, UNDERLINEPOSITION,
|
||||
UNDERLINETHICKNESS, VERSION, XYWIDTH, XWIDTH, WEIGHT, XHEIGHT,
|
||||
NOPE };
|
||||
|
||||
/* keywords for the system:
|
||||
* This a table of all of the current strings that are vaild AFM keys.
|
||||
* Each entry can be referenced by the appropriate parseKey value (an
|
||||
* enumerated data type defined above). If you add a new keyword here,
|
||||
* a corresponding parseKey MUST be added to the enumerated data type
|
||||
* defined above, AND it MUST be added in the same position as the
|
||||
* string is in this table.
|
||||
*
|
||||
* IMPORTANT: since the sorting algorithm is a binary search, the keywords
|
||||
* must be placed in lexicographical order. And, NULL should remain at the
|
||||
* end.
|
||||
*/
|
||||
|
||||
static char *keyStrings[] = {
|
||||
"Ascender", "B", "C", "CC", "CapHeight", "Comment",
|
||||
"Descender", "EncodingScheme", "EndCharMetrics", "EndComposites",
|
||||
"EndFontMetrics", "EndKernData", "EndKernPairs", "EndTrackKern",
|
||||
"FamilyName", "FontBBox", "FontName", "FullName", "IsFixedPitch",
|
||||
"ItalicAngle", "KP", "KPX", "L", "N",
|
||||
"Notice", "PCC", "StartCharMetrics", "StartComposites",
|
||||
"StartFontMetrics", "StartKernData", "StartKernPairs",
|
||||
"StartTrackKern", "TrackKern", "UnderlinePosition",
|
||||
"UnderlineThickness", "Version", "W", "WX", "Weight", "XHeight",
|
||||
NULL };
|
||||
|
||||
/*************************** PARSING ROUTINES **************/
|
||||
|
||||
/*************************** token *************************/
|
||||
|
||||
/* A "AFM File Conventions" tokenizer. That means that it will
|
||||
* return the next token delimited by white space. See also
|
||||
* the `linetoken' routine, which does a similar thing but
|
||||
* reads all tokens until the next end-of-line.
|
||||
*/
|
||||
|
||||
static char *token(FILE *stream)
|
||||
{
|
||||
int ch, idx;
|
||||
|
||||
/* skip over white space */
|
||||
while ((ch = fgetc(stream)) == ' ' || ch == lineterm ||
|
||||
ch == ',' || ch == '\t' || ch == ';');
|
||||
|
||||
idx = 0;
|
||||
while (ch != EOF && ch != ' ' && ch != lineterm
|
||||
&& ch != '\t' && ch != ':' && ch != ';')
|
||||
{
|
||||
ident[idx++] = ch;
|
||||
ch = fgetc(stream);
|
||||
} /* while */
|
||||
|
||||
if (ch == EOF && idx < 1) return ((char *)NULL);
|
||||
if (idx >= 1 && ch != ':' ) ungetc(ch, stream);
|
||||
if (idx < 1 ) ident[idx++] = ch; /* single-character token */
|
||||
ident[idx] = 0;
|
||||
|
||||
return(ident); /* returns pointer to the token */
|
||||
|
||||
} /* token */
|
||||
|
||||
|
||||
/*************************** linetoken *************************/
|
||||
|
||||
/* "linetoken" will get read all tokens until the EOL character from
|
||||
* the given stream. This is used to get any arguments that can be
|
||||
* more than one word (like Comment lines and FullName).
|
||||
*/
|
||||
|
||||
static char *linetoken(FILE *stream)
|
||||
{
|
||||
int ch, idx;
|
||||
|
||||
while ((ch = fgetc(stream)) == ' ' || ch == '\t' );
|
||||
|
||||
idx = 0;
|
||||
while (ch != EOF && ch != lineterm)
|
||||
{
|
||||
ident[idx++] = ch;
|
||||
ch = fgetc(stream);
|
||||
} /* while */
|
||||
|
||||
ungetc(ch, stream);
|
||||
ident[idx] = 0;
|
||||
|
||||
return(ident); /* returns pointer to the token */
|
||||
|
||||
} /* linetoken */
|
||||
|
||||
|
||||
/*************************** recognize *************************/
|
||||
|
||||
/* This function tries to match a string to a known list of
|
||||
* valid AFM entries (check the keyStrings array above).
|
||||
* "ident" contains everything from white space through the
|
||||
* next space, tab, or ":" character.
|
||||
*
|
||||
* The algorithm is a standard Knuth binary search.
|
||||
*/
|
||||
|
||||
static enum parseKey recognize(register char *ident)
|
||||
{
|
||||
int lower = 0, upper = (int) NOPE, midpoint, cmpvalue;
|
||||
BOOL found = FALSE;
|
||||
|
||||
while ((upper >= lower) && !found)
|
||||
{
|
||||
midpoint = (lower + upper)/2;
|
||||
if (keyStrings[midpoint] == NULL) break;
|
||||
cmpvalue = strncmp(ident, keyStrings[midpoint], MAX_NAME);
|
||||
if (cmpvalue == 0) found = TRUE;
|
||||
else if (cmpvalue < 0) upper = midpoint - 1;
|
||||
else lower = midpoint + 1;
|
||||
} /* while */
|
||||
|
||||
if (found) return (enum parseKey) midpoint;
|
||||
else return NOPE;
|
||||
|
||||
} /* recognize */
|
||||
|
||||
|
||||
/************************* parseGlobals *****************************/
|
||||
|
||||
static BOOL parseGlobals(FILE *fp, register PS_FontInfo *gfi)
|
||||
{
|
||||
BOOL cont = TRUE, save = (gfi != NULL);
|
||||
int error = ok;
|
||||
register char *keyword;
|
||||
|
||||
while (cont)
|
||||
{
|
||||
keyword = token(fp);
|
||||
|
||||
if (keyword == NULL)
|
||||
/* Have reached an early and unexpected EOF. */
|
||||
/* Set flag and stop parsing */
|
||||
{
|
||||
error = earlyEOF;
|
||||
break; /* get out of loop */
|
||||
}
|
||||
if (!save)
|
||||
/* get tokens until the end of the Global Font info section */
|
||||
/* without saving any of the data */
|
||||
switch (recognize(keyword))
|
||||
{
|
||||
case STARTCHARMETRICS:
|
||||
cont = FALSE;
|
||||
break;
|
||||
case ENDFONTMETRICS:
|
||||
cont = FALSE;
|
||||
error = normalEOF;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
} /* switch */
|
||||
else {
|
||||
/* otherwise parse entire global font info section, */
|
||||
/* saving the data */
|
||||
switch(recognize(keyword))
|
||||
{
|
||||
case STARTFONTMETRICS:
|
||||
keyword = token(fp);
|
||||
break;
|
||||
case COMMENT:
|
||||
keyword = linetoken(fp);
|
||||
break;
|
||||
case FONTNAME:
|
||||
keyword = token(fp);
|
||||
gfi->name = (char *) malloc(strlen(keyword) + 1);
|
||||
strcpy(gfi->name, keyword);
|
||||
break;
|
||||
case ENCODINGSCHEME:
|
||||
keyword = token(fp);
|
||||
break;
|
||||
case FULLNAME:
|
||||
keyword = linetoken(fp);
|
||||
break;
|
||||
case FAMILYNAME:
|
||||
keyword = linetoken(fp);
|
||||
break;
|
||||
case WEIGHT:
|
||||
keyword = token(fp);
|
||||
break;
|
||||
case ITALICANGLE:
|
||||
keyword = token(fp);
|
||||
break;
|
||||
case ISFIXEDPITCH:
|
||||
keyword = token(fp);
|
||||
break;
|
||||
case UNDERLINEPOSITION:
|
||||
keyword = token(fp);
|
||||
gfi->upos = atoi(keyword);
|
||||
break;
|
||||
case UNDERLINETHICKNESS:
|
||||
keyword = token(fp);
|
||||
gfi->uthick = atoi(keyword);
|
||||
break;
|
||||
case VERSION:
|
||||
keyword = token(fp);
|
||||
break;
|
||||
case NOTICE:
|
||||
keyword = linetoken(fp);
|
||||
break;
|
||||
case FONTBBOX:
|
||||
keyword = token(fp);
|
||||
gfi->fontBBox.llx = atoi(keyword);
|
||||
keyword = token(fp);
|
||||
gfi->fontBBox.lly = atoi(keyword);
|
||||
keyword = token(fp);
|
||||
gfi->fontBBox.urx = atoi(keyword);
|
||||
keyword = token(fp);
|
||||
gfi->fontBBox.ury = atoi(keyword);
|
||||
break;
|
||||
case CAPHEIGHT:
|
||||
keyword = token(fp);
|
||||
break;
|
||||
case XHEIGHT:
|
||||
keyword = token(fp);
|
||||
break;
|
||||
case DESCENDER:
|
||||
keyword = token(fp);
|
||||
break;
|
||||
case ASCENDER:
|
||||
keyword = token(fp);
|
||||
break;
|
||||
case STARTCHARMETRICS:
|
||||
cont = FALSE;
|
||||
break;
|
||||
case ENDFONTMETRICS:
|
||||
cont = FALSE;
|
||||
error = normalEOF;
|
||||
break;
|
||||
case NOPE:
|
||||
break;
|
||||
default:
|
||||
error = parseError;
|
||||
break;
|
||||
} /* switch */
|
||||
}
|
||||
} /* while */
|
||||
|
||||
return(error);
|
||||
|
||||
} /* parseGlobals */
|
||||
|
||||
/************************* parseCharMetrics ************************/
|
||||
|
||||
static int parseCharMetrics(FILE *fp, register PS_FontInfo *fi)
|
||||
{
|
||||
BOOL cont = TRUE;
|
||||
int error = ok, count = 0, code = 0;
|
||||
register char *keyword;
|
||||
|
||||
while (cont)
|
||||
{
|
||||
keyword = token(fp);
|
||||
if (keyword == NULL)
|
||||
{
|
||||
error = earlyEOF;
|
||||
break; /* get out of loop */
|
||||
}
|
||||
|
||||
switch(recognize(keyword))
|
||||
{
|
||||
case COMMENT:
|
||||
keyword = linetoken(fp);
|
||||
break;
|
||||
case CODE:
|
||||
code = atoi(token(fp));
|
||||
count++;
|
||||
break;
|
||||
case XYWIDTH:
|
||||
if (code <0 || code >= 256) {
|
||||
token(fp); token(fp); break;
|
||||
}
|
||||
fi->chars[code].wx = atoi(token(fp));
|
||||
fi->chars[code].wy = atoi(token(fp));
|
||||
break;
|
||||
case XWIDTH:
|
||||
if (code <0 || code >= 256) {
|
||||
token(fp); break;
|
||||
}
|
||||
fi->chars[code].wx = atoi(token(fp));
|
||||
break;
|
||||
case CHARNAME:
|
||||
keyword = token(fp);
|
||||
break;
|
||||
case CHARBBOX:
|
||||
if (code <0 || code >= 256) {
|
||||
token(fp); token(fp); token(fp); token(fp); break;
|
||||
}
|
||||
fi->chars[code].charBBox.llx = atoi(token(fp));
|
||||
fi->chars[code].charBBox.lly = atoi(token(fp));
|
||||
fi->chars[code].charBBox.urx = atoi(token(fp));
|
||||
fi->chars[code].charBBox.ury = atoi(token(fp));
|
||||
break;
|
||||
case LIGATURE:
|
||||
keyword = token(fp);
|
||||
keyword = token(fp);
|
||||
break;
|
||||
case ENDCHARMETRICS:
|
||||
cont = FALSE;;
|
||||
break;
|
||||
case ENDFONTMETRICS:
|
||||
cont = FALSE;
|
||||
error = normalEOF;
|
||||
break;
|
||||
case NOPE:
|
||||
break;
|
||||
default:
|
||||
error = parseError;
|
||||
break;
|
||||
} /* switch */
|
||||
} /* while */
|
||||
|
||||
return(error);
|
||||
|
||||
} /* parseCharMetrics */
|
||||
|
||||
|
||||
|
||||
/*************************** 'PUBLIC' FUNCTION ********************/
|
||||
|
||||
|
||||
/*************************** XP_parseAFMFile *****************************/
|
||||
|
||||
/* this is the only 'public' procedure available. It is called
|
||||
* from an application wishing to get information from an AFM file.
|
||||
* The caller of this function is responsible for locating and opening
|
||||
* an AFM file and handling all errors associated with that task.
|
||||
*
|
||||
* parseFile returns an error code as defined in parseAFM.h.
|
||||
*
|
||||
* The position of the read/write pointer associated with the file
|
||||
* pointer upon return of this function is undefined.
|
||||
*/
|
||||
|
||||
int XP_parseAFMFile (fp, fi)
|
||||
FILE *fp;
|
||||
PS_FontInfo **fi;
|
||||
{
|
||||
|
||||
int code = ok; /* return code from each of the parsing routines */
|
||||
int error = ok; /* used as the return code from this function */
|
||||
int i;
|
||||
|
||||
register char *keyword; /* used to store a token */
|
||||
|
||||
|
||||
/* storage data for the global variable ident */
|
||||
ident = (char *) calloc(MAX_NAME, sizeof(char));
|
||||
if (ident == NULL) {error = storageProblem; return(error);}
|
||||
|
||||
if ((*fi) == NULL) (*fi) = (PS_FontInfo *) calloc(1, sizeof(PS_FontInfo));
|
||||
if ((*fi) == NULL) {error = storageProblem; return(error);}
|
||||
|
||||
for (i=0; i<256; i++) { /* initialize the default font width */
|
||||
(*fi)->chars[i].wx = 250;
|
||||
}
|
||||
|
||||
/* The AFM File begins with Global Font Information. This section */
|
||||
/* will be parsed whether or not information should be saved. */
|
||||
code = parseGlobals(fp, (*fi));
|
||||
|
||||
/* be liberal to strict AFM grammar. */
|
||||
if ((code != earlyEOF) && (code < 0)) error = code;
|
||||
|
||||
/* The Global Font Information is followed by the Character Metrics */
|
||||
/* section. */
|
||||
|
||||
if ((code != normalEOF) && (code != earlyEOF))
|
||||
{
|
||||
token(fp);
|
||||
code = parseCharMetrics(fp, *fi);
|
||||
} /* if */
|
||||
|
||||
if ((code != earlyEOF) && (code < 0)) error = code;
|
||||
|
||||
if (ident != NULL) { free(ident); ident = NULL; }
|
||||
|
||||
return(error);
|
||||
|
||||
} /* XP_parseAFMFile */
|
@ -1,303 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* (C) 1988, 1989 by Adobe Systems Incorporated. All rights reserved.
|
||||
*
|
||||
* This file may be freely copied and redistributed as long as:
|
||||
* 1) This entire notice continues to be included in the file,
|
||||
* 2) If the file has been modified in any way, a notice of such
|
||||
* modification is conspicuously indicated.
|
||||
*
|
||||
* PostScript, Display PostScript, and Adobe are registered trademarks of
|
||||
* Adobe Systems Incorporated.
|
||||
*
|
||||
* ************************************************************************
|
||||
* THE INFORMATION BELOW IS FURNISHED AS IS, IS SUBJECT TO CHANGE WITHOUT
|
||||
* NOTICE, AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY ADOBE SYSTEMS
|
||||
* INCORPORATED. ADOBE SYSTEMS INCORPORATED ASSUMES NO RESPONSIBILITY OR
|
||||
* LIABILITY FOR ANY ERRORS OR INACCURACIES, MAKES NO WARRANTY OF ANY
|
||||
* KIND (EXPRESS, IMPLIED OR STATUTORY) WITH RESPECT TO THIS INFORMATION,
|
||||
* AND EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR PARTICULAR PURPOSES AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
* ************************************************************************
|
||||
*/
|
||||
|
||||
/* ParseAFM.h
|
||||
*
|
||||
* This header file is used in conjuction with the parseAFM.c file.
|
||||
* Together these files provide the functionality to parse Adobe Font
|
||||
* Metrics files and store the information in predefined data structures.
|
||||
* It is intended to work with an application program that needs font metric
|
||||
* information. The program can be used as is by making a procedure call to
|
||||
* parse an AFM file and have the data stored, or an application developer
|
||||
* may wish to customize the code.
|
||||
*
|
||||
* This header file defines the data structures used as well as the key
|
||||
* strings that are currently recognized by this version of the AFM parser.
|
||||
* This program is based on the document "Adobe Font Metrics Files,
|
||||
* Specification Version 2.0".
|
||||
*
|
||||
* AFM files are separated into distinct sections of different data. Because
|
||||
* of this, the parseAFM program can parse a specified file to only save
|
||||
* certain sections of information based on the application's needs. A record
|
||||
* containing the requested information will be returned to the application.
|
||||
*
|
||||
* AFM files are divided into five sections of data:
|
||||
* 1) The Global Font Information
|
||||
* 2) The Character Metrics Information
|
||||
* 3) The Track Kerning Data
|
||||
* 4) The Pair-Wise Kerning Data
|
||||
* 5) The Composite Character Data
|
||||
*
|
||||
* Basically, the application can request any of these sections independent
|
||||
* of what other sections are requested. In addition, in recognizing that
|
||||
* many applications will want ONLY the x-width of characters and not all
|
||||
* of the other character metrics information, there is a way to receive
|
||||
* only the width information so as not to pay the storage cost for the
|
||||
* unwanted data. An application should never request both the
|
||||
* "quick and dirty" char metrics (widths only) and the Character Metrics
|
||||
* Information since the Character Metrics Information will contain all
|
||||
* of the character widths as well.
|
||||
*
|
||||
* There is a procedure in parseAFM.c, called parseFile, that can be
|
||||
* called from any application wishing to get information from the AFM File.
|
||||
* This procedure expects 3 parameters: a vaild file descriptor, a pointer
|
||||
* to a (FontInfo *) variable (for which space will be allocated and then
|
||||
* will be filled in with the data requested), and a mask specifying
|
||||
* which data from the AFM File should be saved in the FontInfo structure.
|
||||
*
|
||||
* The flags that can be used to set the appropriate mask are defined below.
|
||||
* In addition, several commonly used masks have already been defined.
|
||||
*
|
||||
* History:
|
||||
* original: DSM Thu Oct 20 17:39:59 PDT 1988
|
||||
* modified: DSM Mon Jul 3 14:17:50 PDT 1989
|
||||
* - added 'storageProblem' return code
|
||||
* - fixed typos
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* your basic constants */
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
#define EOL '\n' /* end-of-line indicator */
|
||||
#define MAX_NAME 4096 /* max length for identifiers */
|
||||
#define BOOL int
|
||||
#define FLAGS int
|
||||
|
||||
|
||||
|
||||
/* Flags that can be AND'ed together to specify exactly what
|
||||
* information from the AFM file should be saved.
|
||||
*/
|
||||
#define P_G 0x01 /* 0000 0001 */ /* Global Font Info */
|
||||
#define P_W 0x02 /* 0000 0010 */ /* Character Widths ONLY */
|
||||
#define P_M 0x06 /* 0000 0110 */ /* All Char Metric Info */
|
||||
#define P_P 0x08 /* 0000 1000 */ /* Pair Kerning Info */
|
||||
#define P_T 0x10 /* 0001 0000 */ /* Track Kerning Info */
|
||||
#define P_C 0x20 /* 0010 0000 */ /* Composite Char Info */
|
||||
|
||||
|
||||
/* Commonly used flags
|
||||
*/
|
||||
#define P_GW (P_G | P_W)
|
||||
#define P_GM (P_G | P_M)
|
||||
#define P_GMP (P_G | P_M | P_P)
|
||||
#define P_GMK (P_G | P_M | P_P | P_T)
|
||||
#define P_ALL (P_G | P_M | P_P | P_T | P_C)
|
||||
|
||||
|
||||
|
||||
/* Possible return codes from the parseFile procedure.
|
||||
*
|
||||
* ok means there were no problems parsing the file.
|
||||
*
|
||||
* parseError means that there was some kind of parsing error, but the
|
||||
* parser went on. This could include problems like the count for any given
|
||||
* section does not add up to how many entries there actually were, or
|
||||
* there was a key that was not recognized. The return record may contain
|
||||
* vaild data or it may not.
|
||||
*
|
||||
* earlyEOF means that an End of File was encountered before expected. This
|
||||
* may mean that the AFM file had been truncated, or improperly formed.
|
||||
*
|
||||
* storageProblem means that there were problems allocating storage for
|
||||
* the data structures that would have contained the AFM data.
|
||||
*/
|
||||
#define ok 0
|
||||
#define parseError -1
|
||||
#define earlyEOF -2
|
||||
#define storageProblem -3
|
||||
|
||||
|
||||
|
||||
/************************* TYPES *********************************/
|
||||
/* Below are all of the data structure definitions. These structures
|
||||
* try to map as closely as possible to grouping and naming of data
|
||||
* in the AFM Files.
|
||||
*/
|
||||
|
||||
|
||||
/* Bounding box definition. Used for the Font BBox as well as the
|
||||
* Character BBox.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int llx; /* lower left x-position */
|
||||
int lly; /* lower left y-position */
|
||||
int urx; /* upper right x-position */
|
||||
int ury; /* upper right y-position */
|
||||
} BBox;
|
||||
|
||||
|
||||
/* Global Font information.
|
||||
* The key that each field is associated with is in comments. For an
|
||||
* explanation about each key and its value please refer to the AFM
|
||||
* documentation (full title & version given above).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char *afmVersion; /* key: StartFontMetrics */
|
||||
char *fontName; /* key: FontName */
|
||||
char *fullName; /* key: FullName */
|
||||
char *familyName; /* key: FamilyName */
|
||||
char *weight; /* key: Weight */
|
||||
float italicAngle; /* key: ItalicAngle */
|
||||
BOOL isFixedPitch; /* key: IsFixedPitch */
|
||||
BBox fontBBox; /* key: FontBBox */
|
||||
int underlinePosition; /* key: UnderlinePosition */
|
||||
int underlineThickness; /* key: UnderlineThickness */
|
||||
char *version; /* key: Version */
|
||||
char *notice; /* key: Notice */
|
||||
char *encodingScheme; /* key: EncodingScheme */
|
||||
int capHeight; /* key: CapHeight */
|
||||
int xHeight; /* key: XHeight */
|
||||
int ascender; /* key: Ascender */
|
||||
int descender; /* key: Descender */
|
||||
} GlobalFontInfo;
|
||||
|
||||
|
||||
/* Ligature definition is a linked list since any character can have
|
||||
* any number of ligatures.
|
||||
*/
|
||||
typedef struct _t_ligature
|
||||
{
|
||||
char *succ, *lig;
|
||||
struct _t_ligature *next;
|
||||
} Ligature;
|
||||
|
||||
|
||||
/* Character Metric Information. This structure is used only if ALL
|
||||
* character metric information is requested. If only the character
|
||||
* widths is requested, then only an array of the character x-widths
|
||||
* is returned.
|
||||
*
|
||||
* The key that each field is associated with is in comments. For an
|
||||
* explanation about each key and its value please refer to the
|
||||
* Character Metrics section of the AFM documentation (full title
|
||||
* & version given above).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int code, /* key: C */
|
||||
wx, /* key: WX */
|
||||
wy; /* together wx and wy are associated with key: W */
|
||||
char *name; /* key: N */
|
||||
BBox charBBox; /* key: B */
|
||||
Ligature *ligs; /* key: L (linked list; not a fixed number of Ls */
|
||||
} CharMetricInfo;
|
||||
|
||||
|
||||
/* Track kerning data structure.
|
||||
* The fields of this record are the five values associated with every
|
||||
* TrackKern entry.
|
||||
*
|
||||
* For an explanation about each value please refer to the
|
||||
* Track Kerning section of the AFM documentation (full title
|
||||
* & version given above).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int degree;
|
||||
float minPtSize,
|
||||
minKernAmt,
|
||||
maxPtSize,
|
||||
maxKernAmt;
|
||||
} TrackKernData;
|
||||
|
||||
|
||||
/* Pair Kerning data structure.
|
||||
* The fields of this record are the four values associated with every
|
||||
* KP entry. For KPX entries, the yamt will be zero.
|
||||
*
|
||||
* For an explanation about each value please refer to the
|
||||
* Pair Kerning section of the AFM documentation (full title
|
||||
* & version given above).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char *name1;
|
||||
char *name2;
|
||||
int xamt,
|
||||
yamt;
|
||||
} PairKernData;
|
||||
|
||||
|
||||
/* PCC is a piece of a composite character. This is a sub structure of a
|
||||
* compCharData described below.
|
||||
* These fields will be filled in with the values from the key PCC.
|
||||
*
|
||||
* For an explanation about each key and its value please refer to the
|
||||
* Composite Character section of the AFM documentation (full title
|
||||
* & version given above).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char *pccName;
|
||||
int deltax,
|
||||
deltay;
|
||||
} Pcc;
|
||||
|
||||
|
||||
/* Composite Character Information data structure.
|
||||
* The fields ccName and numOfPieces are filled with the values associated
|
||||
* with the key CC. The field pieces points to an array (size = numOfPieces)
|
||||
* of information about each of the parts of the composite character. That
|
||||
* array is filled in with the values from the key PCC.
|
||||
*
|
||||
* For an explanation about each key and its value please refer to the
|
||||
* Composite Character section of the AFM documentation (full title
|
||||
* & version given above).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char *ccName;
|
||||
int numOfPieces;
|
||||
Pcc *pieces;
|
||||
} CompCharData;
|
||||
|
||||
|
||||
/* FontInfo
|
||||
* Record type containing pointers to all of the other data
|
||||
* structures containing information about a font.
|
||||
* A a record of this type is filled with data by the
|
||||
* parseFile function.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
GlobalFontInfo *gfi; /* ptr to a GlobalFontInfo record */
|
||||
int *cwi; /* ptr to 256 element array of just char widths */
|
||||
int numOfChars; /* number of entries in char metrics array */
|
||||
CharMetricInfo *cmi; /* ptr to char metrics array */
|
||||
int numOfTracks; /* number to entries in track kerning array */
|
||||
TrackKernData *tkd; /* ptr to track kerning array */
|
||||
int numOfPairs; /* number to entries in pair kerning array */
|
||||
PairKernData *pkd; /* ptr to pair kerning array */
|
||||
int numOfComps; /* number to entries in comp char array */
|
||||
CompCharData *ccd; /* ptr to comp char array */
|
||||
} FontInfo;
|
||||
|
2101
gfx/src/ps/print.c
2101
gfx/src/ps/print.c
File diff suppressed because it is too large
Load Diff
@ -1,152 +0,0 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
** These functions are useless for our porpoises I don't include
|
||||
** any headers so I don't have to prototype them.
|
||||
*/
|
||||
|
||||
#include "xp_core.h"
|
||||
#include "il_types.h"
|
||||
|
||||
/* this little bit of stupidity wouldn't be necessary
|
||||
if we had XP_BEGIN_PROTOS defined properly for
|
||||
the Mac
|
||||
*/
|
||||
|
||||
void xl_alldone() { }
|
||||
void PSFE_SetDocPosition() {}
|
||||
void PSFE_GetDocPosition() {}
|
||||
void PSFE_FreeFormElement() { }
|
||||
void PSFE_ClearView() { }
|
||||
void PSFE_CreateNewDocWindow() { }
|
||||
#ifdef EDITOR
|
||||
void TXFE_CreateNewEditWindow() { }
|
||||
#endif
|
||||
void PSFE_SetFormElementToggle() {}
|
||||
void PSFE_SetProgressBarPercent() { }
|
||||
void TXFE_SetDocPosition() {}
|
||||
void TXFE_GetDocPosition() {}
|
||||
void TXFE_FreeFormElement() { }
|
||||
void TXFE_ClearView() { }
|
||||
void TXFE_CreateNewDocWindow() { }
|
||||
void TXFE_SetFormElementToggle() {}
|
||||
void TXFE_GetFormElementInfo() { }
|
||||
void TXFE_SetProgressBarPercent() { }
|
||||
void PSFE_FormTextIsSubmit() {}
|
||||
void PSFE_GetFormElementValue() {}
|
||||
void PSFE_ResetFormElement() {}
|
||||
void TXFE_FormTextIsSubmit() {}
|
||||
void TXFE_GetFormElementValue() {}
|
||||
void TXFE_ResetFormElement() {}
|
||||
void TXFE_DisplayFormElement() { }
|
||||
void TXFE_SetDocDimension() { }
|
||||
void TXFE_SetDocTitle() { }
|
||||
void TXFE_BeginPreSection() { }
|
||||
void TXFE_EndPreSection() { }
|
||||
void PSFE_DisplaySubDoc() { }
|
||||
void PSFE_UseFancyFTP () {}
|
||||
void PSFE_FileSortMethod () {}
|
||||
void PSFE_EnableClicking () {}
|
||||
void PSFE_ShowAllNewsArticles () {}
|
||||
void PSFE_GraphProgressDestroy () {}
|
||||
void TXFE_Confirm () {}
|
||||
void TXFE_Alert () {}
|
||||
void TXFE_CheckConfirm () {}
|
||||
void TXFE_SelectDialog () {}
|
||||
void TXFE_GraphProgressDestroy () {}
|
||||
void TXFE_Progress () {}
|
||||
void TXFE_Prompt () {}
|
||||
void TXFE_PromptUsernameAndPassword () {}
|
||||
void TXFE_PromptWithCaption () {}
|
||||
void PSFE_GraphProgressInit () {}
|
||||
void TXFE_UseFancyNewsgroupListing () {}
|
||||
void PSFE_Progress () {}
|
||||
void TXFE_FileSortMethod () {}
|
||||
void TXFE_UseFancyFTP () {}
|
||||
void TXFE_GraphProgress () {}
|
||||
void PSFE_Confirm () {}
|
||||
void TXFE_EnableClicking () {}
|
||||
void TXFE_ShowAllNewsArticles () {}
|
||||
void PSFE_Prompt () {}
|
||||
void PSFE_PromptUsernameAndPassword () {}
|
||||
void PSFE_PromptWithCaption() {}
|
||||
void PSFE_GraphProgress () {}
|
||||
void PSFE_Alert () {}
|
||||
void TXFE_GraphProgressInit () {}
|
||||
void PSFE_UseFancyNewsgroupListing () {}
|
||||
void TXFE_SetBackgroundColor() {}
|
||||
void PSFE_SetBackgroundColor() {}
|
||||
void TXFE_GetEmbedSize(){}
|
||||
/*void PSFE_GetEmbedSize(){}*/
|
||||
void TXFE_FreeEmbedElement(){}
|
||||
/*void PSFE_FreeEmbedElement(){}*/
|
||||
void TXFE_CreateEmbedWindow(){}
|
||||
/*void PSFE_CreateEmbedWindow(){}*/
|
||||
void TXFE_SaveEmbedWindow(){}
|
||||
/*void PSFE_SaveEmbedWindow(){}*/
|
||||
void TXFE_RestoreEmbedWindow(){}
|
||||
/*void PSFE_RestoreEmbedWindow(){}*/
|
||||
void TXFE_DestroyEmbedWindow(){}
|
||||
/*void PSFE_DestroyEmbedWindow(){}*/
|
||||
void TXFE_DisplayEmbed(){}
|
||||
/* void PSFE_DisplayEmbed(){} */
|
||||
void TXFE_GetJavaAppSize(){}
|
||||
void PSFE_GetJavaAppSize(){}
|
||||
void TXFE_FreeJavaAppElement(){}
|
||||
void PSFE_FreeJavaAppElement(){}
|
||||
void TXFE_HideJavaAppElement(){}
|
||||
void PSFE_HideJavaAppElement(){}
|
||||
void TXFE_DisplayJavaApp(){}
|
||||
void TXFE_DrawJavaApp(){}
|
||||
void PSFE_DrawJavaApp(){}
|
||||
void TXFE_HandleClippingView(){}
|
||||
void PSFE_HandleClippingView(){}
|
||||
void TXFE_FreeEdgeElement(){}
|
||||
void PSFE_FreeEdgeElement(){}
|
||||
void TXFE_DisplayCell(){}
|
||||
void TXFE_DisplayEdge(){}
|
||||
void PSFE_DisplayEdge(){}
|
||||
void TXFE_UpdateStopState(){}
|
||||
void PSFE_UpdateStopState(){}
|
||||
#ifdef XP_OS2 /*performance*/
|
||||
void TXFE_GetMaxWidth(){}
|
||||
void PSFE_GetMaxWidth(){}
|
||||
#endif
|
||||
#ifdef LAYERS
|
||||
void TXFE_EraseBackground(){}
|
||||
void PSFE_EraseBackground(){}
|
||||
void TXFE_SetDrawable(){}
|
||||
void PSFE_SetDrawable(){}
|
||||
|
||||
/* Could be implemented for Postscript and Text, but it's only used for selection */
|
||||
void TXFE_GetTextFrame(){}
|
||||
void PSFE_GetTextFrame(){}
|
||||
#endif
|
||||
/* Webfonts */
|
||||
void TXFE_LoadFontResource(){}
|
||||
void PSFE_LoadFontResource(){}
|
||||
|
||||
void TXFE_DisplayBuiltin() {}
|
||||
void PSFE_DisplayBuiltin() {}
|
||||
|
||||
void TXFE_FreeBuiltinElement() {}
|
||||
void PSFE_FreeBuiltinElement() {}
|
||||
|
||||
void PSFE_CheckConfirm() {}
|
||||
void PSFE_SelectDialog() {}
|
@ -1,214 +0,0 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
/*
|
||||
** This file contains a couple of routines which might be useful
|
||||
** in a cross platform way for dealing with the calculations
|
||||
** involved in table printing.
|
||||
*/
|
||||
|
||||
#include "xlate_i.h"
|
||||
|
||||
PRIVATE XP_Bool
|
||||
too_big(MWContext* cx, int size)
|
||||
{
|
||||
return size >= (cx->prInfo->page_height/8)*7;
|
||||
}
|
||||
|
||||
/*
|
||||
** Called by the FE_Display* functions with the Y span of the item to be
|
||||
** displayed. Used to find page breaks and to reject items which are
|
||||
** not on the current page.
|
||||
**
|
||||
** Returns:
|
||||
** TRUE means display the item
|
||||
** FALSE means do not display the item
|
||||
**
|
||||
** Requires:
|
||||
** cx->prInfo to point to a record which contains the following
|
||||
** information:
|
||||
**
|
||||
** page_topy: DOC Y coord of top of this page.
|
||||
** page_break: During layout, initialize this to
|
||||
** page_topy+page_height;
|
||||
** page_height: The physical height of a piece of paper,
|
||||
** minus top and bottom margins.
|
||||
** phase: XL_<mumble>_PHASE
|
||||
**
|
||||
** If invoked with XP_LayoutForPrint and XP_DrawForPrint, this
|
||||
** will be done automatically.
|
||||
*/
|
||||
|
||||
PUBLIC XP_Bool
|
||||
XP_CheckElementSpan(MWContext*cx, int top, int height)
|
||||
{
|
||||
int bottom;
|
||||
|
||||
/*
|
||||
** During load phase, or if this doesn't appear to be a print
|
||||
** related call, we do nothing.
|
||||
*/
|
||||
|
||||
if (cx->prInfo == NULL || cx->prInfo->phase == 0)
|
||||
return TRUE;
|
||||
|
||||
if (cx->prInfo->phase == XL_LOADING_PHASE)
|
||||
return FALSE;
|
||||
|
||||
bottom = top + height - 1;
|
||||
|
||||
/*
|
||||
** Layout phase is used purely to compute the page breaks for each page.
|
||||
** we always return FALSE, but look carefully at items which span the
|
||||
** page boundry and pick for the actual page break the y minimum of
|
||||
** "acceptable" items which span the physical page boundry.
|
||||
*/
|
||||
if (cx->prInfo->phase == XL_LAYOUT_PHASE)
|
||||
{
|
||||
if (!too_big(cx, height)
|
||||
&& top >= cx->prInfo->page_topy
|
||||
&& top < cx->prInfo->page_topy + cx->prInfo->page_height
|
||||
&& bottom >= cx->prInfo->page_topy + cx->prInfo->page_height)
|
||||
{
|
||||
/*
|
||||
** This item won't fit on this page, and is small enough to consider
|
||||
** breaking a page for.
|
||||
*/
|
||||
if (top < cx->prInfo->page_break) {
|
||||
cx->prInfo->page_break = top;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
** Which leaves only the actual generation phase.
|
||||
*/
|
||||
|
||||
/*
|
||||
** Trivial reject of items which aren't on the page at all
|
||||
*/
|
||||
if (bottom < cx->prInfo->page_topy || top > cx->prInfo->page_break) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
** Complete acceptance of items which fall entirely on the current page
|
||||
*/
|
||||
if (top >= cx->prInfo->page_topy && bottom <= cx->prInfo->page_break) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
** Also print items which overhang the soft boundry, but not the hard
|
||||
** page boundry.
|
||||
*/
|
||||
if (bottom < cx->prInfo->page_topy + cx->prInfo->page_height)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
** It straddles the page break. If it's big, then print it, and let it
|
||||
** get chopped off. If it is small, it will display on the next page.
|
||||
*/
|
||||
return too_big(cx, height);
|
||||
}
|
||||
|
||||
/*
|
||||
** Call to set up the page counting fields in the printinfo structure
|
||||
*/
|
||||
PUBLIC void
|
||||
XP_InitializePrintInfo(MWContext *cx)
|
||||
{
|
||||
if (cx->prInfo == NULL) {
|
||||
PrintInfo *p;
|
||||
|
||||
p = XP_NEW_ZAP(PrintInfo);
|
||||
if (!p) return;
|
||||
cx->prInfo = p;
|
||||
}
|
||||
cx->prInfo->n_pages = 0;
|
||||
cx->prInfo->phase = XL_DRAW_PHASE;
|
||||
}
|
||||
|
||||
PUBLIC void
|
||||
XP_CleanupPrintInfo(MWContext *cx)
|
||||
{
|
||||
PrintInfo *p = cx->prInfo;
|
||||
|
||||
if (p) {
|
||||
if (p->pages) {
|
||||
free(p->pages);
|
||||
p->pages = NULL;
|
||||
}
|
||||
free(p);
|
||||
cx->prInfo = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
PUBLIC void
|
||||
XP_LayoutForPrint(MWContext *cx, int32 doc_height)
|
||||
{
|
||||
int32 y;
|
||||
int saveit;
|
||||
|
||||
saveit = cx->prInfo->phase;
|
||||
cx->prInfo->phase = XL_LAYOUT_PHASE;
|
||||
y = 0;
|
||||
while (y < doc_height) {
|
||||
cx->prInfo->page_topy = y;
|
||||
cx->prInfo->page_break = y + cx->prInfo->page_height;
|
||||
LO_RefreshArea(cx, 0, y,
|
||||
cx->prInfo->page_width, cx->prInfo->page_height);
|
||||
if (cx->prInfo->n_pages >= cx->prInfo->pt_size) {
|
||||
cx->prInfo->pt_size += 100;
|
||||
cx->prInfo->pages = (PageBreaks*)realloc(
|
||||
cx->prInfo->pages,
|
||||
cx->prInfo->pt_size * sizeof (PageBreaks));
|
||||
if ( !cx->prInfo->pages )
|
||||
{
|
||||
extern int MK_OUT_OF_MEMORY;
|
||||
cx->prInfo->n_pages = MK_OUT_OF_MEMORY;
|
||||
return;
|
||||
}
|
||||
}
|
||||
cx->prInfo->pages[cx->prInfo->n_pages].y_top = y;
|
||||
cx->prInfo->pages[cx->prInfo->n_pages].y_break = cx->prInfo->page_break-1;
|
||||
cx->prInfo->n_pages++;
|
||||
y = cx->prInfo->page_break;
|
||||
}
|
||||
cx->prInfo->phase = saveit;
|
||||
}
|
||||
|
||||
PUBLIC void
|
||||
XP_DrawForPrint(MWContext *cx, int page)
|
||||
{
|
||||
int32 t;
|
||||
int saveit;
|
||||
|
||||
saveit = cx->prInfo->phase;
|
||||
cx->prInfo->phase = XL_DRAW_PHASE;
|
||||
|
||||
t = cx->prInfo->pages[page].y_top;
|
||||
cx->prInfo->page_topy = t;
|
||||
cx->prInfo->page_break = cx->prInfo->pages[page].y_break;
|
||||
LO_RefreshArea(cx,
|
||||
0, t,
|
||||
cx->prInfo->page_width, cx->prInfo->page_height);
|
||||
cx->prInfo->phase = saveit;
|
||||
}
|
@ -1,787 +0,0 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#include "xlate_i.h"
|
||||
#include "ctxtfunc.h"
|
||||
#include "net.h"
|
||||
#include "libi18n.h"
|
||||
#include "fe_proto.h"
|
||||
#include "prefapi.h"
|
||||
#include "intl_csi.h"
|
||||
|
||||
#define LLOYD_HACK 1
|
||||
|
||||
/*
|
||||
** This code is sometimes called "The Text Front End", because it is a set
|
||||
** of front end routines that deal with conversion of HTML to text, but it
|
||||
** is more accurately the "Plain Text Converter". IMHO a "Text Front End"
|
||||
** is something like Lynx.
|
||||
**
|
||||
** The basic strategy for the text front end is to collect bits in an internal
|
||||
** buffer until it is known that no more data will be written into the area
|
||||
** covered by that buffer, and at that point, output all the characters in
|
||||
** the buffer.
|
||||
**
|
||||
** So far this file is almost entirely Michael Toy's fault. Eventually
|
||||
** someone else will have to own this code, since Michael is showing
|
||||
** signs of having been lobotomized.
|
||||
*/
|
||||
|
||||
/*
|
||||
** 11-20-96 pchen
|
||||
**
|
||||
** Added some XP_MAC's because we need construction of our new front end
|
||||
** context object.
|
||||
**
|
||||
** ****************** NOTE! ******************
|
||||
** If we ever override more context functions (i.e. implement stubbed
|
||||
** out TXFE_* functions in stubs.c), you need to let a MacFE person
|
||||
** know about the changes.
|
||||
**
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef XP_MAC
|
||||
/* MacFE callbacks */
|
||||
extern MWContext* CreatePlainTextConversionContext(MWContext* inUIContext);
|
||||
extern void DisposePlainTextConversionContext(MWContext* inContext);
|
||||
#endif /* XP_MAC */
|
||||
|
||||
/*
|
||||
** This is the structure used to cache previously written on lines until
|
||||
** such a time as it looks like they are needed.
|
||||
*/
|
||||
struct LineRecord_struct {
|
||||
struct LineRecord_struct *next;
|
||||
char *buffer;
|
||||
int buffer_size;
|
||||
int y_top;
|
||||
};
|
||||
|
||||
/*
|
||||
** prepare_to_render
|
||||
** This routine makes sure that that rendering at "y" can be done
|
||||
** by simply ignoring y and writing wherever the x value says to.
|
||||
**
|
||||
** What it does is build a singly linked list of LineRec's,
|
||||
** and sets the cs->prInfo->line to point to the buffer field
|
||||
** of the appropriate LineRecord.
|
||||
*/
|
||||
PRIVATE void
|
||||
prepare_to_render(MWContext* cx, int y)
|
||||
{
|
||||
LineRecord *cur, *lr, *last;
|
||||
|
||||
/*
|
||||
** Search for a line which covers this area already
|
||||
*/
|
||||
last = cur = NULL;
|
||||
for (lr = cx->prInfo->saved_lines; lr != NULL; lr = lr->next) {
|
||||
if (y+TEXT_HEIGHT/2 >= lr->y_top && y+TEXT_HEIGHT/2 < lr->y_top+TEXT_HEIGHT)
|
||||
{
|
||||
cur = lr;
|
||||
break;
|
||||
}
|
||||
if (y+TEXT_HEIGHT/2 < lr->y_top)
|
||||
break;
|
||||
last = lr;
|
||||
}
|
||||
|
||||
if (cur == NULL) {
|
||||
/*
|
||||
** Need to add a new line structure which covers the area spanned
|
||||
** by this item.
|
||||
*/
|
||||
if ((cur = XP_NEW(LineRecord)) == NULL) {
|
||||
cx->prInfo->line = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
cur->y_top = y;
|
||||
if ((cur->buffer = (char *) XP_ALLOC(LINE_WIDTH)) == NULL) {
|
||||
XP_DELETE(cur);
|
||||
cx->prInfo->line = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
cur->next = NULL;
|
||||
XP_MEMSET(cur->buffer, ' ', LINE_WIDTH);
|
||||
cur->buffer_size = LINE_WIDTH;
|
||||
|
||||
if (last == NULL) {
|
||||
cur->next = cx->prInfo->saved_lines;
|
||||
cx->prInfo->saved_lines = cur;
|
||||
} else {
|
||||
cur->next = last->next;
|
||||
last->next = cur;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** In either case, "cur" now points to the LineRecord for the
|
||||
** current item.
|
||||
*/
|
||||
cx->prInfo->line = cur->buffer;
|
||||
}
|
||||
|
||||
PRIVATE void
|
||||
default_completion(PrintSetup* p)
|
||||
{
|
||||
XP_FileClose(p->out);
|
||||
}
|
||||
|
||||
PRIVATE void
|
||||
tx_alldone(URL_Struct *URL_s, int status, MWContext *window_id)
|
||||
{
|
||||
window_id->prSetup->status = status;
|
||||
}
|
||||
|
||||
PUBLIC void
|
||||
XL_InitializeTextSetup(PrintSetup *p)
|
||||
{
|
||||
XP_BZERO(p, sizeof *p);
|
||||
p->width = 76; /* don't use 79 here, or adding ">" makes it wrap. -jwz */
|
||||
p->prefix = "";
|
||||
p->eol = LINEBREAK;
|
||||
p->completion = default_completion;
|
||||
}
|
||||
|
||||
PRIVATE void
|
||||
real_discard_translation_context(void *vcx)
|
||||
{
|
||||
MWContext *cx = (MWContext *)vcx;
|
||||
|
||||
if (cx) {
|
||||
if (cx->prInfo) {
|
||||
XP_DELETE(cx->prInfo);
|
||||
}
|
||||
if (cx->prSetup) XP_DELETE(cx->prSetup);
|
||||
#ifndef XP_MAC
|
||||
if (cx->funcs) XP_DELETE(cx->funcs);
|
||||
XP_DELETE(cx);
|
||||
#else
|
||||
DisposePlainTextConversionContext(cx);
|
||||
#endif /* ndef XP_MAC */
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Hack alert.
|
||||
* 06-21-96 GAB 3.0 Beta 5 Critical Bug #23283
|
||||
*
|
||||
* When translating text in the composition window (quoting a
|
||||
* message) and the window is closed, this context is
|
||||
* interrupted. On interruption, AllConnectionsComplete
|
||||
* gets called, which in turn calls this function.
|
||||
* Previous incantation deleted the context and it's data; upon
|
||||
* return to NET_InterruptWindow, the netlib attempts to
|
||||
* reference the context (now freed), and we have an
|
||||
* access violation.
|
||||
* In order to avoid to problem, we set a timeout to delete
|
||||
* ourselves at a later time (2 seconds later).
|
||||
*/
|
||||
PRIVATE void
|
||||
discard_translation_context(MWContext *cx)
|
||||
{
|
||||
FE_SetTimeout(real_discard_translation_context, (void *)cx, 2000);
|
||||
}
|
||||
|
||||
PUBLIC void TXFE_AllConnectionsComplete(MWContext *cx)
|
||||
{
|
||||
(*cx->prSetup->completion)(cx->prSetup);
|
||||
LO_DiscardDocument(cx);
|
||||
discard_translation_context(cx);
|
||||
}
|
||||
|
||||
MODULE_PRIVATE void
|
||||
TXFE_SetCallNetlibAllTheTime(MWContext *cx)
|
||||
{
|
||||
(*cx->prInfo->scnatt)(NULL);
|
||||
}
|
||||
|
||||
MODULE_PRIVATE void
|
||||
TXFE_ClearCallNetlibAllTheTime(MWContext *cx)
|
||||
{
|
||||
(*cx->prInfo->ccnatt)(NULL);
|
||||
}
|
||||
|
||||
PUBLIC void
|
||||
XL_AbortTextTranslation(XL_TextTranslation tt)
|
||||
{
|
||||
MWContext* cx = (MWContext*) tt;
|
||||
NET_InterruptStream(cx->prSetup->url);
|
||||
}
|
||||
|
||||
PUBLIC XL_TextTranslation
|
||||
XL_TranslateText(MWContext* cx, URL_Struct *url_struct, PrintSetup* pi)
|
||||
{
|
||||
int nfd;
|
||||
#ifndef XP_MAC
|
||||
MWContext *text_context = XP_NewContext();
|
||||
#else
|
||||
MWContext *text_context = CreatePlainTextConversionContext(cx);
|
||||
#endif /* ndef XP_MAC */
|
||||
XP_Bool citation_p;
|
||||
INTL_CharSetInfo text_csi;
|
||||
|
||||
if (text_context == NULL || pi == NULL || pi->out == NULL)
|
||||
return NULL;
|
||||
|
||||
text_csi = LO_GetDocumentCharacterSetInfo(text_context);
|
||||
text_context->type = MWContextText;
|
||||
text_context->prInfo = XP_NEW(PrintInfo);
|
||||
#ifndef XP_MAC
|
||||
text_context->funcs = XP_NEW(ContextFuncs);
|
||||
#endif /* ndef XP_MAC */
|
||||
text_context->prSetup = XP_NEW(PrintSetup);
|
||||
if (text_context->funcs == NULL || text_context->prSetup == NULL
|
||||
|| text_context->prInfo == NULL)
|
||||
{
|
||||
discard_translation_context(text_context);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifndef XP_MAC
|
||||
#define MAKE_FE_FUNCS_PREFIX(f) TXFE_##f
|
||||
#define MAKE_FE_FUNCS_ASSIGN text_context->funcs->
|
||||
#include "mk_cx_fn.h"
|
||||
#endif /* ndef XP_MAC */
|
||||
|
||||
text_context->convertPixX = 1;
|
||||
text_context->convertPixY = 1;
|
||||
text_context->prInfo->page_width = pi->width * TEXT_WIDTH;
|
||||
if (cx && cx->funcs) {
|
||||
text_context->prInfo->scnatt = cx->funcs->SetCallNetlibAllTheTime;
|
||||
text_context->prInfo->ccnatt = cx->funcs->ClearCallNetlibAllTheTime;
|
||||
}
|
||||
*text_context->prSetup = *pi;
|
||||
text_context->prInfo->page_break = 0;
|
||||
#ifdef LLOYD_HACK
|
||||
text_context->prInfo->in_table = TRUE;
|
||||
#else
|
||||
text_context->prInfo->in_table = FALSE;
|
||||
#endif
|
||||
text_context->prInfo->first_line_p = TRUE;
|
||||
text_context->prInfo->saved_lines = NULL;
|
||||
text_context->prInfo->line = NULL;
|
||||
text_context->prInfo->last_y = 0;
|
||||
|
||||
text_context->prSetup->url = url_struct;
|
||||
|
||||
#ifndef XP_MAC
|
||||
INTL_SetCSIDocCSID(text_csi, INTL_DefaultDocCharSetID(cx)); /* For char code conversion */
|
||||
INTL_SetCSIWinCSID(text_csi, INTL_DefaultWinCharSetID(cx)); /* For char code conversion */
|
||||
#endif /* ndef XP_MAC */
|
||||
|
||||
url_struct->position_tag = 0;
|
||||
|
||||
/* Assume this is a news or mail citation if there is a prefix string.
|
||||
We use a different format-out in this case so that mknews.c can be
|
||||
more clever about this sort of thing. */
|
||||
citation_p = pi->prefix && *pi->prefix;
|
||||
|
||||
/* strip off any named anchor information so that we don't
|
||||
* truncate the document when quoting or saving
|
||||
*/
|
||||
if(url_struct->address)
|
||||
XP_STRTOK(url_struct->address, "#");
|
||||
nfd = NET_GetURL (url_struct,
|
||||
(citation_p ? FO_QUOTE_MESSAGE : FO_SAVE_AS_TEXT),
|
||||
text_context,
|
||||
tx_alldone);
|
||||
|
||||
/* 5-31-96 jefft -- bug # 21519
|
||||
* If for some reason we failed on getting URL return NULL.
|
||||
* At this point text_context has been free'd somewhere down the
|
||||
* chain through discard_translation_context(cx). text_context
|
||||
* became invalid.
|
||||
*/
|
||||
if ( nfd < 0 ) return NULL;
|
||||
|
||||
return text_context;
|
||||
}
|
||||
|
||||
PRIVATE void
|
||||
measure_text(LO_TextStruct *text, LO_TextInfo *text_info, int start, int end)
|
||||
{
|
||||
text_info->ascent = TEXT_HEIGHT/2;
|
||||
text_info->descent = TEXT_HEIGHT - text_info->ascent;
|
||||
text_info->max_width = TEXT_WIDTH*(end-start+1);
|
||||
text_info->lbearing = 0;
|
||||
text_info->rbearing = 0;
|
||||
}
|
||||
|
||||
MODULE_PRIVATE int
|
||||
TXFE_GetTextInfo(MWContext *cx, LO_TextStruct *text, LO_TextInfo *text_info)
|
||||
{
|
||||
measure_text(text, text_info, 0, text->text_len-1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
MODULE_PRIVATE void
|
||||
TXFE_LayoutNewDocument(MWContext *cx, URL_Struct *url, int32 *w, int32 *h, int32* mw, int32* mh)
|
||||
{
|
||||
*w = cx->prInfo->page_width;
|
||||
*h = 0;
|
||||
*mw = *mh = 0;
|
||||
}
|
||||
|
||||
PRIVATE void
|
||||
text_at(MWContext *cx, int x, char *str, int len)
|
||||
{
|
||||
int line_width = LINE_WIDTH;
|
||||
|
||||
if (cx->prInfo->line == NULL) {
|
||||
/*
|
||||
** Something is wrong, either prepare_to_render wasn't called,
|
||||
** which is a bug, or prepare_to_render failed to malloc enough
|
||||
** space for the line buffer.
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
/* x counts for number of bytes previously wrote to the line */
|
||||
x = (x + TEXT_WIDTH/2) / TEXT_WIDTH;
|
||||
|
||||
/***** 5/26/96 jefft -- bug# 21360
|
||||
* if the len is >= to the default LINE_WIDTH we have to
|
||||
* reallocate the line buffer. Otherwise, we will end up truncating
|
||||
* the message. That would be really bad.
|
||||
*/
|
||||
if ( len + x >= LINE_WIDTH ) {
|
||||
register LineRecord *cur = NULL;
|
||||
|
||||
line_width = len + x;
|
||||
|
||||
for ( cur = cx->prInfo->saved_lines; cur; cur = cur->next ) {
|
||||
if ( cur->buffer == cx->prInfo->line ) break;
|
||||
}
|
||||
|
||||
XP_ASSERT (cur);
|
||||
/* don't really know this is right */
|
||||
if ( !cur) return;
|
||||
/* plus one accounts for the null character at the end */
|
||||
cx->prInfo->line = XP_REALLOC (cx->prInfo->line, line_width+1);
|
||||
if ( cx->prInfo->line == NULL ) return;
|
||||
/* starts with +x; we don't want to wipe out the previously wrote
|
||||
* strings, i.e. "< " quote strings
|
||||
*/
|
||||
XP_MEMSET ( cx->prInfo->line+x, ' ', len+1 );
|
||||
cur->buffer = cx->prInfo->line;
|
||||
cur->buffer_size = line_width+1;
|
||||
}
|
||||
|
||||
while (x < line_width && len > 0) {
|
||||
cx->prInfo->line[x] = *str++;
|
||||
x++;
|
||||
len--;
|
||||
}
|
||||
}
|
||||
|
||||
MODULE_PRIVATE void
|
||||
TXFE_DisplaySubtext(MWContext *cx, int iLocation, LO_TextStruct *text,
|
||||
int32 start_pos, int32 end_pos, XP_Bool notused)
|
||||
{
|
||||
int x;
|
||||
LO_TextInfo i;
|
||||
x = text->x + text->x_offset;
|
||||
measure_text(text, &i, 0, start_pos-1); /* XXX too much work */
|
||||
if (start_pos) {
|
||||
x += i.max_width;
|
||||
}
|
||||
prepare_to_render(cx, text->y);
|
||||
text_at(cx, x, (char*) text->text, end_pos - start_pos + 1);
|
||||
}
|
||||
|
||||
MODULE_PRIVATE void
|
||||
TXFE_DisplayText(MWContext *cx, int iLocation, LO_TextStruct *text, XP_Bool needbg)
|
||||
{
|
||||
(cx->funcs->DisplaySubtext)(cx, iLocation, text, 0, text->text_len-1, needbg);
|
||||
}
|
||||
|
||||
MODULE_PRIVATE void
|
||||
TXFE_DisplaySubDoc(MWContext *cx, int iLocation, LO_SubDocStruct *subdoc_struct)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
** writeln
|
||||
** Evidence that I once programmed in Pascal :). This routine
|
||||
** writes out the passed buffer, prepending the correct prefix,
|
||||
** stripping trailing spaces, and appending the correct line
|
||||
** termination;
|
||||
*/
|
||||
PRIVATE void
|
||||
writeln(MWContext *cx, char* s, int line_width)
|
||||
{
|
||||
char *buf = NULL;
|
||||
char *cp=NULL;
|
||||
char *prefix = cx->prSetup->prefix;
|
||||
INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(cx);
|
||||
int16 win_csid = INTL_GetCSIWinCSID(csi);
|
||||
|
||||
#ifdef USE_LINE_WIDTH
|
||||
assert(cx->prSetup->prefix==NULL || strlen(cx->prSetup->prefix)<=LINE_WIDTH);
|
||||
#else
|
||||
assert(cx->prSetup->prefix==NULL || strlen(cx->prSetup->prefix)<=line_width);
|
||||
#endif
|
||||
|
||||
buf = (char *) XP_ALLOC ( line_width << 1 );
|
||||
|
||||
/* If this is the first line, and the document is of type message/rfc822,
|
||||
and there is a prefix, then we are in the ``Quote Document'' code for
|
||||
a news or mail message. This means that the message/rfc822 converter
|
||||
is going to emit a line like ``In <blah> foo@bar.com wrote:'' and we
|
||||
should not prepend that line with "> ".
|
||||
*/
|
||||
if (cx->prInfo->first_line_p)
|
||||
{
|
||||
if (cx->prSetup->url &&
|
||||
(!strcasecomp (cx->prSetup->url->content_type, MESSAGE_RFC822) ||
|
||||
!strcasecomp (cx->prSetup->url->content_type, MESSAGE_NEWS)))
|
||||
prefix = 0;
|
||||
cx->prInfo->first_line_p = FALSE;
|
||||
}
|
||||
|
||||
if (s != NULL) {
|
||||
for (cp = s+line_width-2; cp >= s; cp--)
|
||||
if (*cp != ' ') {
|
||||
cp[1] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (prefix)
|
||||
XP_STRCPY(buf, prefix);
|
||||
else
|
||||
*buf = 0;
|
||||
if (s != NULL && cp >= s)
|
||||
XP_STRCAT(buf, s);
|
||||
XP_STRCAT(buf, cx->prSetup->eol);
|
||||
|
||||
/* Convert nobreakspace to space.
|
||||
Maybe this is wrong... */
|
||||
/*
|
||||
<ftang>
|
||||
Answer: Yes, this is wrong.
|
||||
\240 (0xA0) is not nobreakspace in many encoding.
|
||||
It could be
|
||||
DAGGER in MacRoman
|
||||
LATIN CAPITAL LETTER YACUTE in MacRoman Icelandic and Faroese variations
|
||||
characters in any other Macintosh character set.
|
||||
The second byte of ShiftJIS characters
|
||||
|
||||
See Bug # 6640
|
||||
|
||||
for (s = buf; *s; s++)
|
||||
if (*((unsigned char *) s) == '\240')
|
||||
*s = ' ';
|
||||
*/
|
||||
/*
|
||||
void INTL_StripNBSP(int16 csid, char* buf)
|
||||
*/
|
||||
if (CS_USER_DEFINED_ENCODING != win_csid)
|
||||
{ /* strip out NBSP */
|
||||
const char* nbsp = INTL_NonBreakingSpace(win_csid);
|
||||
int nbsplen = XP_STRLEN(nbsp);
|
||||
char* out;
|
||||
char* next;
|
||||
char* boundary = buf + XP_STRLEN(buf) - nbsplen;
|
||||
XP_ASSERT((win_csid != CS_DEFAULT) && (win_csid != CS_UNKNOWN));
|
||||
for (s = out = buf; *s;)
|
||||
{
|
||||
char* next = INTL_NextChar(win_csid, s);
|
||||
if( (s <= boundary) && (0 == XP_STRNCMP(s, nbsp, nbsplen)))
|
||||
{ /* if it is nbsp, replace it with space and advance the pointer */
|
||||
*out = ' ';
|
||||
out++;
|
||||
s = next;
|
||||
}
|
||||
else
|
||||
{ /* if it is not nbsp, copy it */
|
||||
for( ;s < next; s++, out++)
|
||||
*out = *s;
|
||||
}
|
||||
}
|
||||
*out = '\0'; /* NULL terminate it*/
|
||||
}
|
||||
XP_FileWrite(buf, XP_STRLEN(buf), cx->prSetup->out);
|
||||
|
||||
XP_FREE (buf);
|
||||
}
|
||||
|
||||
/*
|
||||
** expire_lines
|
||||
** Write out data from the cache. If expire_all is TRUE
|
||||
** then that is the secret code to dump the entire cache (at the end
|
||||
** of the document.
|
||||
*/
|
||||
PRIVATE void
|
||||
expire_lines(MWContext *cx, int bottom, XP_Bool expire_all)
|
||||
{
|
||||
LineRecord *cur, *next;
|
||||
|
||||
for (cur = (LineRecord *)cx->prInfo->saved_lines; cur != NULL; cur = next) {
|
||||
if (!expire_all && cur->y_top > bottom)
|
||||
return;
|
||||
cx->prInfo->saved_lines = (LineRecord *)cur->next;
|
||||
next = cur->next;
|
||||
if ((cur->y_top - cx->prInfo->last_y) > TEXT_HEIGHT/2)
|
||||
writeln(cx, NULL, LINE_WIDTH);
|
||||
writeln(cx, cur->buffer, cur->buffer_size);
|
||||
cx->prInfo->last_y = cur->y_top + TEXT_HEIGHT;
|
||||
XP_FREE(cur->buffer);
|
||||
XP_FREE(cur);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** TXFE_DisplayTable
|
||||
** This routine arranges that lines will be cached for the entire
|
||||
** span of the table, since table data is not drawn from top
|
||||
** top bottom.
|
||||
**
|
||||
** It is SUPPOSED to draw borders, but doesn't, mostly because
|
||||
** there is no way to tell the layout engine that borders are
|
||||
** the thickness of a character.
|
||||
*/
|
||||
|
||||
MODULE_PRIVATE
|
||||
void TXFE_DisplayTable(MWContext *cx, int iLoc, LO_TableStruct *table)
|
||||
{
|
||||
if (cx->prInfo->in_table)
|
||||
return;
|
||||
cx->prInfo->table_top = table->y;
|
||||
cx->prInfo->table_bottom = table->y + table->line_height;
|
||||
#ifndef LLOYD_HACK
|
||||
cx->prInfo->in_table = TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** TXFE_DisplayLineFeed
|
||||
** Here it is that text actually gets emitted from the translation.
|
||||
** If there is reason to believe that some of the old cached lines are
|
||||
** 'finished', those lines are written out and wiped from the cache.
|
||||
*/
|
||||
|
||||
MODULE_PRIVATE void
|
||||
TXFE_DisplayLineFeed(MWContext *cx, int iLocation, LO_LinefeedStruct *line_feed, XP_Bool notused)
|
||||
{
|
||||
int my_bottom = line_feed->y + line_feed->line_height;
|
||||
if (cx->prInfo->in_table) {
|
||||
#ifndef LLOYD_HACK
|
||||
if (line_feed->y >= cx->prInfo->table_bottom)
|
||||
{
|
||||
expire_lines(cx, cx->prInfo->table_bottom, FALSE);
|
||||
cx->prInfo->in_table = FALSE;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
expire_lines(cx, my_bottom, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** TXFE_DisplayHR
|
||||
** XXX I want this routine to use "=" if the HR is a "thick" one.
|
||||
**
|
||||
*/
|
||||
MODULE_PRIVATE void
|
||||
TXFE_DisplayHR(MWContext *cx, int iLocation , LO_HorizRuleStruct *HR)
|
||||
{
|
||||
int x, left;
|
||||
int32 width = 72;
|
||||
|
||||
/*
|
||||
** jefft -- You may say this is a hack. Indeed, it is a hack. In order
|
||||
** to preserve the plain text line format when quoting we set the print->width
|
||||
** with a extreme large number 998 so that we won't have long/short wrapping
|
||||
** pattern (refer to lib/libmsg/msgcpane.cpp MSG_CompositionPane::QuoteMessage())
|
||||
** This causes problem when quoting a multipart/mixed text/plain message +
|
||||
** text/plain attachment. It creates an extremely long line of separator.
|
||||
** It seems reasonable to do some adjustment here to limit the width of
|
||||
** the separator to the setting of current wrap long line length.
|
||||
**/
|
||||
PREF_GetIntPref("mailnews.wraplength", &width);
|
||||
|
||||
width *= TEXT_WIDTH; /* in pixel */
|
||||
left = x = (TEXT_WIDTH << 1) + HR->x_offset;
|
||||
|
||||
if (HR->width < width) {
|
||||
/* BUG 83737 -- since the line separator has been centered within
|
||||
** the window's coordinate we might as well adjust the start of the
|
||||
** x.
|
||||
*/
|
||||
width = HR->width;
|
||||
left = x = HR->x + HR->x_offset;
|
||||
}
|
||||
|
||||
prepare_to_render(cx, HR->y);
|
||||
for (; x < left + width; x += TEXT_WIDTH)
|
||||
text_at(cx, x, "-", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
** TXFE_TranslateISOText
|
||||
** This assumes the text is already ISO. This is wrong, it should call
|
||||
** the correct front end translation routine. I have some vague memory
|
||||
** that perhaps the Mac front end patches out this function pointer
|
||||
** but it is something which should be looked into
|
||||
*/
|
||||
|
||||
MODULE_PRIVATE char *
|
||||
TXFE_TranslateISOText(MWContext *cx, int charset, char *ISO_Text)
|
||||
{
|
||||
return ISO_Text;
|
||||
}
|
||||
|
||||
/*
|
||||
** XL_DisplayTextImage
|
||||
** Just display the alt text. It currently displays in the upper left
|
||||
** of the image rectangle. Perhaps in future it should try and center
|
||||
** the alt text in the image.
|
||||
*/
|
||||
PUBLIC void
|
||||
XL_DisplayTextImage(MWContext *cx, int iLocation, LO_ImageStruct *img)
|
||||
{
|
||||
int x = img->x + img->x_offset;
|
||||
char *p;
|
||||
|
||||
prepare_to_render(cx, img->y);
|
||||
if (img->alt_len > 0) {
|
||||
PA_LOCK(p, char*, img->alt);
|
||||
if (*p != '[')
|
||||
text_at(cx, x, "[", 1);
|
||||
text_at(cx, x+TEXT_WIDTH, p, img->alt_len);
|
||||
if (p[img->alt_len-1] != ']')
|
||||
text_at(cx, x+TEXT_WIDTH*(img->alt_len+1), "]", 1);
|
||||
PA_UNLOCK(img->alt);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** XL_GetTextImage
|
||||
** All images are ignored in the text front end. This routine is
|
||||
** just here to insure that layout doesn't block and that all images
|
||||
** at least have the default ALT tag text.
|
||||
*/
|
||||
PRIVATE char img[] = "Image";
|
||||
PUBLIC void
|
||||
XL_GetTextImage(LO_ImageStruct *image)
|
||||
{
|
||||
if (image->alt_len == 0)
|
||||
if (image->alt == NULL)
|
||||
{
|
||||
/*
|
||||
** No ALT tag specified, insert make it appear as [Image]
|
||||
*/
|
||||
char *p;
|
||||
if ((image->alt = PA_ALLOC((sizeof img) - 1)) == NULL) {
|
||||
image->width = 1;
|
||||
image->height = 1;
|
||||
return;
|
||||
}
|
||||
image->alt_len = (sizeof img) - 1;
|
||||
p = PA_LOCK(p, char*, image->alt);
|
||||
XP_MEMMOVE(p, img, (sizeof img) - 1);
|
||||
PA_UNLOCK(image->alt);
|
||||
}
|
||||
else
|
||||
{
|
||||
image->width = 1;
|
||||
image->height = 1;
|
||||
}
|
||||
image->width = TEXT_WIDTH*(2+image->alt_len);
|
||||
image->height = TEXT_HEIGHT;
|
||||
}
|
||||
|
||||
/*
|
||||
** TXFE_DisplayBullet
|
||||
**
|
||||
** The only magic here is the calculation about how far to back up
|
||||
** in order to get the bullet at the correct location. The calculation
|
||||
** is based on reading the layout code for bulleted lists.
|
||||
*/
|
||||
MODULE_PRIVATE void
|
||||
TXFE_DisplayBullet(MWContext *cx, int iLocation, LO_BullettStruct *bullet)
|
||||
{
|
||||
int x = bullet->x + bullet->x_offset;
|
||||
|
||||
prepare_to_render(cx, bullet->y);
|
||||
x += 2*bullet->width;
|
||||
x -= 2*TEXT_WIDTH;
|
||||
switch (bullet->bullet_type) {
|
||||
case BULLET_ROUND:
|
||||
text_at(cx, x, "o", 1);
|
||||
break;
|
||||
case BULLET_BASIC:
|
||||
text_at(cx, x, "*", 1);
|
||||
break;
|
||||
case BULLET_SQUARE:
|
||||
text_at(cx, x, "+", 1);
|
||||
break;
|
||||
case BULLET_MQUOTE:
|
||||
text_at(cx, x, ">", 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
MODULE_PRIVATE void
|
||||
TXFE_DisplayBorder(MWContext *context, int iLocation, int x, int y, int width,
|
||||
int height, int bw, LO_Color *color, LO_LineStyle style)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MODULE_PRIVATE void
|
||||
TXFE_DisplayFeedback(MWContext *context, int iLocation, LO_Element *element)
|
||||
{
|
||||
}
|
||||
|
||||
MODULE_PRIVATE void
|
||||
TXFE_FinishedLayout(MWContext *cx)
|
||||
{
|
||||
expire_lines(cx, 0, TRUE);
|
||||
}
|
||||
|
||||
MODULE_PRIVATE char *
|
||||
TXFE_PromptPassword(MWContext *cx, const char *msg)
|
||||
{
|
||||
MWContext *wincx = cx->prSetup->cx;
|
||||
/* If we don't have a context, go find one. This is really a hack, we may
|
||||
* attach to some random window, but at least the print/saveas/etc will
|
||||
* still work. Our caller can prevent this by actually setting cx->prSetup->cx
|
||||
* to something that will really stay around until the save or print is
|
||||
* complete */
|
||||
if (wincx == NULL) {
|
||||
wincx = XP_FindSomeContext();
|
||||
}
|
||||
|
||||
if (wincx != NULL)
|
||||
return FE_PromptPassword(wincx, msg);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -1,289 +0,0 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
** All the wonderful code for dealing with images
|
||||
*/
|
||||
#define JMC_INIT_PSIMGCB_ID
|
||||
|
||||
#include "xlate_i.h"
|
||||
#include "libimg.h" /* Image Library public API. */
|
||||
#include "il_util.h" /* Colormap/Colorspace API. */
|
||||
|
||||
/* Create and initialize the Image Library JMC callback interface.
|
||||
Also create an IL_GroupContext for the current context. */
|
||||
XP_Bool
|
||||
psfe_init_image_callbacks(MWContext *cx)
|
||||
{
|
||||
IL_GroupContext *img_cx;
|
||||
PSIMGCB* img_cb;
|
||||
JMCException *exc = NULL;
|
||||
|
||||
if (!cx->img_cx) {
|
||||
img_cb = PSIMGCBFactory_Create(&exc); /* JMC Module */
|
||||
if (exc) {
|
||||
JMC_DELETE_EXCEPTION(&exc); /* XXXM12N Should really return
|
||||
exception */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Create an Image Group Context. IL_NewGroupContext augments the
|
||||
reference count for the JMC callback interface. The opaque argument
|
||||
to IL_NewGroupContext is the Front End's display context, which will
|
||||
be passed back to all the Image Library's FE callbacks. */
|
||||
img_cx = IL_NewGroupContext((void*)cx, (IMGCBIF *)img_cb);
|
||||
|
||||
/* Attach the IL_GroupContext to the FE's display context. */
|
||||
cx->img_cx = img_cx;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Image Library callbacks */
|
||||
/*****************************************************************************/
|
||||
|
||||
#define HOWMANY(x, r) (((x) + ((r) - 1)) / (r))
|
||||
#define ROUNDUP(x, r) (HOWMANY(x, r) * (r))
|
||||
|
||||
JMC_PUBLIC_API(void)
|
||||
_PSIMGCB_init(struct PSIMGCB* self, JMCException* *exception)
|
||||
{
|
||||
/* Nothing to be done here. */
|
||||
}
|
||||
|
||||
extern JMC_PUBLIC_API(void*)
|
||||
_PSIMGCB_getBackwardCompatibleInterface(struct PSIMGCB* self,
|
||||
const JMCInterfaceID* iid,
|
||||
JMCException* *exception)
|
||||
{
|
||||
return NULL; /* Nothing to be done here. */
|
||||
}
|
||||
|
||||
|
||||
/**************************** Pixmap creation ********************************/
|
||||
JMC_PUBLIC_API(void)
|
||||
_PSIMGCB_NewPixmap(PSIMGCB* img_cb, jint op, void *dpy_cx, jint width,
|
||||
jint height, IL_Pixmap *image, IL_Pixmap *mask)
|
||||
{
|
||||
uint8 img_depth, pixmap_depth;
|
||||
NI_PixmapHeader *img_header = &image->header;
|
||||
NI_PixmapHeader *mask_header = mask ? &mask->header : NULL;
|
||||
MWContext *context = (MWContext *)dpy_cx; /* XXXM12N This should be the
|
||||
FE's display context. */
|
||||
|
||||
|
||||
/* Determine the depth of the image. */
|
||||
pixmap_depth = context->color_space->pixmap_depth;
|
||||
|
||||
/* Override the image colorspace with the display colorspace. This
|
||||
instructs the image library to decode to the display colorspace
|
||||
instead of decoding to the image's source colorspace. */
|
||||
IL_ReleaseColorSpace(img_header->color_space);
|
||||
img_header->color_space = context->color_space;
|
||||
IL_AddRefToColorSpace(img_header->color_space);
|
||||
|
||||
/* Ask the image library to scale to the requested dimensions.
|
||||
Context-specific scaling, however, will be handled by the PSFE. */
|
||||
img_header->width = width;
|
||||
img_header->height = height;
|
||||
if (mask) {
|
||||
mask_header->width = width;
|
||||
mask_header->height = height;
|
||||
}
|
||||
|
||||
/* Compute the number of bytes per scan line for the image and mask,
|
||||
and make sure it is quadlet aligned. */
|
||||
img_depth = img_header->color_space->pixmap_depth;
|
||||
XP_ASSERT(img_depth == pixmap_depth);
|
||||
img_header->widthBytes = (img_header->width * img_depth + 7) / 8;
|
||||
img_header->widthBytes = ROUNDUP(img_header->widthBytes, 4);
|
||||
if (mask) {
|
||||
mask_header->widthBytes = (mask_header->width + 7) / 8;
|
||||
mask_header->widthBytes = ROUNDUP(mask_header->widthBytes, 4);
|
||||
}
|
||||
|
||||
/* Allocate memory for the image bits, and for the mask bits (if
|
||||
required.) */
|
||||
image->bits = calloc(img_header->widthBytes * img_header->height, 1);
|
||||
if (!image->bits)
|
||||
return;
|
||||
if (mask) {
|
||||
mask->bits = calloc(mask_header->widthBytes * mask_header->height, 1);
|
||||
if (!mask->bits) {
|
||||
free(image->bits);
|
||||
image->bits = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**************************** Pixmap update **********************************/
|
||||
JMC_PUBLIC_API(void)
|
||||
_PSIMGCB_UpdatePixmap(PSIMGCB* img_cb, jint op, void* dpy_cx,
|
||||
IL_Pixmap* pixmap, jint x_offset, jint y_offset,
|
||||
jint width, jint height)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/************************** Pixmap memory management *************************/
|
||||
JMC_PUBLIC_API(void)
|
||||
_PSIMGCB_ControlPixmapBits(PSIMGCB* img_cb, jint op, void* dpy_cx,
|
||||
IL_Pixmap* pixmap, IL_PixmapControl message)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**************************** Pixmap destruction *****************************/
|
||||
/* XXXM12N The dpy_cx argument is not used in DestroyPixmap and should be
|
||||
removed. */
|
||||
JMC_PUBLIC_API(void)
|
||||
_PSIMGCB_DestroyPixmap(PSIMGCB* img_cb, jint op, void* dpy_cx,
|
||||
IL_Pixmap* pixmap)
|
||||
{
|
||||
/* Free the pixmap's bits. */
|
||||
if (pixmap->bits) {
|
||||
free(pixmap->bits);
|
||||
pixmap->bits = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**************************** Pixmap display *********************************/
|
||||
JMC_PUBLIC_API(void)
|
||||
_PSIMGCB_DisplayPixmap(PSIMGCB* img_cb, jint op, void* dpy_cx,
|
||||
IL_Pixmap* image, IL_Pixmap* mask, jint x, jint y,
|
||||
jint x_offset, jint y_offset, jint width, jint height,
|
||||
jint req_w, jint req_h )
|
||||
{
|
||||
int32 img_x_offset, img_y_offset; /* Offset of image in drawable. */
|
||||
int32 rect_x_offset, rect_y_offset; /* Offset of update rect in
|
||||
drawable. */
|
||||
NI_PixmapHeader *img_header = &image->header;
|
||||
uint32 img_width = img_header->width; /* Image width. */
|
||||
uint32 img_height = img_header->height; /* Image height. */
|
||||
MWContext *context = (MWContext *)dpy_cx; /* XXX This should be the FE's
|
||||
display context. */
|
||||
XP_Bool tiling_required = FALSE;
|
||||
|
||||
/* Check for zero display area. */
|
||||
if (width == 0 || height == 0)
|
||||
return;
|
||||
|
||||
/* Perform context scaling. */
|
||||
x *= context->convertPixX;
|
||||
y *= context->convertPixY;
|
||||
x_offset *= context->convertPixX;
|
||||
y_offset *= context->convertPixY;
|
||||
width *= context->convertPixX;
|
||||
height *= context->convertPixY;
|
||||
img_width *= context->convertPixX;
|
||||
img_height *= context->convertPixY;
|
||||
|
||||
/* Determine whether tiling is required. */
|
||||
if ((x_offset + width > img_width) || (y_offset + height > img_height))
|
||||
tiling_required = TRUE;
|
||||
|
||||
/* Compute the offset into the drawable of the image origin. */
|
||||
img_x_offset = x; /* + fe_drawable->x_origin; */
|
||||
img_y_offset = y; /* + fe_drawable->y_origin; */
|
||||
|
||||
/* Check whether the image is ready to be displayed. */
|
||||
if (!XP_CheckElementSpan(context, img_y_offset, img_height))
|
||||
return;
|
||||
|
||||
/* Draw the image. */
|
||||
xl_colorimage(context, x, y, width, height, image, mask);
|
||||
}
|
||||
|
||||
|
||||
/**************************** Icon dimensions ********************************/
|
||||
JMC_PUBLIC_API(void)
|
||||
_PSIMGCB_GetIconDimensions(PSIMGCB* img_cb, jint op, void* dpy_cx, int* width,
|
||||
int* height, jint icon_number)
|
||||
{
|
||||
/* Call the screen FE to get the icon dimensions in pixels. */
|
||||
FE_GetPSIconDimensions(icon_number, width, height);
|
||||
}
|
||||
|
||||
|
||||
/**************************** Icon display ***********************************/
|
||||
JMC_PUBLIC_API(void)
|
||||
_PSIMGCB_DisplayIcon(PSIMGCB* img_cb, jint op, void* dpy_cx, jint x, jint y,
|
||||
jint icon_number)
|
||||
{
|
||||
int width; /* Width of the icon in context scaled coordinates. */
|
||||
int height; /* Height of the icon in context scaled coordinates. */
|
||||
int img_depth; /* Depth of the image. */
|
||||
MWContext *context = (MWContext *)dpy_cx;
|
||||
IL_Pixmap image; /* Image pixmap. */
|
||||
NI_PixmapHeader *img_header = &image.header;
|
||||
|
||||
/* Call the screen FE to get the icon dimensions in pixels. */
|
||||
FE_GetPSIconDimensions(icon_number, &width, &height);
|
||||
img_header->width = (int32)width;
|
||||
img_header->height = (int32)height;
|
||||
|
||||
/* Apply context scaling to the dimensions. */
|
||||
width *= context->convertPixX;
|
||||
height *= context->convertPixY;
|
||||
|
||||
/* Check whether we are ready to display the icon. */
|
||||
if (!XP_CheckElementSpan(context, y, height))
|
||||
return;
|
||||
|
||||
/* Don't attempt to display the icon if either dimension is zero. */
|
||||
if (!width || !height)
|
||||
return;
|
||||
|
||||
/* Get ourselves a colorspace. */
|
||||
img_header->color_space = context->color_space;
|
||||
IL_AddRefToColorSpace(img_header->color_space);
|
||||
|
||||
/* Allocate bits for the icon. We don't cache icons created for the
|
||||
purpose of printing. */
|
||||
img_depth = img_header->color_space->pixmap_depth;
|
||||
img_header->widthBytes = (img_header->width * img_depth + 7) / 8;
|
||||
img_header->widthBytes = ROUNDUP(img_header->widthBytes, 4);
|
||||
|
||||
/* Allocate memory for the image bits. */
|
||||
image.bits = calloc(img_header->widthBytes * img_header->height, 1);
|
||||
if (!image.bits) {
|
||||
IL_ReleaseColorSpace(img_header->color_space);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get the icon data from the screen FE and draw the icon. */
|
||||
if (FE_GetPSIconData(icon_number, &image, NULL))
|
||||
xl_colorimage(context, x, y, width, height, &image, NULL);
|
||||
|
||||
/* Clean up. */
|
||||
free(image.bits);
|
||||
IL_ReleaseColorSpace(img_header->color_space);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* End of Image Library callbacks */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user