NOT PART OF BUILD (Photon Only)

- many fixes (fonts, rendering, printing, crashes, image drawing)
This commit is contained in:
dinglis%qnx.com 2001-07-04 17:56:17 +00:00
Родитель 073bbd5813
Коммит 4cb3bc9f9d
13 изменённых файлов: 587 добавлений и 599 удалений

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

@ -43,7 +43,6 @@ static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
nscoord nsDeviceContextPh::mDpi = 96;
static nsHashtable* mFontLoadCache = nsnull;
static int globals_initialized = 0;
nsDeviceContextPh :: nsDeviceContextPh( ) {
NS_INIT_REFCNT();
@ -111,8 +110,6 @@ NS_IMETHODIMP nsDeviceContextPh :: Init( nsNativeWidget aWidget ) {
/* Called for Printing */
nsresult nsDeviceContextPh :: Init( nsNativeDeviceContext aContext, nsIDeviceContext *aOrigContext ) {
nsDeviceContextSpecPh * PrintSpec = nsnull;
PpPrintContext_t *PrinterContext = nsnull;
float origscale, newscale, t2d, a2d;
mDC = aContext;
@ -131,7 +128,6 @@ nsresult nsDeviceContextPh :: Init( nsNativeDeviceContext aContext, nsIDeviceCon
mDevUnitsToAppUnits = 1.0f / mAppUnitsToDevUnits;
// for printers
int width, height;
const PhDim_t *psize;
PhDim_t dim;
PpPrintContext_t *pc = ((nsDeviceContextSpecPh *)mSpec)->GetPrintContext();
@ -148,10 +144,9 @@ nsresult nsDeviceContextPh :: Init( nsNativeDeviceContext aContext, nsIDeviceCon
void nsDeviceContextPh :: GetPrinterRect( int *width, int *height ) {
PhDim_t dim;
const PhDim_t *psize;
const PhRect_t *mrect, *non_print;
const PhRect_t *non_print;
PhRect_t rect, margins;
const char *orientation = 0, *name = NULL;
char *ptr;
const char *orientation = 0;
int tmp;
PpPrintContext_t *pc = ((nsDeviceContextSpecPh *)mSpec)->GetPrintContext();
@ -205,7 +200,7 @@ void nsDeviceContextPh :: CommonInit( nsNativeDeviceContext aDC ) {
}
prefs->RegisterCallback( "browser.display.screen_resolution", prefChanged, (void *)this );
mDpi = prefVal;
if( prefVal >0 ) mDpi = prefVal;
}
}
@ -237,8 +232,8 @@ void nsDeviceContextPh :: CommonInit( nsNativeDeviceContext aDC ) {
/* Revisit: the scroll bar sizes is a gross guess based on Phab */
mScrollbarHeight = 17.0f;
mScrollbarWidth = 17.0f;
mScrollbarHeight = 17;
mScrollbarWidth = 17;
/* Call Base Class */
DeviceContextImpl::CommonInit( );
@ -270,6 +265,7 @@ NS_IMETHODIMP nsDeviceContextPh :: CreateRenderingContext( nsIRenderingContext *
if( NS_OK != rv ) NS_IF_RELEASE( pContext );
aContext = pContext;
NS_ADDREF( pContext ); // otherwise it's crashing after printing
return rv;
}
@ -351,20 +347,44 @@ NS_IMETHODIMP nsDeviceContextPh :: GetSystemAttribute( nsSystemAttrID anID, Syst
case eSystemAttr_Size_Widget3DBorder:
aInfo->mSize = 4;
break;
//---------
// Fonts
//---------
case eSystemAttr_Font_Caption:
case eSystemAttr_Font_Icon:
case eSystemAttr_Font_Menu:
case eSystemAttr_Font_MessageBox:
case eSystemAttr_Font_SmallCaption:
case eSystemAttr_Font_StatusBar:
case eSystemAttr_Font_Tooltips:
case eSystemAttr_Font_Widget:
status = NS_ERROR_FAILURE;
break;
} // switch
//---------
// Fonts
//---------
case eSystemAttr_Font_Caption: // css2
case eSystemAttr_Font_Icon:
case eSystemAttr_Font_Menu:
case eSystemAttr_Font_MessageBox:
case eSystemAttr_Font_SmallCaption:
case eSystemAttr_Font_StatusBar:
case eSystemAttr_Font_Window: // css3
case eSystemAttr_Font_Document:
case eSystemAttr_Font_Workspace:
case eSystemAttr_Font_Desktop:
case eSystemAttr_Font_Info:
case eSystemAttr_Font_Dialog:
case eSystemAttr_Font_Button:
case eSystemAttr_Font_PullDownMenu:
case eSystemAttr_Font_List:
case eSystemAttr_Font_Field:
case eSystemAttr_Font_Tooltips: // moz
case eSystemAttr_Font_Widget:
aInfo->mFont->style = NS_FONT_STYLE_NORMAL;
aInfo->mFont->weight = NS_FONT_WEIGHT_NORMAL;
aInfo->mFont->decorations = NS_FONT_DECORATION_NONE;
aInfo->mFont->name.AssignWithConversion("TextFont");
switch(anID) {
case eSystemAttr_Font_MessageBox:
aInfo->mFont->name.AssignWithConversion("MessageFont");
break;
case eSystemAttr_Font_Tooltips:
aInfo->mFont->name.AssignWithConversion("BalloonFont");
break;
case eSystemAttr_Font_Menu:
aInfo->mFont->name.AssignWithConversion("MenuFont");
break;
}
break;
} // switch
return NS_OK;
}
@ -395,7 +415,7 @@ NS_IMETHODIMP nsDeviceContextPh :: CheckFontExistence( const nsString& aFontName
if( fontName ) {
FontID *id = NULL;
if( id = PfFindFont( (uchar_t *)fontName, 0, 0 ) ) {
if( ( id = PfFindFont( (uchar_t *)fontName, 0, 0 ) ) ) {
if( !mFontLoadCache ) mFontLoadCache = new nsHashtable();
nsCStringKey key((char *)(id->pucStem));
@ -471,22 +491,13 @@ NS_IMETHODIMP nsDeviceContextPh :: GetDeviceContextFor( nsIDeviceContextSpec *aD
//then QI for the real object rather than casting... MMP
aContext = new nsDeviceContextPh();
if(nsnull != aContext){
NS_ADDREF(aContext);
} else {
return NS_ERROR_OUT_OF_MEMORY;
}
((nsDeviceContextPh *)aContext)->mSpec = aDevice;
PpPrintContext_t *pc = ((nsDeviceContextSpecPh*)(((nsDeviceContextPh *)aContext)->mSpec))->GetPrintContext();
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 ((nsDeviceContextPh *)aContext)->Init(NULL, this);
}
@ -517,40 +528,33 @@ int nsDeviceContextPh::prefChanged( const char *aPref, void *aClosure ) {
}
NS_IMETHODIMP nsDeviceContextPh :: BeginDocument( PRUnichar *t ) {
nsresult ret_code = NS_ERROR_FAILURE;
int err;
PpPrintContext_t *pc = ((nsDeviceContextSpecPh *)mSpec)->GetPrintContext();
PhDrawContext_t *dc = PhDCSetCurrent(NULL);
PhDCSetCurrent(dc);
PpStartJob(pc);
PpContinueJob(pc);
dc = PhDCSetCurrent(NULL);
PhDCSetCurrent(dc);
mIsPrinting = 1;
mIsPrinting = 1;
mIsPrintingStart = 1;
return NS_OK;
}
}
NS_IMETHODIMP nsDeviceContextPh :: EndDocument( void ) {
PpPrintContext_t *pc = ((nsDeviceContextSpecPh *)mSpec)->GetPrintContext();
PpSuspendJob(pc);
PpEndJob(pc);
mIsPrinting = 0;
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextPh :: BeginPage( void ) {
PpPrintContext_t *pc = ((nsDeviceContextSpecPh *)mSpec)->GetPrintContext();
if( !mIsPrintingStart ) PpPrintNewPage( pc );
PpContinueJob( pc );
mIsPrintingStart = 0;
return NS_OK;
}
}
NS_IMETHODIMP nsDeviceContextPh :: EndPage( void ) {
PpPrintNewPage(((nsDeviceContextSpecPh *)mSpec)->GetPrintContext());
PpPrintContext_t *pc = ((nsDeviceContextSpecPh *)mSpec)->GetPrintContext();
PpSuspendJob(pc);
return NS_OK;
}
}
int nsDeviceContextPh :: IsPrinting( void ) { return mIsPrinting ? 1 : 0; }
@ -564,7 +568,6 @@ nsresult nsDeviceContextPh :: GetDisplayInfo( PRInt32 &aWidth, PRInt32 &aHeight,
char *p = NULL;
int inp_grp;
PhRid_t rid;
PhRegion_t region;
/* Initialize variables */
aWidth = 0;

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

@ -106,7 +106,7 @@ protected:
static nscoord mDpi;
int mIsPrinting;
PRBool mIsPrinting, mIsPrintingStart;
private:
nsCOMPtr<nsIScreenManager> mScreenManager;

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

@ -71,6 +71,10 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryPh :: CreateDeviceContextSpec(nsIWidget
if (devSpec != nsnull)
{
PtWidget_t *widget = (PtWidget_t*) aWidget->GetNativeData( NS_NATIVE_WIDGET );
PtWidget_t *disjoint = PtFindDisjoint( widget );
if( !PtWidgetIsClass( disjoint, PtWindow ) ) aQuiet = 1; /* for the embedding stuff, the PrintSelection dialog is displayed by the client */
if (NS_OK == ((nsDeviceContextSpecPh *)devSpec)->Init(aQuiet))
{
aNewSpec = devSpec;

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

@ -26,23 +26,26 @@
#include "plstr.h"
#include "nsPhGfxLog.h"
#include "nsGfxCIID.h"
#include "nsIServiceManager.h"
#include "nsIPrintOptions.h"
static NS_DEFINE_IID( kDeviceContextSpecIID, NS_IDEVICE_CONTEXT_SPEC_IID );
static NS_DEFINE_CID( kPrintOptionsCID, NS_PRINTOPTIONS_CID );
nsDeviceContextSpecPh :: nsDeviceContextSpecPh()
{
NS_INIT_REFCNT();
mPC = nsnull;
mIsQuite = PR_FALSE;
}
nsDeviceContextSpecPh :: ~nsDeviceContextSpecPh()
{
if(!mIsQuite)
if (mPC)
PpPrintReleasePC(mPC);
if (mPC)
PpPrintReleasePC(mPC);
}
static NS_DEFINE_IID(kDeviceContextSpecIID, NS_IDEVICE_CONTEXT_SPEC_IID);
NS_IMPL_QUERY_INTERFACE(nsDeviceContextSpecPh, kDeviceContextSpecIID)
NS_IMPL_ADDREF(nsDeviceContextSpecPh)
NS_IMPL_RELEASE(nsDeviceContextSpecPh)
@ -51,36 +54,29 @@ NS_IMETHODIMP nsDeviceContextSpecPh :: Init(PRBool aQuiet)
{
int action;
nsresult rv = NS_OK;
if (aQuiet)
{
// no dialogs
if(mPC)
PpPrintReleasePC(mPC);
mIsQuite = PR_TRUE;
mPC = nsnull;
printf("Print: quiet\n");
if( aQuiet ) {
// no dialogs
NS_WITH_SERVICE( nsIPrintOptions, printService, kPrintOptionsCID, &rv);
PRInt32 value;
printService->GetEndPageRange( &value ); /* use SetEndPageRange/GetEndPageRange to convey the print context */
mPC = ( PpPrintContext_t * ) value;
}
else
{
if(!mPC)
mPC = PpCreatePC();
else {
if( !mPC ) mPC = PpCreatePC();
PtSetParentWidget(NULL);
action = PtPrintSelection(NULL, NULL, NULL, mPC, (Pt_PRINTSEL_DFLT_LOOK));
switch (action)
{
switch( action ) {
case Pt_PRINTSEL_PRINT:
case Pt_PRINTSEL_PREVIEW:
rv = NS_OK;
break;
rv = NS_OK;
break;
case Pt_PRINTSEL_CANCEL:
rv = NS_ERROR_FAILURE;
break;
rv = NS_ERROR_FAILURE;
break;
}
}
return rv;
return rv;
}
//NS_IMETHODIMP nsDeviceContextSpecPh :: GetPrintContext(PpPrintContext_t *&aPrintContext) const

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

@ -41,10 +41,7 @@ public:
protected:
virtual ~nsDeviceContextSpecPh();
PpPrintContext_t *mPC;
int mIsQuite;
};
#endif

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

@ -32,12 +32,6 @@
NS_IMPL_ISUPPORTS2( nsDrawingSurfacePh, nsIDrawingSurface, nsIDrawingSurfacePh )
nsDrawingSurfacePh :: nsDrawingSurfacePh( ) {
PhSysInfo_t sysinfo;
PhRect_t rect = {{0, 0}, {SHRT_MAX, SHRT_MAX}};
char *p;
int inp_grp;
PhRegion_t rid;
NS_INIT_REFCNT();
mDrawContext = nsnull;
@ -152,7 +146,6 @@ NS_IMETHODIMP nsDrawingSurfacePh :: Lock( PRInt32 aX, PRInt32 aY,
}
NS_IMETHODIMP nsDrawingSurfacePh :: Unlock( void ) {
PdOffscreenContext_t *off_dc = (PdOffscreenContext_t *) mDrawContext;
PhArea_t dst_area, src_area;
if( !mLocked ) return NS_ERROR_FAILURE;

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

@ -17,7 +17,7 @@
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*/
#include "xp_core.h"
@ -28,48 +28,49 @@
#include "nsIPref.h"
#include <errno.h>
#include <strings.h>
static int gGotAllFontNames = 0;
// XXX many of these statics need to be freed at shutdown time
static PLHashTable* gFamilies = nsnull;
static nsHashtable* gFontMetricsCache = nsnull;
static int gFontMetricsCacheCount = 0;
static nsCString **gFontNames = nsnull;
static FontDetails *gFontDetails = nsnull;
static int gnFonts = 0;
#undef USER_DEFINED
#define USER_DEFINED "x-user-def"
static NS_DEFINE_IID(kIFontMetricsIID, NS_IFONT_METRICS_IID);
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
nsFontMetricsPh :: nsFontMetricsPh()
{
NS_INIT_REFCNT();
mDeviceContext = nsnull;
mFont = nsnull;
mHeight = 0;
mAscent = 0;
mDescent = 0;
mLeading = 0;
mEmHeight = 0;
mEmAscent = 0;
mEmDescent = 0;
mMaxHeight = 0;
mMaxAscent = 0;
mMaxDescent = 0;
mMaxAdvance = 0;
mXHeight = 0;
mSuperscriptOffset = 0;
mSubscriptOffset = 0;
mStrikeoutSize = 0;
mStrikeoutOffset = 0;
mUnderlineSize = 0;
mUnderlineOffset = 0;
mSpaceWidth = 0;
mAveCharWidth = 0;
NS_INIT_REFCNT();
mDeviceContext = nsnull;
mFont = nsnull;
mHeight = 0;
mAscent = 0;
mDescent = 0;
mLeading = 0;
mEmHeight = 0;
mEmAscent = 0;
mEmDescent = 0;
mMaxHeight = 0;
mMaxAscent = 0;
mMaxDescent = 0;
mMaxAdvance = 0;
mXHeight = 0;
mSuperscriptOffset = 0;
mSubscriptOffset = 0;
mStrikeoutSize = 0;
mStrikeoutOffset = 0;
mUnderlineSize = 0;
mUnderlineOffset = 0;
mSpaceWidth = 0;
mAveCharWidth = 0;
}
static void InitGlobals()
@ -78,77 +79,77 @@ static void InitGlobals()
}
static PRBool
FreeFontMetricsCache(nsHashKey* aKey, void* aData, void* aClosure)
FreeFontMetricsCache(nsHashKey* aKey, void* aData, void* aClosure)
{
FontQueryInfo * node = (FontQueryInfo*) aData;
FontQueryInfo * node = (FontQueryInfo*) aData;
//delete node;
//delete node;
/* Use free() rather since we use calloc() in ::Init to alloc the node. */
if (node)
free (node);
if (node)
free (node);
return PR_TRUE;
return PR_TRUE;
}
static void FreeGlobals()
{
if (gFontMetricsCache) {
gFontMetricsCache->Reset(FreeFontMetricsCache, nsnull);
delete gFontMetricsCache;
gFontMetricsCache = nsnull;
gFontMetricsCacheCount = 0;
}
if (gFontMetricsCache)
{
gFontMetricsCache->Reset(FreeFontMetricsCache, nsnull);
delete gFontMetricsCache;
gFontMetricsCache = nsnull;
gFontMetricsCacheCount = 0;
}
}
nsFontMetricsPh :: ~nsFontMetricsPh( ) {
if( nsnull != mFont ) {
delete mFont;
mFont = nsnull;
}
nsFontMetricsPh :: ~nsFontMetricsPh( )
{
if( nsnull != mFont )
{
delete mFont;
mFont = nsnull;
}
mDeviceContext = nsnull;
if (mFontHandle)
free (mFontHandle);
free (mFontHandle);
FreeGlobals();
}
NS_IMPL_ISUPPORTS1( nsFontMetricsPh, nsIFontMetrics )
NS_IMETHODIMP nsFontMetricsPh :: Init ( const nsFont& aFont, nsIAtom* aLangGroup, nsIDeviceContext* aContext ) {
NS_IMETHODIMP nsFontMetricsPh :: Init ( const nsFont& aFont, nsIAtom* aLangGroup, nsIDeviceContext* aContext )
{
NS_ASSERTION(!(nsnull == aContext), "attempt to init fontmetrics with null device context");
NS_ASSERTION(!(nsnull == aContext), "attempt to init fontmetrics with null device context");
nsAutoString firstFace;
char *str = nsnull;
nsresult result;
nsresult ret_code = NS_ERROR_FAILURE;
int MAX_FONTDETAIL = 50;
FontDetails fDetails[MAX_FONTDETAIL];
int fontcount;
int index;
nsresult result;
PhRect_t extent;
if( !gFontMetricsCacheCount )
InitGlobals( );
mFont = new nsFont(aFont);
mLangGroup = aLangGroup;
mDeviceContext = aContext;
float app2dev;
mDeviceContext->GetAppUnitsToDevUnits(app2dev);
float textZoom = 1.0;
mDeviceContext->GetTextZoom(textZoom);
result = aContext->FirstExistingFont(aFont, firstFace);
str = firstFace.ToNewCString();
#if 0
/* ALAIN:What is this for? it does not serve any purpose. */
/* Commented out and see where things break. */
if( NS_OK != result ) {
aFont.GetFirstFamily(firstFace);
char *str = nsnull;
str = firstFace.ToNewCString();
delete [] str;
}
#endif
if( !str || !str[0] ) {
//delete [] str;
free (str);
str = strdup("serif");
}
if( !str || !str[0] )
{
//delete [] str;
free (str);
str = strdup("serif");
}
const PRUnichar *uc;
aLangGroup->GetUnicode( &uc );
@ -160,27 +161,25 @@ NS_ASSERTION(!(nsnull == aContext), "attempt to init fontmetrics with null devic
/* Free cstring. */
if (cstring)
//delete [] cstring;
free (cstring);
//delete [] cstring;
free (cstring);
char *font_default = NULL;
nsresult res = NS_ERROR_FAILURE;
NS_WITH_SERVICE( nsIPref, prefs, kPrefCID, &res );
if( res == NS_OK ) {
prefs->CopyCharPref( prop, &font_default );
if( font_default ) {
//delete [] str;
free (str);
if( res == NS_OK )
{
prefs->CopyCharPref( prop, &font_default );
if( font_default )
{
//delete [] str;
free (str);
/* font_default was allocated. in CopyCharPref. */
str = font_default;
}
}
str = font_default;
}
}
mFont = new nsFont(aFont);
mLangGroup = aLangGroup;
mDeviceContext = (nsDeviceContextPh *) aContext;
float app2dev, app2twip, scale = 1.0, textZoom = 1.0;
float app2twip, scale = 1.0;
mDeviceContext->GetAppUnitsToDevUnits(app2dev);
mDeviceContext->GetDevUnitsToTwips(app2twip);
@ -189,43 +188,41 @@ NS_ASSERTION(!(nsnull == aContext), "attempt to init fontmetrics with null devic
app2twip *= (app2dev * textZoom);
PRInt32 sizePoints = NSTwipsToFloorIntPoints(nscoord(mFont->size * app2twip * 0.90));
char NSFontName[64]; /* Local buffer to keep the fontname in */
char NSFontSuffix[5];
char NSFullFontName[MAX_FONT_TAG];
NSFontSuffix[0] = nsnull;
unsigned int uiFlags = 0L;
if(aFont.weight > NS_FONT_WEIGHT_NORMAL)
uiFlags |= PF_STYLE_BOLD;
uiFlags |= PF_STYLE_BOLD;
if(aFont.style & NS_FONT_STYLE_ITALIC)
uiFlags |= PF_STYLE_ITALIC;
uiFlags |= PF_STYLE_ITALIC;
if(aFont.style & NS_FONT_STYLE_OBLIQUE)
uiFlags |= PF_STYLE_ANTIALIAS;
uiFlags |= PF_STYLE_ANTIALIAS;
if( PfGenerateFontName( (const uchar_t *)str, uiFlags, sizePoints, (uchar_t *)NSFullFontName ) == NULL ) {
PfGenerateFontName( (const uchar_t *)"Courier 10 Pitch BT", uiFlags, sizePoints, (uchar_t *)NSFullFontName );
}
if( PfGenerateFontName( (const uchar_t *)str, uiFlags, sizePoints, (uchar_t *)NSFullFontName ) == NULL )
{
PfGenerateFontName( (const uchar_t *)"Courier 10 Pitch BT", uiFlags, sizePoints, (uchar_t *)NSFullFontName );
}
/* Once the Photon Font String is built get the attributes */
FontQueryInfo *node;
if( !gFontMetricsCacheCount )
InitGlobals( );
//nsStringKey key((char *)(NSFullFontName));
nsCStringKey key((char *)(NSFullFontName));
node = (FontQueryInfo *) gFontMetricsCache->Get(&key);
if( !node ) {
node = (FontQueryInfo *)calloc(sizeof(FontQueryInfo), 1);
PfQueryFont(NSFullFontName, node);
gFontMetricsCache->Put(&key, node);
gFontMetricsCacheCount++;
}
if( !node )
{
node = (FontQueryInfo *)calloc(sizeof(FontQueryInfo), 1);
PfQueryFont(NSFullFontName, node);
gFontMetricsCache->Put(&key, node);
gFontMetricsCacheCount++;
}
float dev2app;
int height;
@ -257,7 +254,7 @@ NS_ASSERTION(!(nsnull == aContext), "attempt to init fontmetrics with null devic
mUnderlineOffset = -NSToCoordRound((float)node->descender * dev2app * 0.30f); // 30% of descent
if (mFontHandle)
free (mFontHandle);
free (mFontHandle);
mFontHandle = strdup(NSFullFontName);
//delete [] str;
@ -265,302 +262,328 @@ NS_ASSERTION(!(nsnull == aContext), "attempt to init fontmetrics with null devic
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: Destroy( ) {
mDeviceContext = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: Destroy( )
{
mDeviceContext = nsnull;
return NS_OK;
}
static void apGenericFamilyToFont( const nsString& aGenericFamily, nsIDeviceContext* aDC, nsString& aFontFace ) {
char *str = aGenericFamily.ToNewCString();
//delete [] str;
free (str);
}
static void apGenericFamilyToFont( const nsString& aGenericFamily, nsIDeviceContext* aDC, nsString& aFontFace )
{
char *str = aGenericFamily.ToNewCString();
//delete [] str;
free (str);
}
struct FontEnumData
{
FontEnumData(nsIDeviceContext* aContext, char* aFaceName)
{
mContext = aContext;
mFaceName = aFaceName;
}
nsIDeviceContext* mContext;
char* mFaceName;
FontEnumData(nsIDeviceContext* aContext, char* aFaceName)
{
mContext = aContext;
mFaceName = aFaceName;
}
nsIDeviceContext* mContext;
char* mFaceName;
};
static PRBool FontEnumCallback( const nsString& aFamily, PRBool aGeneric, void *aData ) {
return PR_TRUE;
}
static PRBool FontEnumCallback( const nsString& aFamily, PRBool aGeneric, void *aData )
{
return PR_TRUE;
}
void nsFontMetricsPh::RealizeFont() {
}
void nsFontMetricsPh::RealizeFont()
{
}
NS_IMETHODIMP nsFontMetricsPh :: GetXHeight( nscoord& aResult ) {
aResult = mXHeight;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetXHeight( nscoord& aResult )
{
aResult = mXHeight;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetSuperscriptOffset( nscoord& aResult ) {
aResult = mSuperscriptOffset;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetSuperscriptOffset( nscoord& aResult )
{
aResult = mSuperscriptOffset;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetSubscriptOffset( nscoord& aResult ) {
aResult = mSubscriptOffset;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetSubscriptOffset( nscoord& aResult )
{
aResult = mSubscriptOffset;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetStrikeout( nscoord& aOffset, nscoord& aSize ) {
aOffset = mStrikeoutOffset;
aSize = mStrikeoutSize;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetStrikeout( nscoord& aOffset, nscoord& aSize )
{
aOffset = mStrikeoutOffset;
aSize = mStrikeoutSize;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetUnderline( nscoord& aOffset, nscoord& aSize ) {
aOffset = mUnderlineOffset;
aSize = mUnderlineSize;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetUnderline( nscoord& aOffset, nscoord& aSize )
{
aOffset = mUnderlineOffset;
aSize = mUnderlineSize;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetHeight( nscoord &aHeight ) {
aHeight = mHeight;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetHeight( nscoord &aHeight )
{
aHeight = mHeight;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh ::GetNormalLineHeight( nscoord &aHeight ) {
aHeight = mEmHeight + mLeading;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh ::GetNormalLineHeight( nscoord &aHeight )
{
aHeight = mEmHeight + mLeading;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetLeading( nscoord &aLeading ) {
aLeading = mLeading;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetLeading( nscoord &aLeading )
{
aLeading = mLeading;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh::GetEmHeight( nscoord &aHeight ) {
aHeight = mEmHeight;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh::GetEmHeight( nscoord &aHeight )
{
aHeight = mEmHeight;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh::GetEmAscent( nscoord &aAscent ) {
aAscent = mEmAscent;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh::GetEmAscent( nscoord &aAscent )
{
aAscent = mEmAscent;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh::GetEmDescent( nscoord &aDescent ) {
aDescent = mEmDescent;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh::GetEmDescent( nscoord &aDescent )
{
aDescent = mEmDescent;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh::GetMaxHeight( nscoord &aHeight ) {
aHeight = mMaxHeight;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh::GetMaxHeight( nscoord &aHeight )
{
aHeight = mMaxHeight;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetMaxAscent( nscoord &aAscent ) {
aAscent = mMaxAscent;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetMaxAscent( nscoord &aAscent )
{
aAscent = mMaxAscent;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetMaxDescent( nscoord &aDescent ) {
aDescent = mMaxDescent;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetMaxDescent( nscoord &aDescent )
{
aDescent = mMaxDescent;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetMaxAdvance( nscoord &aAdvance ) {
aAdvance = mMaxAdvance;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetMaxAdvance( nscoord &aAdvance )
{
aAdvance = mMaxAdvance;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetFont(const nsFont *&aFont) {
aFont = mFont;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh :: GetFont(const nsFont *&aFont)
{
aFont = mFont;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh::GetLangGroup(nsIAtom** aLangGroup) {
if( !aLangGroup ) return NS_ERROR_NULL_POINTER;
NS_IMETHODIMP nsFontMetricsPh::GetLangGroup(nsIAtom** aLangGroup)
{
if( !aLangGroup ) return NS_ERROR_NULL_POINTER;
*aLangGroup = mLangGroup;
NS_IF_ADDREF(*aLangGroup);
*aLangGroup = mLangGroup;
NS_IF_ADDREF(*aLangGroup);
return NS_OK;
}
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh::GetFontHandle(nsFontHandle &aHandle) {
aHandle = (nsFontHandle) mFontHandle;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsPh::GetFontHandle(nsFontHandle &aHandle)
{
aHandle = (nsFontHandle) mFontHandle;
return NS_OK;
}
nsresult nsFontMetricsPh::GetSpaceWidth(nscoord &aSpaceWidth) {
aSpaceWidth = mSpaceWidth;
return NS_OK;
}
struct nsFontFamily {
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
PLHashTable* mCharSets;
};
nsresult nsFontMetricsPh::GetSpaceWidth(nscoord &aSpaceWidth)
{
aSpaceWidth = mSpaceWidth;
return NS_OK;
}
struct nsFontFamily
{
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
PLHashTable* mCharSets;
};
// The Font Enumerator
nsFontEnumeratorPh::nsFontEnumeratorPh() {
NS_INIT_REFCNT();
}
nsFontEnumeratorPh::nsFontEnumeratorPh()
{
NS_INIT_REFCNT();
}
NS_IMPL_ISUPPORTS(nsFontEnumeratorPh, NS_GET_IID(nsIFontEnumerator));
static int gInitializedFontEnumerator = 0;
static PLHashNumber HashKey(const void* aString) {
const nsString* key = (const nsString*) aString;
return (PLHashNumber) nsCRT::HashCode(key->get());
}
static PRIntn CompareKeys( const void* aStr1, const void* aStr2 ) {
return nsCRT::strcmp(((const nsString*) aStr1)->get(), ((const nsString*) aStr2)->get()) == 0;
}
static int InitializeFontEnumerator( void )
{
gInitializedFontEnumerator = 1;
if( !gGotAllFontNames ) gGotAllFontNames = 1;
return 1;
}
static int InitializeFontEnumerator( void ) {
gInitializedFontEnumerator = 1;
if( !gGotAllFontNames ) gGotAllFontNames = 1;
return 1;
}
typedef struct EnumerateFamilyInfo
{
PRUnichar** mArray;
int mIndex;
}
EnumerateFamilyInfo;
typedef struct EnumerateFamilyInfo {
PRUnichar** mArray;
int mIndex;
} EnumerateFamilyInfo;
static PRIntn EnumerateFamily( PLHashEntry* he, PRIntn i, void* arg )
{
EnumerateFamilyInfo* info = (EnumerateFamilyInfo*) arg;
PRUnichar** array = info->mArray;
int j = info->mIndex;
PRUnichar* str = ((nsString*) he->key)->ToNewUnicode();
static PRIntn EnumerateFamily( PLHashEntry* he, PRIntn i, void* arg ) {
EnumerateFamilyInfo* info = (EnumerateFamilyInfo*) arg;
PRUnichar** array = info->mArray;
int j = info->mIndex;
PRUnichar* str = ((nsString*) he->key)->ToNewUnicode();
if (!str) {
for (j = j - 1; j >= 0; j--) {
nsMemory::Free(array[j]);
}
info->mIndex = 0;
return HT_ENUMERATE_STOP;
}
array[j] = str;
info->mIndex++;
return HT_ENUMERATE_NEXT;
}
static int CompareFontNames(const void* aArg1, const void* aArg2, void* aClosure) {
const PRUnichar* str1 = *((const PRUnichar**) aArg1);
const PRUnichar* str2 = *((const PRUnichar**) aArg2);
// XXX add nsICollation stuff
return nsCRT::strcmp(str1, str2);
}
NS_IMETHODIMP nsFontEnumeratorPh::EnumerateAllFonts(PRUint32* aCount, PRUnichar*** aResult) {
if( aCount ) *aCount = 0;
else return NS_ERROR_NULL_POINTER;
if( aResult ) *aResult = nsnull;
else return NS_ERROR_NULL_POINTER;
if( !gInitializedFontEnumerator && !InitializeFontEnumerator( ) ) return NS_ERROR_FAILURE;
if( gFamilies ) {
PRUnichar** array = (PRUnichar**) nsMemory::Alloc(gFamilies->nentries * sizeof(PRUnichar*));
if( !array ) return NS_ERROR_OUT_OF_MEMORY;
EnumerateFamilyInfo info = { array, 0 };
PL_HashTableEnumerateEntries(gFamilies, EnumerateFamily, &info);
if( !info.mIndex ) {
nsMemory::Free(array);
return NS_ERROR_OUT_OF_MEMORY;
}
NS_QuickSort(array, gFamilies->nentries, sizeof(PRUnichar*),
CompareFontNames, nsnull);
*aCount = gFamilies->nentries;
*aResult = array;
return NS_OK;
}
else return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsFontEnumeratorPh::EnumerateFonts( const char* aLangGroup, const char* aGeneric, PRUint32* aCount, PRUnichar*** aResult ) {
if( !aLangGroup || !aGeneric ) return NS_ERROR_NULL_POINTER;
if( aCount ) *aCount = 0;
else return NS_ERROR_NULL_POINTER;
if( aResult ) *aResult = nsnull;
else return NS_ERROR_NULL_POINTER;
//if( !strcmp(aLangGroup, "x-unicode") || !strcmp(aLangGroup, "x-user-def") ) return EnumerateAllFonts( aCount, aResult );
if( !gInitializedFontEnumerator && !InitializeFontEnumerator( ) ) return NS_ERROR_FAILURE;
int i;
if(!gFontDetails)
{
gnFonts = PfQueryFonts(-1, PHFONT_ALL_FONTS, NULL, 0);
if(gnFonts>0)
{
gFontDetails = new FontDetails[gnFonts];
if(gFontDetails)
{
gFontNames = (nsCString**) nsMemory::Alloc(gnFonts * sizeof(nsCString*));
PfQueryFonts(-1, PHFONT_ALL_FONTS, gFontDetails, gnFonts);
for(i=0;i<gnFonts;i++)
gFontNames[i] = new nsCString(gFontDetails[i].stem);
}
}
}
if(gFontDetails)
{
PRUnichar** array = (PRUnichar**) nsMemory::Alloc(gnFonts * sizeof(PRUnichar*));
if(!array)
return NS_ERROR_OUT_OF_MEMORY;
int nCount = 0;
for(i=0;i<gnFonts;i++)
{
nsCString str(aGeneric);
if(str == "monospace")
if (!str)
{
if(!gFontDetails[i].losize && !gFontDetails[i].hisize
&& (gFontDetails[i].flags | PHFONT_INFO_FIXED) == gFontDetails[i].flags)
{
array[nCount++] = gFontNames[i]->ToNewUnicode();
}
for (j = j - 1; j >= 0; j--)
{
nsMemory::Free(array[j]);
}
info->mIndex = 0;
return HT_ENUMERATE_STOP;
}
else
array[j] = str;
info->mIndex++;
return HT_ENUMERATE_NEXT;
}
static int CompareFontNames(const void* aArg1, const void* aArg2, void* aClosure)
{
const PRUnichar* str1 = *((const PRUnichar**) aArg1);
const PRUnichar* str2 = *((const PRUnichar**) aArg2);
// XXX add nsICollation stuff
//
return nsCRT::strcmp(str1, str2);
}
NS_IMETHODIMP nsFontEnumeratorPh::EnumerateAllFonts(PRUint32* aCount, PRUnichar*** aResult)
{
if( aCount ) *aCount = 0;
else return NS_ERROR_NULL_POINTER;
if( aResult ) *aResult = nsnull;
else return NS_ERROR_NULL_POINTER;
if( !gInitializedFontEnumerator && !InitializeFontEnumerator( ) ) return NS_ERROR_FAILURE;
if( gFamilies )
{
if((gFontDetails[i].flags | PHFONT_INFO_PROP) == gFontDetails[i].flags)
{
array[nCount++] = gFontNames[i]->ToNewUnicode();
}
}
}
*aCount = nCount;
*aResult = array;
return NS_OK;
}
PRUnichar** array = (PRUnichar**) nsMemory::Alloc(gFamilies->nentries * sizeof(PRUnichar*));
if( !array ) return NS_ERROR_OUT_OF_MEMORY;
EnumerateFamilyInfo info = { array, 0
};
PL_HashTableEnumerateEntries(gFamilies, EnumerateFamily, &info);
if( !info.mIndex )
{
nsMemory::Free(array);
return NS_ERROR_OUT_OF_MEMORY;
}
return EnumerateAllFonts( aCount, aResult );
}
NS_QuickSort(array, gFamilies->nentries, sizeof(PRUnichar*),
CompareFontNames, nsnull);
*aCount = gFamilies->nentries;
*aResult = array;
return NS_OK;
}
else return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsFontEnumeratorPh::EnumerateFonts( const char* aLangGroup, const char* aGeneric, PRUint32* aCount, PRUnichar*** aResult )
{
if( !aLangGroup || !aGeneric ) return NS_ERROR_NULL_POINTER;
if( aCount ) *aCount = 0;
else return NS_ERROR_NULL_POINTER;
if( aResult ) *aResult = nsnull;
else return NS_ERROR_NULL_POINTER;
//if( !strcmp(aLangGroup, "x-unicode") || !strcmp(aLangGroup, "x-user-def") ) return EnumerateAllFonts( aCount, aResult );
if( !gInitializedFontEnumerator && !InitializeFontEnumerator( ) ) return NS_ERROR_FAILURE;
int i;
if(!gFontDetails)
{
gnFonts = PfQueryFonts('a', PHFONT_DONT_SHOW_LEGACY, NULL, 0);
if(gnFonts>0)
{
gFontDetails = new FontDetails[gnFonts];
if(gFontDetails)
{
gFontNames = (nsCString**) nsMemory::Alloc(gnFonts * sizeof(nsCString*));
PfQueryFonts('a', PHFONT_DONT_SHOW_LEGACY, gFontDetails, gnFonts);
for(i=0;i<gnFonts;i++)
gFontNames[i] = new nsCString(gFontDetails[i].desc);
}
}
}
if(gFontDetails)
{
PRUnichar** array = (PRUnichar**) nsMemory::Alloc(gnFonts * sizeof(PRUnichar*));
if(!array)
return NS_ERROR_OUT_OF_MEMORY;
int nCount = 0;
for(i=0;i<gnFonts;i++)
{
if(stricmp(aGeneric, "monospace") == 0)
{
if(gFontDetails[i].flags & PHFONT_INFO_FIXED)
array[nCount++] = gFontNames[i]->ToNewUnicode();
}
else
{
if (gFontDetails[i].flags & PHFONT_INFO_PROP)
array[nCount++] = gFontNames[i]->ToNewUnicode();
}
}
*aCount = nCount;
*aResult = array;
return NS_OK;
}
return EnumerateAllFonts( aCount, aResult );
}
NS_IMETHODIMP
nsFontEnumeratorPh::HaveFontFor(const char* aLangGroup, PRBool* aResult)
nsFontEnumeratorPh::HaveFontFor(const char* aLangGroup, PRBool* aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = PR_FALSE;
NS_ENSURE_ARG_POINTER(aLangGroup);
NS_ENSURE_ARG_POINTER(aResult);
*aResult = PR_FALSE;
NS_ENSURE_ARG_POINTER(aLangGroup);
*aResult = PR_TRUE; // always return true for now.
// Finish me - ftang
return NS_OK;
*aResult = PR_TRUE; // always return true for now.
// Finish me - ftang
return NS_OK;
}
NS_IMETHODIMP
nsFontEnumeratorPh::UpdateFontList()
{
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -33,16 +33,14 @@
#include "nsIDeviceContext.h"
#include "nsCRT.h"
#include "nsCOMPtr.h"
#include "nsRenderingContextPh.h"
#include "nsDeviceContextPh.h"
class nsFontMetricsPh : public nsIFontMetrics
{
public:
nsFontMetricsPh();
~nsFontMetricsPh();
virtual ~nsFontMetricsPh();
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
NS_DECL_ISUPPORTS
@ -75,7 +73,7 @@ public:
protected:
void RealizeFont();
nsDeviceContextPh *mDeviceContext;
nsIDeviceContext *mDeviceContext;
nsFont *mFont;
char *mFontHandle; /* Photon Fonts are just a string */
nscoord mHeight;

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

@ -37,6 +37,7 @@
#include "nsIImageManager.h"
#include "nsDeviceContextPh.h"
#include "nsPrintOptionsPh.h"
#include "nsFontList.h"
// objects that just require generic constructors
@ -49,6 +50,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsRegionPh)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecPh)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecFactoryPh)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontEnumeratorPh)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontList)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerPh)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrintOptionsPh)
@ -170,6 +172,11 @@ static nsModuleComponentInfo components[] =
NS_FONT_ENUMERATOR_CID,
"@mozilla.org/gfx/fontenumerator;1",
nsFontEnumeratorPhConstructor },
{ "Font List",
NS_FONTLIST_CID,
// "@mozilla.org/gfx/fontlist;1"
NS_FONTLIST_CONTRACTID,
nsFontListConstructor },
{ "Ph Screen Manager",
NS_SCREENMANAGER_CID,
"@mozilla.org/gfx/screenmanager;1",

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

@ -59,6 +59,7 @@ nsImagePh :: nsImagePh()
mIsOptimized = PR_FALSE;
memset(&mPhImage, 0, sizeof(PhImage_t));
mPhImageCache=NULL;
mPhImageZoom = NULL;
}
// ----------------------------------------------------------------
@ -88,6 +89,12 @@ nsImagePh :: ~nsImagePh()
mAlphaBits = nsnull;
}
if( mPhImageZoom ) {
PgShmemDestroy( mPhImageZoom->image );
free( mPhImageZoom );
mPhImageZoom = NULL;
}
memset(&mPhImage, 0, sizeof(PhImage_t));
}
@ -310,6 +317,43 @@ void nsImagePh :: ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRec
mFlags = aFlags; // this should be 0'd out by Draw()
}
/* set the mask_bm and mask_bpl to 0, replacing the transparency mask_bm based with the Ph_USE_TRANSPARENCY mechanism */
static void convert_mask_bm_to_transparency( PhImage_t *image ) {
if( !image->mask_bpl || !image->mask_bm ) return;
int one = 0, x, y, b;
uchar_t bit;
char *ptr;
PgColor_t transparent = PgRGB( 255, 255, 0 ); /* Shawn's idea */
for( ptr = image->mask_bm,y = 0; y<image->size.h; y++ ) {
for( b=0; b<image->mask_bpl; b++ ) {
x = b * 8;
for( bit=0x1; bit; bit<<=1 ) {
if( !( (*ptr) & bit ) ) {
if( x<image->size.w ) PiSetPixel( image, x, y, transparent );
one++;
}
x++;
}
ptr++;
}
}
if( one ) {
image->flags |= Ph_USE_TRANSPARENCY;
image->transparent = transparent;
// free( image->mask_bm );
image->mask_bm = NULL;
image->mask_bpl = 0;
}
}
/** ----------------------------------------------------------------
* Draw the bitmap, this method has a source and destination coordinates
* @update dc - 11/20/98
@ -331,9 +375,12 @@ NS_IMETHODIMP nsImagePh :: Draw(nsIRenderingContext &aContext, nsDrawingSurface
{
PhRect_t clip = { {aDX, aDY}, {aDX + aDWidth, aDY + aDHeight} };
PhPoint_t pos = { aDX - aSX, aDY - aSY};
PRBool aOffScreen;
PRBool aOffScreen;
nsDrawingSurfacePh* drawing = (nsDrawingSurfacePh*) aSurface;
if( !aSWidth || !aSHeight || !aDWidth || !aDHeight ) return NS_OK;
nsDrawingSurfacePh* drawing = (nsDrawingSurfacePh*) aSurface;
#ifdef ALLOW_PHIMAGE_CACHEING
drawing->IsOffscreen(&aOffScreen);
@ -354,9 +401,19 @@ NS_IMETHODIMP nsImagePh :: Draw(nsIRenderingContext &aContext, nsDrawingSurface
else
#endif
{
PhImage_t *pimage = &mPhImage;
if( aSWidth != aDWidth || aSHeight != aDHeight ) {
if( !mPhImageZoom ) {
convert_mask_bm_to_transparency( &mPhImage );
mPhImageZoom = PiResizeImage( &mPhImage, NULL, aDWidth, aDHeight, Pi_USE_COLORS|Pi_SHMEM );
}
pimage = mPhImageZoom;
}
PgSetMultiClip( 1, &clip );
if ((mAlphaDepth == 1) || (mAlphaDepth == 0))
PgDrawPhImagemx(&pos, &mPhImage, 0);
PgDrawPhImagemx( &pos, pimage, 0 );
else
printf("DRAW IMAGE: with 8 bit alpha!!\n");
PgSetMultiClip( 0, NULL );

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

@ -123,6 +123,7 @@ private:
PRInt8 mImageCache; // place to save off the old image for fast animation
PRInt16 mAlphaLevel; // an alpha level every pixel uses
PhImage_t mPhImage;
PhImage_t *mPhImageZoom; // the zoomed version of mPhImage
PdOffscreenContext_t *mPhImageCache; // Cache for the image offscreen
PRUint8 mFlags; // flags set by ImageUpdated

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

@ -1,5 +1,3 @@
extern "C" int verbose=4; // kedl, need this while using Bobby's test render lib...
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
@ -199,26 +197,28 @@ NS_IMETHODIMP nsRenderingContextPh :: Init( nsIDeviceContext* aContext, nsIWidge
PhRid_t rid = PtWidgetRid( mWidget );
if( rid ) {
mGC = PgCreateGC( 16 * 1024 );
if( !mGC ) abort();
mGC = PgCreateGC(0);
if( !mGC )
abort();
PgSetDrawBufferSize(0x7fff);
/* Make sure the new GC is reset to the default settings */
PgDefaultGC( mGC );
mSurface = new nsDrawingSurfacePh();
if( mSurface ) {
res = mSurface->Init( mGC );
if( res != NS_OK ) return NS_ERROR_FAILURE;
mOffscreenSurface = mSurface;
NS_ADDREF( mSurface );
/* Make sure the new GC is reset to the default settings */
PgDefaultGC( mGC );
mSurface = new nsDrawingSurfacePh();
if( mSurface ) {
res = mSurface->Init( mGC );
if( res != NS_OK ) return NS_ERROR_FAILURE;
mOffscreenSurface = mSurface;
NS_ADDREF( mSurface );
/* hack up code to setup new GC for on screen drawing */
PgSetGC( mGC );
PgSetRegion( rid );
}
else abort();
}
}
else abort();
}
mInitialized = PR_TRUE;
return CommonInit();
@ -284,12 +284,16 @@ NS_IMETHODIMP nsRenderingContextPh::UnlockDrawingSurface( void ) {
}
extern "C" {
int PdSetOffscreenTranslation(PdOffscreenContext_t *osc, PhPoint_t *trans);
}
NS_IMETHODIMP nsRenderingContextPh :: SelectOffScreenDrawingSurface( nsDrawingSurface aSurface ) {
if( nsnull==aSurface ) mSurface = mOffscreenSurface;
else mSurface = (nsDrawingSurfacePh *) aSurface;
mSurface->Select();
mSurface->Select( );
mBufferIsEmpty = PR_TRUE;
return NS_OK;
@ -408,7 +412,6 @@ NS_IMETHODIMP nsRenderingContextPh :: IsVisibleRect( const nsRect& aRect, PRBool
NS_IMETHODIMP nsRenderingContextPh :: SetClipRect( const nsRect& aRect, nsClipCombine aCombine, PRBool &aClipEmpty ) {
nsresult res = NS_ERROR_FAILURE;
nsRect trect = aRect;
PhRect_t *rgn;
if( mTranMatrix && mClipRegion ) {
mTranMatrix->TransformCoord( &trect.x, &trect.y,&trect.width, &trect.height );
@ -699,6 +702,8 @@ NS_IMETHODIMP nsRenderingContextPh :: FillRect( nscoord aX, nscoord aY, nscoord
SELECT( mSurface );
if( PgGetGC() != mGC ) PgSetGC( mGC );
if( w && h ) {
int y2 = y + h - 1;
if( y < SHRT_MIN ) y = SHRT_MIN; /* on very large documents, the PgDrawIRect will take only the short part from the int, which could lead to randomly, hazardous results see PR: 5864 */
@ -741,7 +746,6 @@ NS_IMETHODIMP nsRenderingContextPh :: InvertRect( nscoord aX, nscoord aY, nscoor
NS_IMETHODIMP nsRenderingContextPh :: DrawPolygon( const nsPoint aPoints[], PRInt32 aNumPoints ) {
PhPoint_t *pts;
int err = 0;
if( !aNumPoints ) return NS_OK;
@ -870,7 +874,7 @@ NS_IMETHODIMP nsRenderingContextPh :: DrawArc(nscoord aX, nscoord aY, nscoord aW
radii.y = y+h-1;
SELECT(mSurface);
PgSetStrokeColor( NS_TO_PH_RGB( mCurrentColor ));
PgDrawArc( &center, &radii, aStartAngle, aEndAngle, Pg_EXTENT_BASED | Pg_DRAW_STROKE );
PgDrawArc( &center, &radii, (unsigned int)aStartAngle, (unsigned int)aEndAngle, Pg_EXTENT_BASED | Pg_DRAW_STROKE );
return NS_OK;
}
@ -896,13 +900,12 @@ NS_IMETHODIMP nsRenderingContextPh :: FillArc( nscoord aX, nscoord aY, nscoord a
radii.y = y+h-1;
SELECT(mSurface);
PgSetFillColor( NS_TO_PH_RGB( mCurrentColor ));
PgDrawArc( &center, &radii, aStartAngle, aEndAngle, Pg_EXTENT_BASED | Pg_DRAW_FILL );
PgDrawArc( &center, &radii, (unsigned int)aStartAngle, (unsigned int)aEndAngle, Pg_EXTENT_BASED | Pg_DRAW_FILL );
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: GetWidth( char ch, nscoord& aWidth ) {
nsresult ret_code;
// Check for the very common case of trying to get the width of a single
// space.
@ -917,7 +920,6 @@ NS_IMETHODIMP nsRenderingContextPh :: GetWidth( char ch, nscoord& aWidth ) {
NS_IMETHODIMP nsRenderingContextPh :: GetWidth( PRUnichar ch, nscoord &aWidth, PRInt32 *aFontID ) {
PRUnichar buf[2];
nsresult ret_code;
/* turn it into a string */
buf[0] = ch;
@ -931,7 +933,6 @@ NS_IMETHODIMP nsRenderingContextPh :: GetWidth( const char* aString, nscoord& aW
NS_IMETHODIMP nsRenderingContextPh :: GetWidth(const char* aString, PRUint32 aLength, nscoord& aWidth ) {
nsresult ret_code = NS_ERROR_FAILURE;
FontQueryInfo tsInfo;
aWidth = 0; // Initialize to zero in case we fail.
@ -943,10 +944,10 @@ NS_IMETHODIMP nsRenderingContextPh :: GetWidth(const char* aString, PRUint32 aLe
nsCString strTail("M");
char* tail=(char*)strTail.ToNewUnicode();
int tailLength=strlen(tail);
PRUint32 tailLength=strlen(tail);
char* text = (char*) nsMemory::Alloc(aLength + tailLength + 2);
int i;
PRUint32 i;
for(i=0;i<aLength;i++)
text[i]=aString[i];
for(i=0;i<tailLength;i++)
@ -961,7 +962,6 @@ NS_IMETHODIMP nsRenderingContextPh :: GetWidth(const char* aString, PRUint32 aLe
ret_code = NS_OK;
}
nsMemory::Free(text);
}
else ret_code = NS_ERROR_FAILURE;
@ -979,8 +979,6 @@ NS_IMETHODIMP nsRenderingContextPh :: GetWidth( const PRUnichar *aString, PRUint
aWidth = 0; // Initialize to zero in case we fail.
if( nsnull != mFontMetrics ) {
PhRect_t extent;
NS_ConvertUCS2toUTF8 theUnicodeString (aString, aLength);
ret_code = GetWidth( theUnicodeString.get(), strlen(theUnicodeString.get()), aWidth );
}
@ -1020,7 +1018,6 @@ NS_IMETHODIMP nsRenderingContextPh :: DrawString( const char *aString, PRUint32
}
NS_IMETHODIMP nsRenderingContextPh :: DrawString( const PRUnichar *aString, PRUint32 aLength, nscoord aX, nscoord aY, PRInt32 aFontID, const nscoord* aSpacing ) {
char *str;
NS_ConvertUCS2toUTF8 theUnicodeString( aString, aLength );
const char *p = theUnicodeString.get( );
return DrawString( p, strlen( p ), aX, aY, aSpacing );
@ -1049,66 +1046,32 @@ NS_IMETHODIMP nsRenderingContextPh::DrawImage( nsIImage *aImage, const nsRect& a
NS_IMETHODIMP nsRenderingContextPh::DrawImage( nsIImage *aImage, nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight ) {
nscoord x, y, w, h;
nsresult res = NS_OK;
int ww,hh;
x = aX;
y = aY;
w = aWidth;
h = aHeight;
mTranMatrix->TransformCoord(&x, &y, &w, &h);
#if 0
SELECT(mSurface);
ww = mSurface->mWidth;
hh = mSurface->mHeight;
nsDeviceContextPh *phContext = (nsDeviceContextPh *)mContext;
if( !phContext || !phContext->IsPrinting() ) {
if( x >= ww || y >=hh ) return NS_OK;
}
if( x + w > ww ) w = ww - x;
if( y + h > hh ) h = hh - y;
#endif
return (aImage->Draw(*this, mSurface, x, y, w, h));
}
NS_IMETHODIMP nsRenderingContextPh::DrawImage( nsIImage *aImage, const nsRect& aSRect, const nsRect& aDRect ) {
#if 0
nsRect sr,dr;
nsresult res = NS_OK;
if( mClipRegion->IsEmpty() ) return NS_ERROR_FAILURE;
nsRect sr,dr;
sr = aSRect;
mTranMatrix->TransformCoord(&sr.x, &sr.y, &sr.width, &sr.height);
sr.x -= mTranMatrix->GetXTranslationCoord();
sr.y -= mTranMatrix->GetYTranslationCoord();
dr = aDRect;
mTranMatrix->TransformCoord(&dr.x, &dr.y, &dr.width, &dr.height);
SELECT(mSurface);
return aImage->Draw( *this, mSurface, sr.x, sr.y, sr.width, sr.height, dr.x, dr.y, dr.width, dr.height );
#else
nsRect sr,dr;
sr = aSRect;
mTranMatrix->TransformCoord(&sr.x, &sr.y, &sr.width, &sr.height);
sr.x -= mTranMatrix->GetXTranslationCoord();
sr.y -= mTranMatrix->GetYTranslationCoord();
dr = aDRect;
mTranMatrix->TransformCoord(&dr.x, &dr.y, &dr.width, &dr.height);
return aImage->Draw(*this, mSurface,
sr.x, sr.y,
sr.width, sr.height,
dr.x, dr.y,
dr.width, dr.height);
#endif
return aImage->Draw(*this, mSurface,
sr.x, sr.y,
sr.width, sr.height,
dr.x, dr.y,
dr.width, dr.height);
}
/** ---------------------------------------------------
@ -1137,7 +1100,6 @@ NS_IMETHODIMP nsRenderingContextPh::DrawTile( nsIImage *aImage, nscoord aSrcXOff
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: CopyOffScreenBits( nsDrawingSurface aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY, const nsRect &aDestBounds, PRUint32 aCopyFlags ) {
PhArea_t darea, sarea;
@ -1145,7 +1107,6 @@ NS_IMETHODIMP nsRenderingContextPh :: CopyOffScreenBits( nsDrawingSurface aSrcSu
PRInt32 srcY = aSrcY;
nsRect drect = aDestBounds;
nsDrawingSurfacePh *destsurf;
unsigned char *ptr;
if( !aSrcSurf || !mTranMatrix || !mSurface ) return NS_ERROR_FAILURE;
@ -1158,69 +1119,19 @@ NS_IMETHODIMP nsRenderingContextPh :: CopyOffScreenBits( nsDrawingSurface aSrcSu
if( aCopyFlags & NS_COPYBITS_XFORM_SOURCE_VALUES ) mTranMatrix->TransformCoord( &srcX, &srcY );
if( aCopyFlags & NS_COPYBITS_XFORM_DEST_VALUES ) mTranMatrix->TransformCoord( &drect.x, &drect.y, &drect.width, &drect.height );
darea.pos.x=drect.x;
darea.pos.y=drect.y;
darea.size.w=drect.width;
darea.size.h=drect.height;
destsurf->Select( );
(PgGetGC())->target_rid = 0; // kedl, fix the animations showing thru all regions
nsRect rect;
PRBool valid;
/* Is this really needed?? */
GetClipRect( rect,valid );
/* Flush the Source buffer, Really need this */
((nsDrawingSurfacePh *)aSrcSurf)->Flush();
if( aSrcSurf != destsurf ) destsurf->Select();
else abort();
{//xyz
PhRect_t rsrc,rdst;
PdOffscreenContext_t *d;
int off;
int oldrid;
PhGC_t *oldgc;
int ww,hh;
int rid;
oldgc = PgGetGC();
oldrid=(PgGetGC())->rid;
destsurf->IsOffscreen(&off);
if (off)
d = (PdOffscreenContext_t *) destsurf->GetDC();
else
{
d=NULL;
PhDCSetCurrent(NULL);
(PgGetGC())->target_rid = 0; // kedl, fix the animations showing thru all regions
}
ww = destsurf->mWidth;
hh = destsurf->mHeight;
if (d && (darea.pos.x >= ww || darea.pos.y >=hh))
return NS_OK;
PhArea_t sarea;
sarea.pos.x = srcX;
sarea.pos.y = srcY;
sarea.size.w = darea.size.w;
sarea.size.h = darea.size.h;
sarea.size.w = drect.width;
sarea.size.h = drect.height;
darea.pos.x = drect.x;
darea.pos.y = drect.y;
darea.size.w = sarea.size.w;
darea.size.h = sarea.size.h;
PgContextBlitArea( (PdOffscreenContext_t *) ((nsDrawingSurfacePh *)aSrcSurf)->GetDC(), &sarea, NULL, &darea );
PhDCSetCurrent(d);
rid = PtWidgetRid(mWidget);
PgSetRegion(rid);
PgContextBlitArea((PdOffscreenContext_t *) ((nsDrawingSurfacePh *)aSrcSurf)->GetDC(), &sarea, d, &darea);
PgSetRegion(oldrid);
PgSetGC(oldgc);
ApplyClipping(oldgc);
}
destsurf->Flush();
mBufferIsEmpty = PR_TRUE;
return NS_OK;
}
@ -1237,7 +1148,6 @@ void nsRenderingContextPh::ApplyClipping( PhGC_t *gc ) {
PgSetGC(mGC); /* new */
if( mClipRegion ) {
int err;
PhTile_t *tiles = nsnull;
PhRect_t *rects = nsnull;
int rect_count;

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

@ -26,7 +26,6 @@
#include "nsPhGfxLog.h"
nsScreenPh :: nsScreenPh ( ) {
nsresult res = NS_ERROR_FAILURE;
PhSysInfo_t SysInfo;
PhRect_t rect;
char *p = NULL;