--- a/content/canvas/src/Makefile.in
+++ b/content/canvas/src/Makefile.in
@@ -102,14 +102,9 @@ CXXFLAGS += $(MOZ_CAIRO_CFLAGS) $(TK_CFL
ifndef MOZ_ENABLE_CAIRO_GFX
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
# needed for nsDrawingSurfaceMac.h
CXXFLAGS += -I$(topsrcdir)/gfx/src/mac
endif
endif
-ifeq ($(MOZ_WIDGET_TOOLKIT), os2)
-# needed for nsDrawingSurfaceOS2.h
-CXXFLAGS += -I$(topsrcdir)/gfx/src/os2
-endif
-
DEFINES += -D_IMPL_NS_LAYOUT
--- a/gfx/src/Makefile.in
+++ b/gfx/src/Makefile.in
@@ -76,17 +76,17 @@ ifdef MOZ_ENABLE_CAIRO_GFX
DIRS += thebes
else
ifdef MOZ_ENABLE_PHOTON
DIRS += photon
endif
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
DIRS += mac
endif
- ifneq (,$(filter windows beos os2 mac,$(MOZ_WIDGET_TOOLKIT)))
+ ifneq (,$(filter windows beos mac,$(MOZ_WIDGET_TOOLKIT)))
DIRS += $(MOZ_WIDGET_TOOLKIT)
endif
endif
CPPSRCS = \
nsColor.cpp \
nsColorNames.cpp \
nsDeviceContext.cpp \
@@ -107,29 +107,16 @@ CPPSRCS += imgScaler.cpp
endif
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
CPPSRCS += \
mac/nsRegionPool.cpp \
$(NULL)
endif
-ifeq ($(OS_ARCH),OS2)
-CPPSRCS += \
- os2/nsOS2Uni.cpp \
- os2/nsPaletteOS2.cpp \
- os2/nsPrintOS2.cpp \
- $(NULL)
-EXPORTS += \
- os2/nsOS2Uni.h \
- os2/nsPaletteOS2.h \
- os2/nsPrintOS2.h \
- $(NULL)
-endif
-
EXTRA_DSO_LDOPTS = \
$(DEPTH)/modules/libutil/src/$(LIB_PREFIX)mozutil_s.$(LIB_SUFFIX) \
$(MOZ_UNICHARUTIL_LIBS) \
$(MOZ_COMPONENT_LIBS) \
$(NULL)
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
EXTRA_DSO_LDOPTS += \
deleted file mode 100644
--- a/gfx/src/os2/Makefile.in
+++ /dev/null
@@ -1,111 +0,0 @@
-#
-# ***** BEGIN LICENSE BLOCK *****
-# Version: MPL 1.1/GPL 2.0/LGPL 2.1
-#
-# The contents of this file are subject to the Mozilla Public License Version
-# 1.1 (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-# http://www.mozilla.org/MPL/
-#
-# Software distributed under the License is distributed on an "AS IS" basis,
-# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-# for the specific language governing rights and limitations under the
-# License.
-#
-# The Original Code is the Mozilla OS/2 libraries.
-#
-# The Initial Developer of the Original Code is
-# John Fairhurst, <john_fairhurst@iname.com>.
-# Portions created by the Initial Developer are Copyright (C) 1999
-# the Initial Developer. All Rights Reserved.
-#
-# Contributor(s):
-#
-# Alternatively, the contents of this file may be used under the terms of
-# either of the GNU General Public License Version 2 or later (the "GPL"),
-# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
-# in which case the provisions of the GPL or the LGPL are applicable instead
-# of those above. If you wish to allow use of your version of this file only
-# under the terms of either the GPL or the LGPL, and not to allow others to
-# use your version of this file under the terms of the MPL, indicate your
-# decision by deleting the provisions above and replace them with the notice
-# and other provisions required by the GPL or the LGPL. If you do not delete
-# the provisions above, a recipient may use your version of this file under
-# the terms of any one of the MPL, the GPL or the LGPL.
-#
-# ***** END LICENSE BLOCK *****
-
-DEPTH = ../../..
-topsrcdir = @top_srcdir@
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-include $(DEPTH)/config/autoconf.mk
-
-MODULE = gfx
-LIBRARY_NAME = gfx_os2
-EXPORT_LIBRARY = 1
-IS_COMPONENT = 1
-MODULE_NAME = nsGfxOS2Module
-GRE_MODULE = 1
-LIBXUL_LIBRARY = 1
-
-PACKAGE_FILE = gfxos2.pkg
-
-REQUIRES = xpcom \
- string \
- widget \
- view \
- util \
- pref \
- uconv \
- locale \
- unicharutil \
- imglib2 \
- $(NULL)
-
-# code that we share with Win32
-SHARED_LCPPSRCS = nsUnicodeRange.cpp
-
-CPPSRCS = \
- nsDeviceContextOS2.cpp \
- nsDrawingSurfaceOS2.cpp \
- nsRenderingContextOS2.cpp \
- nsFontMetricsOS2.cpp \
- nsImageOS2.cpp \
- nsRegionOS2.cpp \
- nsGfxFactoryOS2.cpp \
- nsGfxDefs.cpp \
- $(SHARED_LCPPSRCS) \
- $(NULL)
-
-EXPORTS = \
- nsIRenderingContextOS2.h \
- nsDrawingSurfaceOS2.h \
- $(NULL)
-
-EXTRA_DSO_LIBS = gkgfx mozutil_s gfxshared_s
-
-EXTRA_DSO_LDOPTS = \
- $(EXTRA_DSO_LIBS) \
- $(MOZ_UNICHARUTIL_LIBS) \
- $(MOZ_JS_LIBS) \
- $(MOZ_COMPONENT_LIBS) \
- $(NULL)
-
-GARBAGE += $(SHARED_LCPPSRCS) $(wildcard *.$(OBJ_SUFFIX))
-
-include $(topsrcdir)/config/rules.mk
-
-LOCAL_INCLUDES = \
- -I$(srcdir)/.. \
- -I$(srcdir)/../shared \
- -I$(srcdir)/../windows \
- -I$(srcdir)/../../../widget/src/os2 \
- $(NULL)
-
-DEFINES += -DUSE_OS2_TOOLKIT_HEADERS
-
-export:: $(addprefix $(srcdir)/../windows/,$(SHARED_LCPPSRCS))
- $(INSTALL) $^ .
-
deleted file mode 100644
--- a/gfx/src/os2/gfxos2.pkg
+++ /dev/null
@@ -1,6 +0,0 @@
-[gecko]
-#if SHARED_LIBRARY
-dist/bin/components/@SHARED_LIBRARY@
-#else
-!staticcomp @LIBRARY@ @MODULE_NAME@
-#endif
deleted file mode 100644
--- a/gfx/src/os2/nsDeviceContextOS2.cpp
+++ /dev/null
@@ -1,870 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Mozilla OS/2 libraries.
- *
- * The Initial Developer of the Original Code is
- * John Fairhurst, <john_fairhurst@iname.com>.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Henry Sobotka <sobotka@axess.com> 2OOO/O2 update
- * IBM Corp.
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsDeviceContextOS2.h"
-#include "nsRenderingContextOS2.h"
-#include "nsDeviceContextSpecOS2.h"
-#include "nsPrintOS2.h"
-#include "nsIServiceManager.h"
-#include "nsCOMPtr.h"
-#include "nsIScreenManager.h"
-#include "nsIScreen.h"
-
-#include "nsHashTable.h" // For CreateFontAliasTable()
-
-#include "nsGfxDefs.h"
-#include "nsIPref.h"
-
-#include "nsOS2Uni.h"
-#include "nsPaletteOS2.h"
-
-#define NOT_SETUP 0x33
-static PRBool gIsWarp4 = NOT_SETUP;
-
-PRUint32 nsDeviceContextOS2::sNumberOfScreens = 0;
-nscoord nsDeviceContextOS2::mDpi = 120;
-
-
-nsDeviceContextOS2 :: nsDeviceContextOS2()
- : DeviceContextImpl()
-{
- mSurface = NULL;
- mIsPaletteDevice = PR_FALSE;
- mPrintDC = NULL;
- mWidth = -1;
- mHeight = -1;
- mSpec = nsnull;
- mCachedClientRect = PR_FALSE;
- mCachedFullRect = PR_FALSE;
- mSupportsRasterFonts = PR_FALSE;
- mPrintingStarted = PR_FALSE;
-#ifdef XP_OS2
- mPrintState = nsPrintState_ePreBeginDoc;
-#endif
-
- // The first time in we initialize gIsWarp4 flag
- if (NOT_SETUP == gIsWarp4) {
- unsigned long ulValues[2];
- DosQuerySysInfo( QSV_VERSION_MAJOR, QSV_VERSION_MINOR,
- ulValues, sizeof(ulValues));
- gIsWarp4 = (ulValues[0] >= 20) && (ulValues[1] >= 40);
- }
-}
-
-nsDeviceContextOS2::~nsDeviceContextOS2()
-{
- if(mPrintDC)
- {
- GFX (::GpiDestroyPS (mPrintPS), FALSE);
- ::DevCloseDC(mPrintDC);
- } else {
- nsresult rv;
- nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
- if (NS_SUCCEEDED(rv)) {
- prefs->UnregisterCallback("layout.css.dpi",
- prefChanged, (void *)this);
- }
- }
- NS_IF_RELEASE(mSpec);
-}
-
-nsresult nsDeviceContextOS2::Init( nsNativeWidget aWidget)
-{
- mWidget = aWidget;
-
- CommonInit(::WinOpenWindowDC((HWND)aWidget));
-
- static int initialized = 0;
- PRInt32 prefVal = -1;
- if (!initialized) {
- initialized = 1;
-
- // Set prefVal the value of the preference
- // "layout.css.dpi"
- // or -1 if we can't get it.
- // If it's negative, we pretend it's not set.
- // If it's 0, it means force use of the operating system's logical
- // resolution.
- // If it's positive, we use it as the logical resolution
- nsresult res;
-
- nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &res));
- if (NS_SUCCEEDED(res) && prefs) {
- res = prefs->GetIntPref("layout.css.dpi", &prefVal);
- if (NS_FAILED(res)) {
- prefVal = -1;
- }
- prefs->RegisterCallback("layout.css.dpi", prefChanged,
- (void *)this);
- }
-
- SetDPI(prefVal);
- } else {
- SetDPI(mDpi); // to setup p2t and t2p
- }
-
- return NS_OK;
-}
-
-// This version of Init() is called when creating a print DC
-nsresult nsDeviceContextOS2::Init( nsNativeDeviceContext aContext,
- nsIDeviceContext *aOrigContext)
-{
- float origscale, newscale;
- float t2d, a2d;
-
- mPrintDC = (HDC)aContext;
-
- NS_ASSERTION( mPrintDC, "!ERROR! - Received empty DC for printer");
-
-#ifdef XP_OS2
- // Create a print PS now. This is necessary 'cos we need it from
- // odd places to do font-y things, where the only common reference
- // point is this DC. We can't just create a new PS because only one
- // PS can be associated with a given DC, and we can't get that PS from
- // the DC (really?). And it would be slow :-)
- SIZEL sizel = { 0 , 0 };
- mPrintPS = GFX (::GpiCreatePS ( 0/*hab*/, mPrintDC, &sizel,
- PU_PELS | GPIT_MICRO | GPIA_ASSOC), GPI_ERROR);
-#endif
-
- CommonInit( mPrintDC);
-
- long dpi;
- GFX (::DevQueryCaps(mPrintDC, CAPS_VERTICAL_FONT_RES, 1, &dpi), FALSE);
-
- mPixelsToTwips = ((float)NSIntPointsToTwips(72)) / ((float)dpi);
- mTwipsToPixels = 1.0 / mPixelsToTwips;
-
- newscale = TwipsToDevUnits();
-// On OS/2, origscale can be different based on the video resolution.
-// On 640x480, it's 1/15, on everything else it is 1/12.
-// For consistent printing, 1/15 is the correct value to use.
-// It is the closest to 4.x and to Windows.
-// origscale = aOrigContext->TwipsToDevUnits();
- origscale = 1.0/15.0;
-
- mCPixelScale = newscale / origscale;
-
- t2d = aOrigContext->TwipsToDevUnits();
- a2d = aOrigContext->AppUnitsToDevUnits();
-
- mAppUnitsToDevUnits = (a2d / t2d) * mTwipsToPixels;
- mDevUnitsToAppUnits = 1.0f / mAppUnitsToDevUnits;
-
-#ifdef XP_OS2
- HCINFO hcinfo;
- PrnQueryHardcopyCaps( mPrintDC, &hcinfo);
- mWidth = hcinfo.xPels;
- mHeight = hcinfo.yPels;
- // XXX hsb says there are margin problems, must be from here...
-#ifdef DEBUG
- printf( "Got surface of size %d x %d pixels (%d Kb)\n", mWidth, mHeight, mWidth * mHeight * mDepth / 8 / 1024);
- printf( "mCPixelScale = %f\n", mCPixelScale);
-#endif
-
-#endif
-
- return NS_OK;
-}
-
-void nsDeviceContextOS2 :: CommonInit(HDC aDC)
-{
- LONG alArray[CAPS_DEVICE_POLYSET_POINTS];
-
- GFX (::DevQueryCaps(aDC, CAPS_FAMILY, CAPS_DEVICE_POLYSET_POINTS, alArray), FALSE);
-
- mDepth = alArray[CAPS_COLOR_BITCOUNT];
- mIsPaletteDevice = ((alArray[CAPS_ADDITIONAL_GRAPHICS] & CAPS_PALETTE_MANAGER) == CAPS_PALETTE_MANAGER);
-
- mWidth = alArray[CAPS_WIDTH];
- mHeight = alArray[CAPS_HEIGHT];
-
- if (alArray[CAPS_TECHNOLOGY] == CAPS_TECH_RASTER_DISPLAY)
- {
- // init the screen manager and compute our client rect based on the
- // screen objects. We'll save the result
- nsresult ignore;
- mScreenManager = do_GetService("@mozilla.org/gfx/screenmanager;1", &ignore);
- if ( !sNumberOfScreens )
- mScreenManager->GetNumberOfScreens(&sNumberOfScreens);
- mSupportsRasterFonts = !!(alArray[CAPS_RASTER_CAPS] & CAPS_RASTER_FONTS);
- } // if this dc is not a print device
-
- DeviceContextImpl::CommonInit();
-}
-
-void
-nsDeviceContextOS2 :: ComputeClientRectUsingScreen ( nsRect* outRect )
-{
- if ( !mCachedClientRect ) {
- nsCOMPtr<nsIScreen> screen;
- FindScreen ( getter_AddRefs(screen) );
- if ( screen ) {
- PRInt32 x, y, width, height;
- screen->GetAvailRect ( &x, &y, &width, &height );
-
- // convert to device units
- outRect->y = NSToIntRound(y * mDevUnitsToAppUnits);
- outRect->x = NSToIntRound(x * mDevUnitsToAppUnits);
- outRect->width = NSToIntRound(width * mDevUnitsToAppUnits);
- outRect->height = NSToIntRound(height * mDevUnitsToAppUnits);
-
- mCachedClientRect = PR_TRUE;
- mClientRect = *outRect;
- }
- }
- else
- *outRect = mClientRect;
-
-} // ComputeClientRectUsingScreen
-
-
-void
-nsDeviceContextOS2 :: ComputeFullAreaUsingScreen ( nsRect* outRect )
-{
- if ( !mCachedFullRect ) {
- nsCOMPtr<nsIScreen> screen;
- FindScreen ( getter_AddRefs(screen) );
- if ( screen ) {
- PRInt32 x, y, width, height;
- screen->GetRect ( &x, &y, &width, &height );
-
- // convert to device units
- outRect->y = NSToIntRound(y * mDevUnitsToAppUnits);
- outRect->x = NSToIntRound(x * mDevUnitsToAppUnits);
- outRect->width = NSToIntRound(width * mDevUnitsToAppUnits);
- outRect->height = NSToIntRound(height * mDevUnitsToAppUnits);
-
- mWidth = width;
- mHeight = height;
- mCachedFullRect = PR_TRUE;
- }
- }
- else {
- outRect->y = 0;
- outRect->x = 0;
- outRect->width = NSToIntRound(mWidth * mDevUnitsToAppUnits);
- outRect->height = NSToIntRound(mHeight * mDevUnitsToAppUnits);
- }
-
-} // ComputeFullRectUsingScreen
-
-
-//
-// FindScreen
-//
-// Determines which screen intersects the largest area of the given surface.
-//
-void
-nsDeviceContextOS2 :: FindScreen ( nsIScreen** outScreen )
-{
- // optimize for the case where we only have one monitor.
- static nsCOMPtr<nsIScreen> sPrimaryScreen;
- if ( !sPrimaryScreen && mScreenManager )
- mScreenManager->GetPrimaryScreen ( getter_AddRefs(sPrimaryScreen) );
- NS_IF_ADDREF(*outScreen = sPrimaryScreen.get());
- return;
-} // FindScreen
-
-/* OS2TODO - NOT PORTED */
-// Create a rendering context against our hdc for a printer
-nsresult nsDeviceContextOS2::CreateRenderingContext( nsIRenderingContext *&aContext)
-{
-#ifdef NS_PRINT_PREVIEW
- // Defer to Alt when there is one
- if (mAltDC && ((mUseAltDC & kUseAltDCFor_CREATERC_PAINT) || (mUseAltDC & kUseAltDCFor_CREATERC_REFLOW))) {
- return mAltDC->CreateRenderingContext(aContext);
- }
-#endif
-
- NS_ASSERTION( mPrintDC, "CreateRenderingContext for non-print DC");
-
- nsIRenderingContext *pContext = new nsRenderingContextOS2;
- if (!pContext)
- return NS_ERROR_OUT_OF_MEMORY;
- NS_ADDREF(pContext);
-
- nsPrintSurface *surf = new nsPrintSurface;
- if (!surf)
- return NS_ERROR_OUT_OF_MEMORY;
-
- surf->Init( mPrintPS, mWidth, mHeight, 0);
-
- nsresult rc = pContext->Init(this, surf);
-
- if( NS_OK != rc)
- {
- delete surf;
- NS_IF_RELEASE(pContext);
- }
-
- aContext = pContext;
-
- return rc;
-}
-
-NS_IMETHODIMP nsDeviceContextOS2 :: SupportsNativeWidgets(PRBool &aSupportsWidgets)
-{
- if (nsnull == mPrintDC)
- aSupportsWidgets = PR_TRUE;
- else
- aSupportsWidgets = PR_FALSE;
-
- return NS_OK;
-}
-
-nscolor GetSysColorInfo(int iSysColor)
-{
- long lColor = ::WinQuerySysColor( HWND_DESKTOP, iSysColor, 0);
- RGB2 *pRGB2 = (RGB2*) &lColor;
- return NS_RGB( pRGB2->bRed, pRGB2->bGreen, pRGB2->bBlue);
-}
-
-/* Helper function to query font from INI file */
-
-void QueryFontFromINI(char* fontType, char* fontName, ULONG ulLength)
-{
- ULONG ulMaxNameL = ulLength;
-
- /* We had to switch to using PrfQueryProfileData because */
- /* some users have binary font data in their INI files */
- BOOL rc = PrfQueryProfileData(HINI_USER, "PM_SystemFonts", fontType,
- fontName, &ulMaxNameL);
- /* If there was no entry in the INI, default to something */
- if (rc == FALSE) {
- /* Different values for DBCS vs. SBCS */
- if (!IsDBCS()) {
- /* WarpSans is only available on Warp 4 and above */
- if (gIsWarp4)
- strcpy(fontName, "9.WarpSans");
- else
- strcpy(fontName, "8.Helv");
- } else {
- /* WarpSans is only available on Warp 4 and above */
- if (gIsWarp4)
- strcpy(fontName, "9.WarpSans Combined");
- else
- strcpy(fontName, "10.Helv Combined");
- }
- } else {
- /* null terminate fontname */
- fontName[ulMaxNameL] = '\0';
- }
-}
-
-
-nsresult GetSysFontInfo(nsSystemFontID aID, nsFont* aFont)
-{
- char szFontNameSize[MAXNAMEL];
-
- switch (aID)
- {
- case eSystemFont_Icon:
- QueryFontFromINI("IconText", szFontNameSize, MAXNAMEL);
- break;
-
- case eSystemFont_Menu:
- QueryFontFromINI("Menus", szFontNameSize, MAXNAMEL);
- break;
-
- case eSystemFont_Caption:
-
- case eSystemFont_MessageBox:
-
- case eSystemFont_SmallCaption:
-
- case eSystemFont_StatusBar:
- case eSystemFont_Tooltips:
-
- case eSystemFont_Widget:
-
- case eSystemFont_Window: // css3
- case eSystemFont_Document:
- case eSystemFont_Workspace:
- case eSystemFont_Desktop:
- case eSystemFont_Info:
- case eSystemFont_Dialog:
- case eSystemFont_Button:
- case eSystemFont_PullDownMenu:
- case eSystemFont_List:
- case eSystemFont_Field:
- QueryFontFromINI("WindowText", szFontNameSize, MAXNAMEL);
- break;
- } // switch
-
- int pointSize;
- char *szFacename;
-
- pointSize = atoi(szFontNameSize);
- szFacename = strchr(szFontNameSize, '.');
-
- if ((pointSize == 0) || (!szFacename) || (*(szFacename++) == '\0')) {
- return NS_ERROR_FAILURE;
- }
-
-#ifdef OLDCODE
- PRUnichar name[FACESIZE];
- name[0] = 0;
- MultiByteToWideChar(0, szFacename,
- strlen(szFacename) + 1, name, sizeof(name)/sizeof(name[0]));
-#endif
- aFont->name.AssignWithConversion(szFacename);
-
- // Do Style
- aFont->style = NS_FONT_STYLE_NORMAL;
-#if 0
- if (ptrLogFont->lfItalic)
- {
- aFont->style = NS_FONT_STYLE_ITALIC;
- }
-#endif
- // XXX What about oblique?
-
- aFont->variant = NS_FONT_VARIANT_NORMAL;
-
- // Do Weight
-#if 0
- aFont->weight = (ptrLogFont->lfWeight == FW_BOLD ?
- NS_FONT_WEIGHT_BOLD : NS_FONT_WEIGHT_NORMAL);
-#else
- aFont->weight = NS_FONT_WEIGHT_NORMAL;
-#endif
-
- // Do decorations
- aFont->decorations = NS_FONT_DECORATION_NONE;
-#if 0
- if (ptrLogFont->lfUnderline)
- {
- aFont->decorations |= NS_FONT_DECORATION_UNDERLINE;
- }
- if (ptrLogFont->lfStrikeOut)
- {
- aFont->decorations |= NS_FONT_DECORATION_LINE_THROUGH;
- }
-#endif
-
- // Do Size
- aFont->size = NSIntPointsToTwips(pointSize);
-
- aFont->systemFont = PR_TRUE;
-
- return NS_OK;
-}
-
-NS_IMETHODIMP nsDeviceContextOS2 :: GetSystemFont(nsSystemFontID aID, nsFont *aFont) const
-{
- nsresult status = NS_OK;
-
- switch (aID) {
- case eSystemFont_Caption:
- case eSystemFont_Icon:
- case eSystemFont_Menu:
- case eSystemFont_MessageBox:
- case eSystemFont_SmallCaption:
- case eSystemFont_StatusBar:
- case eSystemFont_Tooltips:
- case eSystemFont_Widget:
-
- case eSystemFont_Window: // css3
- case eSystemFont_Document:
- case eSystemFont_Workspace:
- case eSystemFont_Desktop:
- case eSystemFont_Info:
- case eSystemFont_Dialog:
- case eSystemFont_Button:
- case eSystemFont_PullDownMenu:
- case eSystemFont_List:
- case eSystemFont_Field:
- {
- status = GetSysFontInfo(aID, aFont);
- break;
- }
- }
-
- return status;
-}
-
-NS_IMETHODIMP nsDeviceContextOS2 :: CheckFontExistence(const nsString& aFontName)
-{
- HPS hps = NULL;
-
- if (NULL != mPrintDC){
- hps = mPrintPS;
- } else {
- hps = ::WinGetPS((HWND)mWidget);
- }
-
- nsAutoCharBuffer fontName;
- PRInt32 fontNameLength;
- WideCharToMultiByte(0, aFontName.get(), aFontName.Length(),
- fontName, fontNameLength);
-
- long lWant = 0;
- long lFonts = GFX (::GpiQueryFonts(hps, QF_PUBLIC | QF_PRIVATE,
- fontName.get(), &lWant, 0, 0),
- GPI_ALTERROR);
-
- if (NULL == mPrintDC)
- ::WinReleasePS(hps);
-
- if (lFonts > 0)
- return NS_OK;
- else
- return NS_ERROR_FAILURE;
-}
-
-NS_IMETHODIMP nsDeviceContextOS2::GetDepth(PRUint32& aDepth)
-{
- aDepth = mDepth;
- return NS_OK;
-}
-
-nsresult
-nsDeviceContextOS2::SetDPI(PRInt32 aPrefDPI)
-{
- // Set OSVal to what the operating system thinks the logical resolution is.
- long OSVal;
- HPS ps = ::WinGetScreenPS(HWND_DESKTOP);
- HDC hdc = GFX (::GpiQueryDevice (ps), HDC_ERROR);
- GFX (::DevQueryCaps(hdc, CAPS_HORIZONTAL_FONT_RES, 1, &OSVal), FALSE);
- ::WinReleasePS(ps);
-
- if (aPrefDPI > 0) {
- // If there's a valid pref value for the logical resolution,
- // use it.
- mDpi = aPrefDPI;
- } else if ((aPrefDPI == 0) || (OSVal > 96)) {
- // Either if the pref is 0 (force use of OS value) or the OS
- // value is bigger than 96, use the OS value.
- mDpi = OSVal;
- } else {
- // if we couldn't get the pref or it's negative, and the OS
- // value is under 96ppi, then use 96.
- mDpi = 96;
- }
-
- int pt2t = 72;
-
- // make p2t a nice round number - this prevents rounding problems
- mPixelsToTwips = float(NSToIntRound(float(NSIntPointsToTwips(pt2t)) / float(mDpi)));
- mTwipsToPixels = 1.0f / mPixelsToTwips;
-
- // XXX need to reflow all documents
- return NS_OK;
-}
-
-int prefChanged(const char *aPref, void *aClosure)
-{
- nsDeviceContextOS2 *context = (nsDeviceContextOS2*)aClosure;
- nsresult rv;
-
- if (nsCRT::strcmp(aPref, "layout.css.dpi")==0) {
- PRInt32 dpi;
- nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &rv));
- rv = prefs->GetIntPref(aPref, &dpi);
- if (NS_SUCCEEDED(rv))
- context->SetDPI(dpi);
-
- }
-
- return 0;
-}
-
-NS_IMETHODIMP nsDeviceContextOS2 :: GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight)
-{
-#ifdef NS_PRINT_PREVIEW
- // Defer to Alt when there is one
- if (mAltDC && (mUseAltDC & kUseAltDCFor_SURFACE_DIM))
- return mAltDC->GetDeviceSurfaceDimensions(aWidth, aHeight);
-#endif
-
- if ( mSpec )
- {
- // we have a printer device
- aWidth = NSToIntRound(mWidth * mDevUnitsToAppUnits);
- aHeight = NSToIntRound(mHeight * mDevUnitsToAppUnits);
- }
- else {
- nsRect area;
- ComputeFullAreaUsingScreen ( &area );
- aWidth = area.width;
- aHeight = area.height;
- }
-
- return NS_OK;
-}
-
-NS_IMETHODIMP nsDeviceContextOS2 :: GetRect(nsRect &aRect)
-{
- if ( mSpec )
- {
- // we have a printer device
- aRect.x = 0;
- aRect.y = 0;
- aRect.width = NSToIntRound(mWidth * mDevUnitsToAppUnits);
- aRect.height = NSToIntRound(mHeight * mDevUnitsToAppUnits);
- }
- else
- ComputeFullAreaUsingScreen ( &aRect );
-
- return NS_OK;
-}
-
-
-NS_IMETHODIMP nsDeviceContextOS2 :: GetClientRect(nsRect &aRect)
-{
- if ( mSpec )
- {
- // we have a printer device
- aRect.x = 0;
- aRect.y = 0;
- aRect.width = NSToIntRound(mWidth * mDevUnitsToAppUnits);
- aRect.height = NSToIntRound(mHeight * mDevUnitsToAppUnits);
- }
- else
- ComputeClientRectUsingScreen ( &aRect );
-
- return NS_OK;
-}
-
-NS_IMETHODIMP nsDeviceContextOS2 :: GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
- nsIDeviceContext *&aContext)
-{
- PRTQUEUE *pq;
-
- aContext = new nsDeviceContextOS2();
- if(nsnull != aContext){
- NS_ADDREF(aContext);
- } else {
- return NS_ERROR_OUT_OF_MEMORY;
- }
-
- ((nsDeviceContextOS2 *)aContext)->mSpec = aDevice;
- NS_ADDREF(aDevice);
-
- int numCopies = 0;
- int printerDest = 0;
- char *file = nsnull;
-
- ((nsDeviceContextSpecOS2 *)aDevice)->GetPRTQUEUE(pq);
- ((nsDeviceContextSpecOS2 *)aDevice)->GetCopies(numCopies);
- ((nsDeviceContextSpecOS2 *)aDevice)->GetDestination(printerDest);
- if (!printerDest)
- ((nsDeviceContextSpecOS2 *)aDevice)->GetPath(&file);
-
- HDC dc = PrnOpenDC(pq, "Mozilla", numCopies, printerDest, file);
-
- if (!dc) {
- return NS_ERROR_FAILURE; //PMERROR("DevOpenDC");
- } /* endif */
-
- return ((nsDeviceContextOS2 *)aContext)->Init((nsNativeDeviceContext)dc, this);
-}
-
-nsresult nsDeviceContextOS2::CreateFontAliasTable()
-{
- nsresult result = NS_OK;
-
- if( !mFontAliasTable)
- {
- mFontAliasTable = new nsHashtable;
-
- nsAutoString times; times.AssignLiteral("Times");
- nsAutoString timesNewRoman; timesNewRoman.AssignLiteral("Times New Roman");
- nsAutoString timesRoman; timesRoman.AssignLiteral("Tms Rmn");
- nsAutoString arial; arial.AssignLiteral("Arial");
- nsAutoString helv; helv.AssignLiteral("Helv");
- nsAutoString helvetica; helvetica.AssignLiteral("Helvetica");
- nsAutoString courier; courier.AssignLiteral("Courier");
- nsAutoString courierNew; courierNew.AssignLiteral("Courier New");
- nsAutoString sans; sans.AssignLiteral("Sans");
- nsAutoString unicode; unicode.AssignLiteral("Unicode");
- nsAutoString timesNewRomanMT30; timesNewRomanMT30.AssignLiteral("Times New Roman MT 30");
- nsAutoString nullStr;
-
- AliasFont(times, timesNewRoman, timesRoman, PR_FALSE);
- AliasFont(timesRoman, timesNewRoman, times, PR_FALSE);
- AliasFont(timesNewRoman, timesRoman, times, PR_FALSE);
- AliasFont(arial, helv, helvetica, PR_FALSE);
- AliasFont(helvetica, helv, arial, PR_FALSE);
- AliasFont(courier, courierNew, nullStr, PR_TRUE);
- AliasFont(courierNew, courier, nullStr, PR_FALSE);
- AliasFont(sans, helv, arial, PR_FALSE);
-
- // Is this right?
- AliasFont(unicode, timesNewRomanMT30, nullStr, PR_FALSE);
- }
- return result;
-}
-
-// Printing ------------------------------------------------------------------
-nsresult nsDeviceContextOS2::PrepareDocument(PRUnichar * aTitle, PRUnichar* aPrintToFileName)
-{
- nsresult rv = NS_OK;
-
- if (NULL != mPrintDC){
- nsString titleStr;
- titleStr = aTitle;
- char *title = GetACPString(titleStr);
-
- PSZ pszDocName;
- const PSZ pszGenericDocName = "MozillaDocument";
-
- if (title) {
- pszDocName = title;
- } else {
- pszDocName = pszGenericDocName;
- }
-
- long lDummy = 0;
- long lResult = ::DevEscape(mPrintDC, DEVESC_STARTDOC,
- strlen(pszDocName) + 1, pszDocName,
- &lDummy, NULL);
-
- mPrintingStarted = PR_TRUE;
-
- if (lResult == DEV_OK)
- rv = NS_OK;
- else
- rv = NS_ERROR_GFX_PRINTER_STARTDOC;
-
- if (title != nsnull) {
- nsMemory::Free(title);
- }
- }
-
- return rv;
-}
-
-nsresult nsDeviceContextOS2::BeginDocument(PRUnichar * aTitle, PRUnichar* aPrintToFileName, PRInt32 aStartPage, PRInt32 aEndPage)
-{
- // Everything is done in PrepareDocument
- return NS_OK;
-}
-
-nsresult nsDeviceContextOS2::EndDocument()
-{
- if (NULL != mPrintDC)
- {
- long lOutCount = 2;
- USHORT usJobID = 0;
- long lResult = ::DevEscape(mPrintDC, DEVESC_ENDDOC,
- 0, NULL,
- &lOutCount, (PBYTE)&usJobID);
- if (lResult == DEV_OK)
- return NS_OK;
- else
- return NS_ERROR_GFX_PRINTER_ENDDOC;
- }
-
- return NS_OK;
-}
-
-nsresult nsDeviceContextOS2::AbortDocument()
-{
- if (NULL != mPrintDC)
- {
- long ldummy = 0;
- long lResult = ::DevEscape(mPrintDC, DEVESC_ABORTDOC, 0, NULL,
- &ldummy, NULL);
- if (lResult == DEV_OK)
- return NS_OK;
- else
- return NS_ERROR_ABORT;
- }
-
- return NS_OK;
-}
-
-
-nsresult nsDeviceContextOS2::BeginPage()
-{
- if (mPrintingStarted) {
- mPrintingStarted = PR_FALSE;
- return NS_OK;
- }
-
- if (NULL != mPrintDC)
- {
- long lDummy = 0;
- long lResult = ::DevEscape(mPrintDC, DEVESC_NEWFRAME, 0, NULL,
- &lDummy, NULL);
-
- if (lResult == DEV_OK)
- return NS_OK;
- else
- return NS_ERROR_GFX_PRINTER_STARTPAGE;
- }
-
- return NS_OK;
-
-}
-
-nsresult nsDeviceContextOS2::EndPage()
-{
- return NS_OK;
-}
-
-char*
-nsDeviceContextOS2::GetACPString(const nsString& aStr)
-{
- if (aStr.Length() == 0) {
- return nsnull;
- }
-
- nsAutoCharBuffer acp;
- PRInt32 acpLength;
- WideCharToMultiByte(0, aStr.get(), aStr.Length(), acp, acpLength);
- return ToNewCString(nsDependentCString(acp.get()));
-}
-
-BOOL nsDeviceContextOS2::isPrintDC()
-{
- if ( mPrintDC == nsnull )
- return 0;
-
- else
- return 1;
-}
-PRBool nsDeviceContextOS2::SupportsRasterFonts()
-{
- return mSupportsRasterFonts;
-}
deleted file mode 100644
--- a/gfx/src/os2/nsDeviceContextOS2.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef nsDeviceContextOS2_h___
-#define nsDeviceContextOS2_h___
-
-#include "nsGfxDefs.h"
-
-#include "nsDeviceContext.h"
-#include "nsIScreenManager.h"
-#include "nsDeviceContextSpecOS2.h"
-
-class nsIScreen;
-
-class nsDeviceContextOS2 : public DeviceContextImpl
-{
-public:
- nsDeviceContextOS2();
-
- NS_IMETHOD Init(nsNativeWidget aWidget);
-
- using DeviceContextImpl::CreateRenderingContext;
- NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext);
-
- NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets);
-
- NS_IMETHOD GetSystemFont(nsSystemFontID anID, nsFont *aFont) const;
-
- NS_IMETHOD CheckFontExistence(const nsString& aFontName);
-
- NS_IMETHOD GetDepth(PRUint32& aDepth);
-
- NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight);
- NS_IMETHOD GetRect(nsRect &aRect);
- NS_IMETHOD GetClientRect(nsRect &aRect);
-
- NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
- nsIDeviceContext *&aContext);
-
- NS_IMETHOD PrepareDocument(PRUnichar * aTitle,
- PRUnichar* aPrintToFileName);
- NS_IMETHOD BeginDocument(PRUnichar * aTitle, PRUnichar* aPrintToFileName, PRInt32 aStartPage, PRInt32 aEndPage);
- NS_IMETHOD EndDocument(void);
- NS_IMETHOD AbortDocument(void);
-
- NS_IMETHOD BeginPage(void);
- NS_IMETHOD EndPage(void);
-
- // Static Helper Methods
- static char* GetACPString(const nsString& aStr);
- nsresult SetDPI(PRInt32 aPrefDPI);
- int GetDPI() { return mDpi; };
-
-protected:
- virtual ~nsDeviceContextOS2();
- void CommonInit(HDC aDC);
- nsresult Init(nsNativeDeviceContext aContext, nsIDeviceContext *aOrigContext);
- void FindScreen ( nsIScreen** outScreen ) ;
- void ComputeClientRectUsingScreen ( nsRect* outRect ) ;
- void ComputeFullAreaUsingScreen ( nsRect* outRect ) ;
-
- PRBool mCachedClientRect;
- PRBool mCachedFullRect;
- PRBool mPrintingStarted;
-
- nsIDrawingSurface* mSurface;
- PRUint32 mDepth; // bit depth of device
- PRBool mIsPaletteDevice;
- PRInt32 mWidth;
- PRInt32 mHeight;
- nsRect mClientRect;
- nsIDeviceContextSpec *mSpec;
- PRBool mSupportsRasterFonts;
-
- nsCOMPtr<nsIScreenManager> mScreenManager;
- static PRUint32 sNumberOfScreens;
- static nscoord mDpi;
-
-public:
- HDC mPrintDC;
- HPS mPrintPS;
-
- enum nsPrintState
- {
- nsPrintState_ePreBeginDoc,
- nsPrintState_eBegunDoc,
- nsPrintState_eBegunFirstPage,
- nsPrintState_eEndedDoc
- } mPrintState;
-
- BOOL isPrintDC();
- PRBool SupportsRasterFonts();
- PRBool IsPaletteDevice() {return mIsPaletteDevice;};
- nsresult CreateFontAliasTable();
-};
-
-int PR_CALLBACK prefChanged(const char *aPref, void *aClosure);
-
-#endif /* nsDeviceContextOS2_h___ */
deleted file mode 100644
--- a/gfx/src/os2/nsDrawingSurfaceOS2.cpp
+++ /dev/null
@@ -1,623 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Mozilla OS/2 libraries.
- *
- * The Initial Developer of the Original Code is
- * John Fairhurst, <john_fairhurst@iname.com>.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Pierre Phaneuf <pp@ludusdesign.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsGfxDefs.h"
-#include "nsHashtable.h"
-#include "nsIWidget.h"
-#include "nsDrawingSurfaceOS2.h"
-#include "nsFontMetricsOS2.h"
-#include "nsPaletteOS2.h"
-
-#define LCID_START 2
-
-
-// Base class -- fonts, palette and xpcom -----------------------------------
-
-NS_IMPL_ISUPPORTS1(nsDrawingSurfaceOS2, nsIDrawingSurface)
-
-// We start allocated lCIDs at 2. This leaves #1 for nsFontMetricsOS2 to
-// do testing with, and 0 is, of course, LCID_DEFAULT.
-
-nsDrawingSurfaceOS2::nsDrawingSurfaceOS2()
- : mNextID(LCID_START), mTopID(1), mPS(0), mOwnPS(PR_FALSE),
- mWidth (0), mHeight (0)
-{
- mHTFonts = new nsHashtable;
-}
-
-nsDrawingSurfaceOS2::~nsDrawingSurfaceOS2()
-{
- DisposeFonts();
-}
-
-void nsDrawingSurfaceOS2::DisposeFonts()
-{
- if( mHTFonts)
- {
- // free font things
- GFX (::GpiSetCharSet(mPS, LCID_DEFAULT), FALSE);
-
- for (int i = LCID_START; i <= mTopID; i++) {
- GFX (::GpiDeleteSetId(mPS, i), FALSE);
- }
- delete mHTFonts;
- mHTFonts = 0;
- }
-}
-
-// Key for the hashtable
-typedef nsVoidKey FontHandleKey;
-
-void nsDrawingSurfaceOS2::SelectFont(nsFontOS2* aFont)
-{
- FontHandleKey key((void*)aFont->mHashMe);
-
- long lcid = (long) mHTFonts->Get(&key);
- if (lcid == 0) {
- if (mNextID == 255) {
- // ids used up, need to empty table and start again.
- FlushFontCache();
- }
-
- lcid = mNextID;
- mNextID++;
- CHK_SUCCESS (::GpiCreateLogFont(mPS, 0, lcid, &aFont->mFattrs),
- FONT_MATCH);
- mHTFonts->Put(&key, (void *) lcid);
- if (mTopID < 254) {
- mTopID++;
- }
- }
-
- aFont->SelectIntoPS(mPS, lcid);
-}
-
-void nsDrawingSurfaceOS2::FlushFontCache()
-{
- mHTFonts->Reset();
- mNextID = LCID_START;
- // leave mTopID where it is.
-}
-
-// OS/2 - XP coord conversion ----------------------------------------------
-
-// get inclusive-inclusive rect
-void nsDrawingSurfaceOS2::NS2PM_ININ( const nsRect &in, RECTL &rcl)
-{
- const static nscoord kBottomLeftLimit = -8192;
- const static nscoord kTopRightLimit = 16384;
-
- PRInt32 ulHeight = GetHeight ();
-
- rcl.xLeft = PR_MAX(kBottomLeftLimit, in.x);
- rcl.xRight = PR_MIN(in.x+in.width-1, kTopRightLimit);
- rcl.yTop = PR_MIN(ulHeight-in.y-1, kTopRightLimit);
- rcl.yBottom = PR_MAX(rcl.yTop-in.height+1, kBottomLeftLimit);
- return;
-}
-
-void nsDrawingSurfaceOS2::PM2NS_ININ( const RECTL &in, nsRect &out)
-{
- PRInt32 ulHeight = GetHeight ();
-
- out.x = in.xLeft;
- out.width = in.xRight - in.xLeft + 1;
- out.y = ulHeight - in.yTop - 1;
- out.height = in.yTop - in.yBottom + 1;
-}
-
-// get in-ex rect
-void nsDrawingSurfaceOS2::NS2PM_INEX( const nsRect &in, RECTL &rcl)
-{
- NS2PM_ININ( in, rcl);
- rcl.xRight++;
- rcl.yTop++;
-}
-
-void nsDrawingSurfaceOS2::NS2PM( PPOINTL aPointl, ULONG cPointls)
-{
- PRInt32 ulHeight = GetHeight ();
-
- for( ULONG i = 0; i < cPointls; i++)
- aPointl[ i].y = ulHeight - aPointl[ i].y - 1;
-}
-
-nsresult nsDrawingSurfaceOS2::GetDimensions( PRUint32 *aWidth, PRUint32 *aHeight)
-{
- if( !aWidth || !aHeight)
- return NS_ERROR_NULL_POINTER;
-
- *aWidth = mWidth;
- *aHeight = mHeight;
-
- return NS_OK;
-}
-
-
-// Offscreen surface --------------------------------------------------------
-
-nsOffscreenSurface::nsOffscreenSurface() : mDC(0), mBitmap(0),
- mInfoHeader(0), mBits(0),
- mYPels(0), mScans(0)
-{
-}
-
-NS_IMETHODIMP nsOffscreenSurface :: Init(HPS aPS)
-{
- mPS = aPS;
-
- return NS_OK;
-}
-
-// Setup a new offscreen surface which is to be compatible with the
-// passed-in presentation space.
-nsresult nsOffscreenSurface::Init( HPS aCompatiblePS,
- PRInt32 aWidth, PRInt32 aHeight, PRUint32 aFlags)
-{
- nsresult rc = NS_ERROR_FAILURE;
-
- // Find the compatible device context and create a memory one
- HDC hdcCompat = GFX (::GpiQueryDevice (aCompatiblePS), HDC_ERROR);
- DEVOPENSTRUC dop = { 0, 0, 0, 0, 0 };
- mDC = GFX (::DevOpenDC( 0/*hab*/, OD_MEMORY, "*", 5, (PDEVOPENDATA) &dop, hdcCompat), DEV_ERROR);
-
- if( DEV_ERROR != mDC)
- {
- // create the PS
- SIZEL sizel = { 0, 0 };
- mPS = GFX (::GpiCreatePS (0/*hab*/, mDC, &sizel,
- PU_PELS | GPIT_MICRO | GPIA_ASSOC), GPI_ERROR);
-
- if( GPI_ERROR != mPS)
- {
- mOwnPS = PR_TRUE;
-
- nsPaletteOS2::SelectGlobalPalette(mPS);
-
- // now create a bitmap of the right size
- BITMAPINFOHEADER2 hdr = { 0 };
-
- hdr.cbFix = sizeof( BITMAPINFOHEADER2);
- hdr.cx = aWidth;
- hdr.cy = aHeight;
- hdr.cPlanes = 1;
-
- // find bitdepth
- LONG lBitCount = 0;
- GFX (::DevQueryCaps( hdcCompat, CAPS_COLOR_BITCOUNT, 1, &lBitCount), FALSE);
- hdr.cBitCount = (USHORT) lBitCount;
-
- mBitmap = GFX (::GpiCreateBitmap (mPS, &hdr, 0, 0, 0), GPI_ERROR);
-
- if( GPI_ERROR != mBitmap)
- {
- // set final stats & select bitmap into ps
- mHeight = aHeight;
- mWidth = aWidth;
- GFX (::GpiSetBitmap (mPS, mBitmap), HBM_ERROR);
- rc = NS_OK;
- }
- }
- }
-
- return rc;
-}
-
-nsOffscreenSurface::~nsOffscreenSurface()
-{
- DisposeFonts();
-
- if (mBitmap) {
- GFX (::GpiSetBitmap (mPS, 0), HBM_ERROR);
- GFX (::GpiDeleteBitmap (mBitmap), FALSE);
- }
- if (mOwnPS) {
- GFX (::GpiDestroyPS (mPS), FALSE);
- }
- if (mDC) {
- ::DevCloseDC(mDC);
- }
-
- if( mInfoHeader)
- free( mInfoHeader);
- delete [] mBits;
-}
-
-// Okay; plan here is to get the bits and hope that the fact that we're
-// returning an upside-down rectangle doesn't matter.
-//
-// If it does, then the following needs to be done:
-//
-// * undefine the USD flag in libimg
-// * alter the draw code in nsImageOS2 to draw right-way-up
-// * fix the printing case (probably involving an ugly xform)
-//
-nsresult nsOffscreenSurface::Lock( PRInt32 aX, PRInt32 aY,
- PRUint32 aWidth, PRUint32 aHeight,
- void **aBits, PRInt32 *aStride,
- PRInt32 *aWidthBytes,
- PRUint32 aFlags)
-{
- // Trust other platforms to ensure that we don't get nested!
- PRInt32 lStride = 0;
- ULONG rc = 0;
-
- // Allocate buffers first time we get called.
- //
- // Need to look at the way in which this functionality is exercised:
- // may actually be more efficient to only grab the section of bitmap
- // required on each call, and to free up memory afterwards.
- //
- // Currently: * allocate once enough space for the entire bitmap
- // * only grab & set the required scanlines
- //
- if( !mBits)
- {
- BITMAPINFOHEADER bih = { sizeof( BITMAPINFOHEADER), 0, 0, 0, 0 };
-
- rc = GFX (::GpiQueryBitmapInfoHeader (mBitmap, (PBITMAPINFOHEADER2) &bih), FALSE);
-
- // alloc space to query pel data into...
- lStride = RASWIDTH( bih.cx, bih.cBitCount);
- mBits = new PRUint8 [ lStride * bih.cy ];
-
- // ..and colour table too
- int cols = -1;
- if( bih.cBitCount >= 24) cols = 0;
- else cols = 1 << bih.cBitCount;
-
- int szStruct = sizeof( BITMAPINFOHEADER2) + cols * sizeof( RGB2);
-
- mInfoHeader = (PBITMAPINFOHEADER2) calloc( szStruct, 1);
- mInfoHeader->cbFix = sizeof( BITMAPINFOHEADER2);
- mInfoHeader->cx = bih.cx;
- mInfoHeader->cy = bih.cy;
- mInfoHeader->cPlanes = 1;
- mInfoHeader->cBitCount = (USHORT) bih.cBitCount;
- // GPI-Ref says these have to be set too...
- mInfoHeader->ulCompression = BCA_UNCOMP;
- mInfoHeader->usRecording = BRA_BOTTOMUP;
- mInfoHeader->usRendering = BRH_NOTHALFTONED; // ...hmm...
- mInfoHeader->ulColorEncoding = BCE_RGB;
- }
- else
- lStride = RASWIDTH( mInfoHeader->cx, mInfoHeader->cBitCount);
-
- // record starting scanline (bottom is 0)
- mYPels = mInfoHeader->cy - aY - aHeight;
- mScans = aHeight;
-
- rc = GFX (::GpiQueryBitmapBits (mPS, mYPels, mScans, (PBYTE)mBits,
- (PBITMAPINFO2)mInfoHeader), GPI_ALTERROR);
-
-#ifdef DEBUG
- if( rc != mScans) {
- PMERROR( "GpiQueryBitmapBits");
- printf( "Lock, requested %d x %d and got %d x %d\n",
- aWidth, aHeight, (int) mInfoHeader->cx, aHeight);
- }
-#endif
-
- // Okay. Now have current state of bitmap in mBits.
- *aStride = lStride;
- *aBits = (void*) (mBits + (aX * (mInfoHeader->cBitCount >> 3)));
- *aWidthBytes = aWidth * (mInfoHeader->cBitCount >> 3);
-
- return NS_OK;
-}
-
-nsresult nsOffscreenSurface::Unlock()
-{
- GFX (::GpiSetBitmapBits (mPS, mYPels, mScans, (PBYTE)mBits,
- (PBITMAPINFO2)mInfoHeader), GPI_ALTERROR);
-
- return NS_OK;
-}
-
-nsresult nsOffscreenSurface::IsOffscreen( PRBool *aOffScreen)
-{
- if( !aOffScreen)
- return NS_ERROR_NULL_POINTER;
-
- *aOffScreen = PR_TRUE;
-
- return NS_OK;
-}
-
-nsresult nsOffscreenSurface::IsPixelAddressable( PRBool *aAddressable)
-{
- if( !aAddressable)
- return NS_ERROR_NULL_POINTER;
-
- *aAddressable = PR_TRUE;
-
- return NS_OK;
-}
-
-nsresult nsOffscreenSurface::GetPixelFormat( nsPixelFormat *aFormat)
-{
- if( !aFormat)
- return NS_ERROR_NULL_POINTER;
-
- // Okay. Who knows what's going on here - we (as wz) currently support
- // only 8 and 24 bpp bitmaps; dunno what should be done for 32 bpp,
- // even if os/2 supports them.
- //
- // (prob'ly need to get the FOURCC stuff into the act for 16bpp?)
- //
- BITMAPINFOHEADER bih = { sizeof( BITMAPINFOHEADER), 0, 0, 0, 0 };
- GFX (::GpiQueryBitmapInfoHeader (mBitmap, (PBITMAPINFOHEADER2)&bih), FALSE);
-
- switch( bih.cBitCount)
- {
- case 8:
- memset( aFormat, 0, sizeof(nsPixelFormat));
- break;
-
- case 16:
- aFormat->mRedZeroMask = 0x001F;
- aFormat->mGreenZeroMask = 0x003F;
- aFormat->mBlueZeroMask = 0x001F;
- aFormat->mAlphaZeroMask = 0;
- aFormat->mRedMask = 0xF800;
- aFormat->mGreenMask = 0x07E0;
- aFormat->mBlueMask = 0x001F;
- aFormat->mAlphaMask = 0;
- aFormat->mRedCount = 5;
- aFormat->mGreenCount = 6;
- aFormat->mBlueCount = 5;
- aFormat->mAlphaCount = 0;
- aFormat->mRedShift = 11;
- aFormat->mGreenShift = 5;
- aFormat->mBlueShift = 0;
- aFormat->mAlphaShift = 0;
- break;
-
- case 24:
- aFormat->mRedZeroMask = 0x0000FF;
- aFormat->mGreenZeroMask = 0x0000FF;
- aFormat->mBlueZeroMask = 0x0000FF;
- aFormat->mAlphaZeroMask = 0;
- aFormat->mRedMask = 0x0000FF;
- aFormat->mGreenMask = 0x00FF00;
- aFormat->mBlueMask = 0xFF0000;
- aFormat->mAlphaMask = 0;
- aFormat->mRedCount = 8;
- aFormat->mGreenCount = 8;
- aFormat->mBlueCount = 8;
- aFormat->mAlphaCount = 0;
- aFormat->mRedShift = 0;
- aFormat->mGreenShift = 8;
- aFormat->mBlueShift = 16;
- aFormat->mAlphaShift = 0;
- break;
-
- case 32:
- aFormat->mRedZeroMask = 0x000000FF;
- aFormat->mGreenZeroMask = 0x000000FF;
- aFormat->mBlueZeroMask = 0x000000FF;
- aFormat->mAlphaZeroMask = 0x000000FF;
- aFormat->mRedMask = 0x00FF0000;
- aFormat->mGreenMask = 0x0000FF00;
- aFormat->mBlueMask = 0x000000FF;
- aFormat->mAlphaMask = 0xFF000000;
- aFormat->mRedCount = 8;
- aFormat->mGreenCount = 8;
- aFormat->mBlueCount = 8;
- aFormat->mAlphaCount = 8;
- aFormat->mRedShift = 16;
- aFormat->mGreenShift = 8;
- aFormat->mBlueShift = 0;
- aFormat->mAlphaShift = 24;
- break;
-
- default:
-#ifdef DEBUG
- printf( "Bad bit-depth for GetPixelFormat (%d)\n", bih.cBitCount);
-#endif
- break;
- }
-
- return NS_OK;
-}
-
-// Non-offscreen surfaces, base for window & print --------------------------
-nsOnscreenSurface::nsOnscreenSurface() : mProxySurface(nsnull)
-{
-}
-
-nsOnscreenSurface::~nsOnscreenSurface()
-{
- NS_IF_RELEASE(mProxySurface);
-}
-
-void nsOnscreenSurface::EnsureProxy()
-{
- if( !mProxySurface)
- {
- PRUint32 width, height;
- GetDimensions( &width, &height);
-
- mProxySurface = new nsOffscreenSurface;
- if( NS_SUCCEEDED(mProxySurface->Init( mPS, width, height, NS_CREATEDRAWINGSURFACE_FOR_PIXEL_ACCESS)))
- {
- NS_ADDREF(mProxySurface);
- }
- else
- {
- delete mProxySurface;
- mProxySurface = nsnull;
- }
- }
-}
-
-nsresult nsOnscreenSurface::Lock( PRInt32 aX, PRInt32 aY,
- PRUint32 aWidth, PRUint32 aHeight,
- void **aBits, PRInt32 *aStride,
- PRInt32 *aWidthBytes,
- PRUint32 aFlags)
-{
- EnsureProxy();
-
-#ifdef DEBUG
- printf( "Locking through a proxy\n");
-#endif
-
- // blit our 'real' bitmap to the proxy surface
- PRUint32 width, height;
- GetDimensions( &width, &height);
- POINTL pts[3] = { { 0, 0 }, { width, height }, { 0, 0 } };
- GFX (::GpiBitBlt (mProxySurface->GetPS (), mPS, 3, pts,
- ROP_SRCCOPY, BBO_OR), GPI_ERROR);
-
- return mProxySurface->Lock( aX, aY, aWidth, aHeight,
- aBits, aStride, aWidthBytes, aFlags);
-}
-
-nsresult nsOnscreenSurface::Unlock()
-{
- nsresult rc = mProxySurface->Unlock();
-
- // blit proxy bitmap back to ours
- PRUint32 width, height;
- GetDimensions( &width, &height);
- POINTL pts[3] = { { 0, 0 }, { width, height }, { 0, 0 } };
- GFX (::GpiBitBlt (mPS, mProxySurface->GetPS (), 3, pts,
- ROP_SRCCOPY, BBO_OR), GPI_ERROR);
-
- return rc;
-}
-
-nsresult nsOnscreenSurface::GetPixelFormat( nsPixelFormat *aFormat)
-{
- EnsureProxy();
- return mProxySurface->GetPixelFormat( aFormat);
-}
-
-nsresult nsOnscreenSurface::IsOffscreen( PRBool *aOffScreen)
-{
- if( !aOffScreen)
- return NS_ERROR_NULL_POINTER;
-
- *aOffScreen = PR_FALSE;
-
- return NS_OK;
-}
-
-nsresult nsOnscreenSurface::IsPixelAddressable( PRBool *aAddressable)
-{
- if( !aAddressable)
- return NS_ERROR_NULL_POINTER;
-
- *aAddressable = PR_FALSE;
-
- return NS_OK;
-}
-
-// Surface for a PM window --------------------------------------------------
-nsWindowSurface::nsWindowSurface() : mWidget(nsnull)
-{
-}
-
-nsWindowSurface::~nsWindowSurface()
-{
- // palette will be deselected in superclass dtor
-
- // need to do this now because hps is invalid after subsequent free
- DisposeFonts();
-
- // release hps if we had instantiated it
- if (mOwnPS) {
- mWidget->FreeNativeData( (void*) mPS, NS_NATIVE_GRAPHIC);
- }
-}
-
-NS_IMETHODIMP nsWindowSurface::Init(HPS aPS, nsIWidget *aWidget)
-{
- mPS = aPS;
- mWidget = aWidget;
-
- return NS_OK;
-}
-
-nsresult nsWindowSurface::Init( nsIWidget *aOwner)
-{
- mWidget = aOwner;
- mPS = (HPS) mWidget->GetNativeData( NS_NATIVE_GRAPHIC);
- mOwnPS = PR_TRUE;
-
- return NS_OK;
-}
-
-nsresult nsWindowSurface::GetDimensions( PRUint32 *aWidth, PRUint32 *aHeight)
-{
- // I don't think we can be more efficient than this, except perhaps by
- // doing some kind of `push' of height from the window to us.
- nsRect rect;
- mWidget->GetClientBounds( rect);
- *aHeight = rect.height;
- *aWidth = rect.width;
- return NS_OK;
-}
-
-PRUint32 nsWindowSurface::GetHeight ()
-{
- nsRect rect;
-
- mWidget->GetClientBounds (rect);
-
- return rect.height;
-}
-
-// Printer surface. A few minor differences, like the page size is fixed ---
-nsPrintSurface::nsPrintSurface()
-{
-}
-
-nsresult nsPrintSurface::Init( HPS aPS, PRInt32 aWidth, PRInt32 aHeight, PRUint32 aFlags)
-{
- mPS = aPS;
- mHeight = aHeight;
- mWidth = aWidth;
-
- return NS_OK;
-}
-
-nsPrintSurface::~nsPrintSurface()
-{
- // PS is owned by the DC; superclass dtor will deselect palette.
-}
deleted file mode 100644
--- a/gfx/src/os2/nsDrawingSurfaceOS2.h
+++ /dev/null
@@ -1,184 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Mozilla OS/2 libraries.
- *
- * The Initial Developer of the Original Code is
- * John Fairhurst, <john_fairhurst@iname.com>.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK *****
- * This Original Code has been modified by IBM Corporation.
- * Modifications made by IBM described herein are
- * Copyright (c) International Business Machines
- * Corporation, 2000
- *
- * Modifications to Mozilla code or documentation
- * identified per MPL Section 3.3
- *
- * Date Modified by Description of modification
- * 03/28/2000 IBM Corp. Changes to make os2.h file similar to windows.h file
- */
-
-#ifndef _nsDrawingSurfaceOS2_h
-#define _nsDrawingSurfaceOS2_h
-
-#include "nsIDrawingSurface.h"
-
-class nsHashtable;
-class nsIWidget;
-class nsFontOS2;
-
-// These were called `drawables' in os2fe.
-//
-// Note that each surface has a ref to the palette of the device context
-// from which it was spun off. This is because drawing surfaces have
-// lifetimes which extend further than the rendering context which
-// created them. The creating object must select the palette into the
-// surface's presentation space; all the drawing surface does is deselect
-// the palette when it's dying.
-//
-// This is rather unwieldy...
-
-class nsDrawingSurfaceOS2 : public nsIDrawingSurface
-{
- nsHashtable *mHTFonts; // cache of fonthandle to lcid
- long mNextID; // next lcid to allocate
- long mTopID; // highest used lcid
-
-protected:
- HPS mPS; // presentation space for this surface
- PRBool mOwnPS; // did we instantiate PS or was it passed in?
- PRInt32 mWidth; // dimensions of drawing surface
- PRInt32 mHeight;
-
-
- nsDrawingSurfaceOS2();
- virtual ~nsDrawingSurfaceOS2();
-
- NS_DECL_ISUPPORTS
-
- void DisposeFonts(); // MUST be called before disposing of PS
-
-
- public:
- NS_IMETHOD GetDimensions( PRUint32 *aWidth, PRUint32 *aHeight);
-
- // os/2 methods
- HPS GetPS() { return mPS; }
- void SelectFont(nsFontOS2* aFont);
- void FlushFontCache();
- virtual PRUint32 GetHeight() { return mHeight; }
-
- // Convertion between XP and OS/2 coordinate space.
- void NS2PM_ININ (const nsRect &in, RECTL &rcl);
- void NS2PM_INEX (const nsRect &in, RECTL &rcl);
- void PM2NS_ININ (const RECTL &in, nsRect &out);
- void NS2PM (PPOINTL aPointl, ULONG cPointls);
-};
-
-// Offscreen surface. Others depend on this.
-class nsOffscreenSurface : public nsDrawingSurfaceOS2
-{
- HDC mDC;
- HBITMAP mBitmap;
-
- PBITMAPINFOHEADER2 mInfoHeader;
- PRUint8 *mBits;
-
- PRInt32 mYPels;
- PRUint32 mScans;
-
- public:
- nsOffscreenSurface();
- virtual ~nsOffscreenSurface();
-
- // os/2 methods
- NS_IMETHOD Init( HPS aCompatiblePS, PRInt32 aWidth, PRInt32 aHeight, PRUint32 aFlags);
- NS_IMETHOD Init(HPS aPS);
-
- HDC GetDC() { return mDC; }
-
- // nsIDrawingSurface methods
- NS_IMETHOD Lock( PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
- void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes,
- PRUint32 aFlags);
- NS_IMETHOD Unlock();
- NS_IMETHOD IsOffscreen( PRBool *aOffScreen);
- NS_IMETHOD IsPixelAddressable( PRBool *aAddressable);
- NS_IMETHOD GetPixelFormat( nsPixelFormat *aFormat);
-};
-
-// Onscreen surface - uses an offscreen to implement bitlevel access
-class nsOnscreenSurface : public nsDrawingSurfaceOS2
-{
- nsOffscreenSurface *mProxySurface;
- void EnsureProxy();
-
- protected:
- nsOnscreenSurface();
- virtual ~nsOnscreenSurface();
-
- public:
- // nsIDrawingSurface methods
- NS_IMETHOD Lock( PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
- void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes,
- PRUint32 aFlags);
- NS_IMETHOD Unlock();
- NS_IMETHOD IsOffscreen( PRBool *aOffScreen);
- NS_IMETHOD IsPixelAddressable( PRBool *aAddressable);
- NS_IMETHOD GetPixelFormat( nsPixelFormat *aFormat);
-};
-
-// Surface for an onscreen window
-class nsWindowSurface : public nsOnscreenSurface
-{
- nsIWidget *mWidget; // window who owns the surface
-
- public:
- nsWindowSurface();
- virtual ~nsWindowSurface();
-
- NS_IMETHOD Init(HPS aPS, nsIWidget *aWidget);
- NS_IMETHOD Init( nsIWidget *aOwner);
- NS_IMETHOD GetDimensions( PRUint32 *aWidth, PRUint32 *aHeight);
-
- virtual PRUint32 GetHeight ();
-};
-
-// Surface for a printer-page
-class nsPrintSurface : public nsOnscreenSurface
-{
- public:
- nsPrintSurface();
- virtual ~nsPrintSurface();
-
- NS_IMETHOD Init( HPS aPS, PRInt32 aWidth, PRInt32 aHeight, PRUint32 aFlags);
-};
-
-#endif
deleted file mode 100644
--- a/gfx/src/os2/nsFontMetricsOS2.cpp
+++ /dev/null
@@ -1,2746 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Mozilla OS/2 libraries.
- *
- * The Initial Developer of the Original Code is
- * John Fairhurst, <john_fairhurst@iname.com>.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Pierre Phaneuf <pp@ludusdesign.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsGfxDefs.h"
-#include "nsIPref.h"
-#include "nsIServiceManager.h"
-#include "nsILanguageAtomService.h"
-#include "nsICharsetConverterManager.h"
-#include "nsLocaleCID.h"
-#include "nsILocaleService.h"
-#include "nsICharRepresentable.h"
-#include "nsISaveAsCharset.h"
-#include "nsIObserver.h"
-#include "nsIObserverService.h"
-#include "nsFontMetricsOS2.h"
-#include "nsQuickSort.h"
-#include "nsTextFormatter.h"
-#include "prmem.h"
-#include "plhash.h"
-#include "prprf.h"
-#include "nsReadableUtils.h"
-#include "nsUnicodeRange.h"
-#include "nsUnicharUtils.h"
-
-#include "nsOS2Uni.h"
-#include <math.h>
-
-#ifdef MOZ_MATHML
- #include <math.h>
-#endif
-
-#undef USER_DEFINED
-#define USER_DEFINED "x-user-def"
-
-#define NS_REPLACEMENT_CHAR PRUnichar(0x003F) // question mark
-
-
-#define NS_MAX_FONT_WEIGHT 900
-#define NS_MIN_FONT_WEIGHT 100
-
-#undef CHAR_BUFFER_SIZE
-#define CHAR_BUFFER_SIZE 1024
-
-
-/***** Global variables *****/
-nsTHashtable<GlobalFontEntry>* nsFontMetricsOS2::gGlobalFonts = nsnull;
-PRBool nsFontMetricsOS2::gSubstituteVectorFonts = PR_TRUE;
-PLHashTable *nsFontMetricsOS2::gFamilyNames = nsnull;
-
-static nsIPref *gPref = nsnull;
-static nsIAtom *gUsersLocale = nsnull;
-static nsIAtom *gSystemLocale = nsnull;
-static nsIAtom *gUserDefined = nsnull;
-static int gInitialized = 0;
-static ULONG gSystemCodePage = 0;
-static ULONG gCurrHashValue = 1;
-
-#ifdef USE_FREETYPE
-PRBool nsFontMetricsOS2::gUseFTFunctions = PR_FALSE;
-static nsISaveAsCharset* gFontSubstituteConverter = nsnull;
-
-static nsIAtom* gJA = nsnull;
-static nsIAtom* gKO = nsnull;
-static nsIAtom* gZHTW = nsnull;
-static nsIAtom* gZHCN = nsnull;
-static nsIAtom* gZHHK = nsnull;
-#endif /* use_freetype */
-
-/***** Charset structures *****/
-enum nsCharset
-{
- eCharset_DEFAULT = 0,
- eCharset_ANSI,
- eCharset_EASTEUROPE,
- eCharset_RUSSIAN,
- eCharset_GREEK,
- eCharset_TURKISH,
- eCharset_HEBREW,
- eCharset_ARABIC,
- eCharset_BALTIC,
- eCharset_THAI,
- eCharset_SHIFTJIS,
- eCharset_GB2312,
- eCharset_HANGEUL,
- eCharset_CHINESEBIG5,
- eCharset_JOHAB,
- eCharset_COUNT
-};
-
-struct nsCharsetInfo
-{
- char* mName;
-/* USHORT mMask; */
- PRUint16 mCodePage;
- char* mLangGroup;
-};
-
-static nsCharsetInfo gCharsetInfo[eCharset_COUNT] =
-{
- { "DEFAULT", /* 0, */ 0, "" },
- { "ANSI", /* FM_DEFN_LATIN1, */ 1252, "x-western" },
- { "EASTEUROPE", /* FM_DEFN_LATIN2, */ 1250, "x-central-euro" },
- { "RUSSIAN", /* FM_DEFN_CYRILLIC, */ 1251, "x-cyrillic" },
- { "GREEK", /* FM_DEFN_GREEK, */ 813, "el" },
- { "TURKISH", /* 0, */ 1254, "tr" },
- { "HEBREW", /* FM_DEFN_HEBREW, */ 1208, "he" },
- { "ARABIC", /* FM_DEFN_ARABIC, */ 864, "ar" },
- { "BALTIC", /* 0, */ 1257, "x-baltic" },
- { "THAI", /* FM_DEFN_THAI, */ 874, "th" },
- { "SHIFTJIS", /* FM_DEFN_KANA, */ 932, "ja" },
- { "GB2312", /* FM_DEFN_KANA, */ 1381, "zh-CN" },
- { "HANGEUL", /* FM_DEFN_KANA, */ 949, "ko" },
- { "CHINESEBIG5", /* FM_DEFN_KANA, */ 950, "zh-TW" },
- { "JOHAB", /* FM_DEFN_KANA, */ 1361, "ko-XXX", }
-};
-
-
-/**********************************************************
- nsFontMetricsOS2
- **********************************************************/
-
-static void
-FreeGlobals(void)
-{
- gInitialized = 0;
-
- NS_IF_RELEASE(gPref);
- NS_IF_RELEASE(gUsersLocale);
- NS_IF_RELEASE(gSystemLocale);
- NS_IF_RELEASE(gUserDefined);
-#ifdef USE_FREETYPE
- if (nsFontMetricsOS2::gUseFTFunctions) {
- // disable the freetype engine
- nsFontMetricsOS2FT::pfnFt2EnableFontEngine(FALSE);
-
- NS_IF_RELEASE(gJA);
- NS_IF_RELEASE(gKO);
- NS_IF_RELEASE(gZHTW);
- NS_IF_RELEASE(gZHCN);
- NS_IF_RELEASE(gZHHK);
- }
-#endif /* use_freetype */
-
- if (nsFontMetricsOS2::gGlobalFonts) {
- nsFontMetricsOS2::gGlobalFonts->Clear();
- delete nsFontMetricsOS2::gGlobalFonts;
- nsFontMetricsOS2::gGlobalFonts = nsnull;
- }
-
- if (nsFontMetricsOS2::gFamilyNames) {
- PL_HashTableDestroy(nsFontMetricsOS2::gFamilyNames);
- nsFontMetricsOS2::gFamilyNames = nsnull;
- }
-}
-
-class nsFontCleanupObserver : public nsIObserver {
-public:
- NS_DECL_ISUPPORTS
- NS_DECL_NSIOBSERVER
-
- nsFontCleanupObserver() { }
- virtual ~nsFontCleanupObserver() {}
-};
-
-NS_IMPL_ISUPPORTS1(nsFontCleanupObserver, nsIObserver)
-
-NS_IMETHODIMP nsFontCleanupObserver::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData)
-{
- if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
- FreeGlobals();
- }
- return NS_OK;
-}
-
-static nsFontCleanupObserver *gFontCleanupObserver;
-
-static nsresult
-InitGlobals(void)
-{
- CallGetService(NS_PREF_CONTRACTID, &gPref);
- if (!gPref) {
- FreeGlobals();
- return NS_ERROR_FAILURE;
- }
-
- nsCOMPtr<nsILanguageAtomService> langService;
- langService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID);
- if (langService) {
- NS_IF_ADDREF(gUsersLocale = langService->GetLocaleLanguageGroup());
- }
- if (!gUsersLocale) {
- gUsersLocale = NS_NewAtom("x-western");
- }
- if (!gUsersLocale) {
- FreeGlobals();
- return NS_ERROR_OUT_OF_MEMORY;
- }
-
- UINT cp = ::WinQueryCp(HMQ_CURRENT);
- for (int i = 1; i < eCharset_COUNT; ++i) {
- if (gCharsetInfo[i].mCodePage == cp) {
- gSystemLocale = NS_NewAtom(gCharsetInfo[i].mLangGroup);
- break;
- }
- }
- if (!gSystemLocale) {
- gSystemLocale = gUsersLocale;
- NS_ADDREF(gSystemLocale);
- }
-
- gUserDefined = NS_NewAtom(USER_DEFINED);
- if (!gUserDefined) {
- FreeGlobals();
- return NS_ERROR_OUT_OF_MEMORY;
- }
-#ifdef USE_FREETYPE
- if (nsFontMetricsOS2::gUseFTFunctions) {
- // enable the freetype engine
- nsFontMetricsOS2FT::pfnFt2EnableFontEngine(TRUE);
-
- gJA = NS_NewAtom("ja");
- if (!gJA) {
- FreeGlobals();
- return NS_ERROR_OUT_OF_MEMORY;
- }
- gKO = NS_NewAtom("ko");
- if (!gKO) {
- FreeGlobals();
- return NS_ERROR_OUT_OF_MEMORY;
- }
- gZHCN = NS_NewAtom("zh-CN");
- if (!gZHCN) {
- FreeGlobals();
- return NS_ERROR_OUT_OF_MEMORY;
- }
- gZHTW = NS_NewAtom("zh-TW");
- if (!gZHTW) {
- FreeGlobals();
- return NS_ERROR_OUT_OF_MEMORY;
- }
- gZHHK = NS_NewAtom("zh-HK");
- if (!gZHHK) {
- FreeGlobals();
- return NS_ERROR_OUT_OF_MEMORY;
- }
- }
-#endif /* use_freetype */
-
- // Not all versions of OS/2 support the 1386 and 943 codepages, so by default
- // we use 1381 and 932 (see the declaration of gCharsetInfo above).
- // Here, we check to see if the OS supports the newer codepages, and if so,
- // use them.
- ULONG numCP = ::WinQueryCpList((HAB)0, 0, NULL);
- if (numCP > 0) {
- ULONG * pCPList = (ULONG*)nsMemory::Alloc(numCP*sizeof(ULONG));
- if (::WinQueryCpList((HAB)0, numCP, pCPList)) {
- for (PRUint32 i = 0; i < numCP; i++) {
- if (pCPList[i] == 1386) {
- gCharsetInfo[11].mCodePage = 1386;
- } else if (pCPList[i] == 943) {
- gCharsetInfo[10].mCodePage = 943;
- }
- }
- }
- nsMemory::Free(pCPList);
- }
-
- gSystemCodePage = ::WinQueryCp(HMQ_CURRENT);
-
- nsresult res;
-
- if (!nsFontMetricsOS2::gGlobalFonts) {
- res = nsFontMetricsOS2::InitializeGlobalFonts();
- if (NS_FAILED(res)) {
- FreeGlobals();
- return res;
- }
- }
-
- res = gPref->GetBoolPref("browser.display.substitute_vector_fonts",
- &nsFontMetricsOS2::gSubstituteVectorFonts);
- NS_ASSERTION( NS_SUCCEEDED(res), "Could not get pref 'browser.display.substitute_vector_fonts'" );
-
- //register an observer to take care of cleanup
- gFontCleanupObserver = new nsFontCleanupObserver();
- NS_ASSERTION(gFontCleanupObserver, "failed to create observer");
- if (gFontCleanupObserver) {
- // register for shutdown
- nsresult rv;
- nsCOMPtr<nsIObserverService> observerService(do_GetService("@mozilla.org/observer-service;1", &rv));
- if (NS_SUCCEEDED(rv)) {
- rv = observerService->AddObserver(gFontCleanupObserver, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
- }
- }
- gInitialized = 1;
-
- return NS_OK;
-}
-
-#ifdef DEBUG_FONT_STRUCT_ALLOCS
-unsigned long nsFontMetricsOS2::mRefCount = 0;
-#endif
-
-nsFontMetricsOS2::nsFontMetricsOS2()
-{
-#ifdef DEBUG_FONT_STRUCT_ALLOCS
- mRefCount++;
- printf("+++ nsFontMetricsOS2 total = %d\n", mRefCount);
-#endif
-}
-
-nsFontMetricsOS2::~nsFontMetricsOS2()
-{
- mFontHandle = nsnull; // released below
- mUnicodeFont = nsnull; // release below
- mWesternFont = nsnull; // release below
-
- for (PRInt32 i = mLoadedFonts.Count()-1; i >= 0; --i) {
- delete (nsFontOS2*)mLoadedFonts[i];
- }
- mLoadedFonts.Clear();
-
- if (mDeviceContext) {
- // Notify our device context that owns us so that it can update its font cache
- mDeviceContext->FontMetricsDeleted(this);
- mDeviceContext = nsnull;
- }
-#ifdef DEBUG_FONT_STRUCT_ALLOCS
- mRefCount--;
- printf("--- nsFontMetricsOS2 total = %d\n", mRefCount);
-#endif
-}
-
-NS_IMPL_ISUPPORTS1(nsFontMetricsOS2, nsIFontMetrics)
-
-NS_IMETHODIMP
-nsFontMetricsOS2::Init( const nsFont &aFont, nsIAtom* aLangGroup,
- nsIDeviceContext *aContext)
-{
- nsresult res;
- if (!gInitialized) {
- res = InitGlobals();
- if (NS_FAILED(res)) {
- return res;
- }
- }
-
- mFont = aFont;
- mLangGroup = aLangGroup;
-
- //don't addref this to avoid circular refs
- mDeviceContext = (nsDeviceContextOS2 *) aContext;
- return RealizeFont();
-}
-
-NS_IMETHODIMP
-nsFontMetricsOS2::Destroy()
-{
- mDeviceContext = nsnull;
- return NS_OK;
-}
-
-// Utility; delete [] when done.
-static FONTMETRICS* getMetrics( long &lFonts, PCSZ facename, HPS hps)
-{
- LONG lWant = 0;
- lFonts = GFX (::GpiQueryFonts(hps, QF_PUBLIC | QF_PRIVATE,
- facename, &lWant, 0, 0),
- GPI_ALTERROR);
- if (!lFonts) {
- return NULL;
- }
- FONTMETRICS* pMetrics = (FONTMETRICS*)nsMemory::Alloc(lFonts * sizeof(FONTMETRICS));
-
- GFX (::GpiQueryFonts(hps, QF_PUBLIC | QF_PRIVATE, facename,
- &lFonts, sizeof (FONTMETRICS), pMetrics),
- GPI_ALTERROR);
-
- return pMetrics;
-}
-
-/* For a vector font, we create a charbox based directly on mFont.size, so
- * we don't need to calculate anything here. For image fonts, though, we
- * want to find the closest match for the given mFont.size.
- */
-nsFontOS2*
-nsFontMetricsOS2::SetFontHandle(HPS aPS, GlobalFontEntry* aEntry,
- nsMiniMetrics* aMetrics, PRBool aDoFakeEffects)
-{
- nsFontOS2* font;
-#ifdef USE_FREETYPE
- if (gUseFTFunctions) {
- font = new nsFontOS2FT();
- } else
-#endif
- {
- font = new nsFontOS2();
- }
-
- strcpy(font->mFattrs.szFacename, aMetrics->szFacename);
- if (aMetrics->fsDefn & FM_DEFN_OUTLINE ||
- !mDeviceContext->SupportsRasterFonts()) {
- font->mFattrs.fsFontUse = FATTR_FONTUSE_OUTLINE |
- FATTR_FONTUSE_TRANSFORMABLE;
- }
- if (aMetrics->fsType & FM_TYPE_MBCS)
- font->mFattrs.fsType |= FATTR_TYPE_MBCS;
- if (aMetrics->fsType & FM_TYPE_DBCS)
- font->mFattrs.fsType |= FATTR_TYPE_DBCS;
-
- if (aDoFakeEffects) {
- // fake the effects
- if (mFont.weight > NS_FONT_WEIGHT_NORMAL)
- font->mFattrs.fsSelection |= FATTR_SEL_BOLD;
- if (mFont.style & (NS_FONT_STYLE_ITALIC | NS_FONT_STYLE_OBLIQUE))
- font->mFattrs.fsSelection |= FATTR_SEL_ITALIC;
- }
-
-#ifdef USE_FREETYPE
- // We only want to set the codepage in the freetype case if the codepage for
- // the font is 65400 (a symbol font).
- if (!gUseFTFunctions || aEntry->mCodePage == 65400)
-#endif
- font->mFattrs.usCodePage = aEntry->mCodePage;
-
-#ifdef PERF_HASGLYPH_CHAR_MAP
- if (gUseFTFunctions) {
- if (aEntry->mHaveCheckedCharMap == nsnull) {
- aEntry->mHaveCheckedCharMap = (PRUint32*)calloc(UCS2_MAP_LEN, sizeof(PRUint32));
- aEntry->mRepresentableCharMap = (PRUint32*)calloc(UCS2_MAP_LEN, sizeof(PRUint32));
- }
- font->mHaveCheckedCharMap = aEntry->mHaveCheckedCharMap;
- font->mRepresentableCharMap = aEntry->mRepresentableCharMap;
- }
-#endif
-
- float app2dev, reqEmHeight;
- app2dev = mDeviceContext->AppUnitsToDevUnits();
- reqEmHeight = mFont.size * app2dev;
-
- FATTRS* fattrs = &(font->mFattrs);
- if (fattrs->fsFontUse == 0) // if image font
- {
- long lFonts = 0;
- FONTMETRICS* pMetrics = getMetrics( lFonts, fattrs->szFacename, aPS);
-
- int reqPointSize = NSTwipsToIntPoints(mFont.size);
- int browserRes = mDeviceContext->GetDPI();
-
- int minSize = 99, maxSize = 0, curEmHeight = 0;
- for (int i = 0; i < lFonts; i++)
- {
- // If we are asked for a specific point size for which we have an
- // appropriate font, use it. This avoids us choosing an incorrect
- // size due to rounding issues
- if (pMetrics[i].sYDeviceRes == browserRes &&
- pMetrics[i].sNominalPointSize / 10 == reqPointSize)
- {
- // image face found fine, set required size in fattrs.
- curEmHeight = pMetrics[i].lEmHeight;
- fattrs->lMaxBaselineExt = pMetrics[i].lMaxBaselineExt;
- fattrs->lAveCharWidth = pMetrics[i].lAveCharWidth;
- minSize = maxSize = pMetrics[i].lEmHeight;
- break;
- }
- else
- {
- if (fabs(pMetrics[i].lEmHeight - reqEmHeight) <
- fabs(curEmHeight - reqEmHeight))
- {
- curEmHeight = pMetrics[i].lEmHeight;
- fattrs->lMaxBaselineExt = pMetrics[i].lMaxBaselineExt;
- fattrs->lAveCharWidth = pMetrics[i].lAveCharWidth;
- }
- else if (fabs(pMetrics[i].lEmHeight - reqEmHeight) ==
- fabs(curEmHeight - reqEmHeight))
- {
- if ((pMetrics[i].lEmHeight) > curEmHeight)
- {
- curEmHeight = pMetrics[i].lEmHeight;
- fattrs->lMaxBaselineExt = pMetrics[i].lMaxBaselineExt;
- fattrs->lAveCharWidth = pMetrics[i].lAveCharWidth;
- }
- }
- }
-
- // record the min/max point size available for given font
- if (pMetrics[i].lEmHeight > maxSize)
- maxSize = pMetrics[i].lEmHeight;
- if (pMetrics[i].lEmHeight < minSize)
- minSize = pMetrics[i].lEmHeight;
- }
-
- nsMemory::Free(pMetrics);
-
- // Enable font substitution if the requested size is outside of the range
- // of available sizes by more than 3
- if (reqEmHeight < minSize - 3 ||
- reqEmHeight > maxSize + 3)
- {
- // If the browser.display.substitute_vector_fonts pref is set, then we
- // exchange Times New Roman for Tms Rmn and Helvetica for Helv if the
- // requested points size is less than the minimum or more than the
- // maximum point size available for Tms Rmn and Helv.
- nsAutoString alias;
- if (gSubstituteVectorFonts &&
- GetVectorSubstitute(aPS, aEntry->GetKey(), alias))
- {
- strcpy(fattrs->szFacename, NS_LossyConvertUTF16toASCII(alias).get());
- fattrs->fsFontUse = FATTR_FONTUSE_OUTLINE | FATTR_FONTUSE_TRANSFORMABLE;
- fattrs->fsSelection &= ~(FM_SEL_BOLD | FM_SEL_ITALIC);
- }
- }
-
- if (fattrs->fsFontUse == 0) { // if still image font
- reqEmHeight = curEmHeight;
- }
- }
-
- // Add effects
- if (mFont.decorations & NS_FONT_DECORATION_UNDERLINE) {
- fattrs->fsSelection |= FATTR_SEL_UNDERSCORE;
- }
- if (mFont.decorations & NS_FONT_DECORATION_LINE_THROUGH) {
- fattrs->fsSelection |= FATTR_SEL_STRIKEOUT;
- }
-
-#ifdef USE_FREETYPE
- if (!gUseFTFunctions)
-#endif
- {
- // Encoding:
- // There doesn't seem to be any encoding stuff yet, so guess.
- // (XXX unicode hack; use same codepage as converter!)
- const char* langGroup;
- mLangGroup->GetUTF8String(&langGroup);
- for (int j=0; j < eCharset_COUNT; j++)
- {
- if (langGroup[0] == gCharsetInfo[j].mLangGroup[0])
- {
- if (!strcmp(langGroup, gCharsetInfo[j].mLangGroup))
- {
- mConvertCodePage = gCharsetInfo[j].mCodePage;
- break;
- }
- }
- }
-
- // Symbols fonts must be created with codepage 65400,
- // so use 65400 for the fattrs codepage. We still do
- // conversions with the charset codepage
- if (fattrs->usCodePage != 65400) {
- fattrs->usCodePage = mConvertCodePage;
- }
- }
-
- // set up the charbox; set for image fonts also, in case we need to
- // substitute a vector font later on (for UTF-8, etc)
- long lFloor = NSToIntFloor(reqEmHeight);
- font->mCharbox.cx = MAKEFIXED(lFloor, (reqEmHeight - (float)lFloor) * 65536.0f);
- font->mCharbox.cy = font->mCharbox.cx;
-
- return font;
-}
-
-/* aName is a font family name. see if fonts of that family exist
- * if so, return font structure with family name
- */
-nsFontOS2*
-nsFontMetricsOS2::LoadFont(HPS aPS, const nsAString& aFontname)
-{
- nsFontOS2* font = nsnull;
-
- // set style flags
- PRBool bBold = mFont.weight > NS_FONT_WEIGHT_NORMAL;
- PRBool bItalic = (mFont.style & (NS_FONT_STYLE_ITALIC | NS_FONT_STYLE_OBLIQUE));
- USHORT flags = bBold ? FM_SEL_BOLD : 0;
- flags |= bItalic ? FM_SEL_ITALIC : 0;
-
- // always pass vector fonts to the printer
- nsAutoString fontptr;
- if (mDeviceContext->SupportsRasterFonts() ||
- !GetVectorSubstitute(aPS, aFontname, fontptr))
- {
- fontptr = aFontname;
- }
-
- GlobalFontEntry* globalEntry = gGlobalFonts->GetEntry(fontptr);
- if (globalEntry) {
- nsMiniMetrics* metrics = globalEntry->mMetrics;
- nsMiniMetrics* plainFont = nsnull;
- while (metrics) {
- if ((metrics->fsSelection & (FM_SEL_ITALIC | FM_SEL_BOLD)) == flags) {
- font = SetFontHandle(aPS, globalEntry, metrics, PR_FALSE);
- break;
- }
-
- // Save ref to 'plain' font (non-bold, non-italic)
- if (!plainFont && !(metrics->fsSelection & (FM_SEL_ITALIC | FM_SEL_BOLD)))
- plainFont = metrics;
-
- metrics = metrics->mNext;
- }
-
- // A font of family "familyname" and with the applied effects (bold &
- // italic) was not found. Therefore, just look for a 'regular' font
- // (that is not italic and not bold), and then have the
- // system simulate the appropriate effects (see RealizeFont()).
- if (!font && plainFont) {
- font = SetFontHandle(aPS, globalEntry, plainFont, PR_TRUE);
- }
- }
-
- if (!font) {
- // If a font was not found, then maybe "familyname" is really a face name.
- // See if a font with that facename exists on system and load the font.
- long lFonts = 0;
- nsAutoCharBuffer facename;
- PRInt32 len;
- WideCharToMultiByte(0, PromiseFlatString(aFontname).get(),
- aFontname.Length(), facename, len);
- FONTMETRICS* pMetrics = getMetrics(lFonts, facename.get(), aPS);
-
- if (lFonts > 0) {
- nsAutoChar16Buffer familyname;
- MultiByteToWideChar(0, pMetrics[0].szFamilyname,
- strlen(pMetrics[0].szFamilyname), familyname, len);
- nsAutoString name(familyname.get());
- GlobalFontEntry* globalEntry = gGlobalFonts->GetEntry(name);
- if (globalEntry) {
- // Look through metrics for one that matches given facename
- nsMiniMetrics* metrics = globalEntry->mMetrics;
- while (metrics) {
- if (stricmp(metrics->szFacename, facename.get()) == 0) {
- font = SetFontHandle(aPS, globalEntry, metrics, PR_TRUE);
- break;
- }
- metrics = metrics->mNext;
- }
- }
- }
- nsMemory::Free(pMetrics);
- }
-
- if (font) {
- mLoadedFonts.AppendElement(font);
- }
-
- return font;
-}
-
-typedef struct nsFontFamilyName
-{
- char* mName;
- char* mWinName;
-} nsFontFamilyName;
-
-static nsFontFamilyName gBadDBCSFontMapping[] =
-{
- { "\xB7\xC2\xCB\xCE\xB3\xA3\xB9\xE6", "IBM Fang Song SC"},
- { "\xBA\xDA\xCC\xE5\xB3\xA3\xB9\xE6", "IBM Hei SC"},
- { "\xBF\xAC\xCC\xE5\xB3\xA3\xB9\xE6", "IBM Kai SC"},
- { "\x5B\x8B\x4F\x53\x5E\x38\x89\xC4", "IBM Song SC"},
- { "\x91\x76\x91\xCC\x8F\xED", "IBM Song SC"},
-
- { "@\xB7\xC2\xCB\xCE\xB3\xA3\xB9\xE6", "@IBM Fang Song SC"},
- { "@\xBA\xDA\xCC\xE5\xB3\xA3\xB9\xE6", "@IBM Hei SC"},
- { "@\xBF\xAC\xCC\xE5\xB3\xA3\xB9\xE6", "@IBM Kai SC"},
- { "@\x5B\x8B\x4F\x53\x5E\x38\x89\xC4", "@IBM Song SC"},
- { "@\x91\x76\x91\xCC\x8F\xED", "@IBM Song SC"},
-
- { "\xAC\xD1\xFA\x80\xFA\xBD\x8F\x82", "MOEKai TC"},
- { "\xBC\xD0\xB7\xC7\xB7\xA2\xC5\xE9", "MOEKai TC"},
- { "\xAC\xD1\xFA\x80\x15\xA7\x8F\x82", "MOESung TC"},
- { "\xBC\xD0\xB7\xC7\xA7\xBA\xC5\xE9", "MOESung TC"},
- { "\xCF\xCF\x14\xB6\x8F\x82", "Hei TC"},
- { "\xA4\xA4\xB6\xC2\xC5\xE9", "Hei TC"},
-
- { "@\xAC\xD1\xFA\x80\xFA\xBD\x8F\x82", "@MOEKai TC"},
- { "@\xBC\xD0\xB7\xC7\xB7\xA2\xC5\xE9", "@MOEKai TC"},
- { "@\xAC\xD1\xFA\x80\x15\xA7\x8F\x82", "@MOESong TC"},
- { "@\xBC\xD0\xB7\xC7\xA7\xBA\xC5\xE9", "@MOESong TC"},
- { "@\xCF\xCF\x14\xB6\x8F\x82", "@Hei TC"},
- { "@\xA4\xA4\xB6\xC2\xC5\xE9", "@Hei TC"},
- { nsnull, nsnull }
-};
-
-#ifdef DEBUG
-PR_STATIC_CALLBACK(PLDHashOperator)
-DebugOutputEnumFunc(GlobalFontEntry* aEntry, void* aData)
-{
- printf("---------------------------------------------------------------------\n");
- printf(" [[]] %s\n", NS_LossyConvertUTF16toASCII(aEntry->GetKey()).get());
- nsMiniMetrics* metrics = aEntry->mMetrics;
- while (metrics) {
- printf(" %32s", metrics->szFacename);
-
- if (metrics->fsDefn & FM_DEFN_OUTLINE)
- printf(" : vector");
- else
- printf(" : bitmap");
-
- if (metrics->fsSelection & FM_SEL_BOLD)
- printf(" : bold");
- else
- printf(" : ");
-
- if (metrics->fsSelection & FM_SEL_ITALIC)
- printf(" : italic");
- else
- printf(" : ");
-
- if (metrics->fsType & FM_TYPE_DBCS ||
- metrics->fsType & FM_TYPE_MBCS)
- printf(" : M/DBCS");
- else
- printf(" : ");
-
- printf(" : cp=%5d\n", aEntry->mCodePage );
-
- metrics = metrics->mNext;
- }
-
- return PL_DHASH_NEXT;
-}
-#endif
-
-nsresult
-nsFontMetricsOS2::InitializeGlobalFonts()
-{
- gGlobalFonts = new nsTHashtable<GlobalFontEntry>;
- if (!gGlobalFonts->Init(64))
- return NS_ERROR_OUT_OF_MEMORY;
-
- HPS ps = ::WinGetScreenPS(HWND_DESKTOP);
- LONG lRemFonts = 0, lNumFonts;
- lNumFonts = GFX (::GpiQueryFonts(ps, QF_PUBLIC, NULL, &lRemFonts, 0, 0),
- GPI_ALTERROR);
- FONTMETRICS* pFontMetrics = (PFONTMETRICS) nsMemory::Alloc(lNumFonts * sizeof(FONTMETRICS));
- lRemFonts = GFX (::GpiQueryFonts(ps, QF_PUBLIC, NULL, &lNumFonts,
- sizeof (FONTMETRICS), pFontMetrics),
- GPI_ALTERROR);
- ::WinReleasePS(ps);
-
- for (int i = 0; i < lNumFonts; i++) {
- FONTMETRICS* font = &(pFontMetrics[i]);
-
- // The discrepencies between the Courier bitmap and outline fonts are
- // too much to deal with, so we only use the outline font
- if (strcmp(font->szFamilyname, "Courier") == 0 &&
- !(font->fsDefn & FM_DEFN_OUTLINE)) {
- continue;
- }
-
- // The facenames for Roman are "Tms Rmn...", for Swiss "Helv...". This
- // conflicts with the actual "Tms Rmn" and "Helv" font families. So, we
- // skip over these.
- if (strcmp(pFontMetrics[i].szFamilyname, "Roman") == 0 ||
- strcmp(pFontMetrics[i].szFamilyname, "Swiss") == 0) {
- continue;
- }
-
- // Problem: OS/2 has many non-standard fonts that do not follow the
- // normal Family-name/Face-name conventions (i.e. 'foo',
- // 'foo bold', 'foo italic', 'foo bold italic'). This is
- // especially true for DBCS fonts (i.e. the 'WarpSans' family
- // can contain the 'WarpSans', 'WarpSans Bold', and 'WarpSans
- // Combined' faces).
- // Solution: Unfortunately, there is no perfect way to handle this. After
- // many attempts, we will attempt to remedy the situation by
- // searching the Facename for certain indicators ('bold',
- // 'italic', 'oblique', 'regular'). If the Facename contains
- // one of these indicators, then we will create the sort key
- // based on the Familyname. Otherwise, use the Facename.
- char* f;
- if (PL_strcasestr(font->szFacename, "bold") != nsnull ||
- PL_strcasestr(font->szFacename, "italic") != nsnull ||
- PL_strcasestr(font->szFacename, "oblique") != nsnull ||
- PL_strcasestr(font->szFacename, "regular") != nsnull ||
- PL_strcasestr(font->szFacename, "-normal") != nsnull)
- {
- f = static_cast<char*>(font->szFamilyname);
- } else {
- f = static_cast<char*>(font->szFacename);
- }
- nsAutoChar16Buffer fontname;
- PRInt32 len;
- MultiByteToWideChar(0, f, strlen(f), fontname, len);
- nsAutoString fontptr(fontname.get());
-
- // The fonts in gBadDBCSFontMapping do not display well in non-Chinese
- // systems. Map them to a more intelligible name.
- if (font->fsType & FM_TYPE_DBCS)
- {
- if ((gSystemCodePage != 1386) &&
- (gSystemCodePage != 1381) &&
- (gSystemCodePage != 950))
- {
- for (int i = 0; gBadDBCSFontMapping[i].mName != nsnull; i++) {
- if (strcmp(f, gBadDBCSFontMapping[i].mName) == 0)
- {
- CopyASCIItoUTF16(nsDependentCString(gBadDBCSFontMapping[i].mWinName),
- fontptr);
- break;
- }
- }
- }
- }
-
- // Create entry for family name, or retrieve already created entry
- GlobalFontEntry* globalEntry = gGlobalFonts->PutEntry(fontptr);
- if (!globalEntry)
- return NS_ERROR_OUT_OF_MEMORY;
-
- // Init the nsMiniMetrics structure...
- nsMiniMetrics* metrics = new nsMiniMetrics;
- strcpy(metrics->szFacename, font->szFacename);
- metrics->fsType = font->fsType;
- metrics->fsDefn = font->fsDefn;
- metrics->fsSelection = font->fsSelection;
- // Set the FM_SEL_BOLD flag in fsSelection. This makes the check for
- // bold and italic much easier in LoadFont
- if (font->usWeightClass > 5)
- metrics->fsSelection |= FM_SEL_BOLD;
-
- // The 'Lucida' set of fonts does not set the bold flag correctly on OS/2,
- // so we'll just set it properly.
- if (strncmp(font->szFamilyname, "Lucida", 6) == 0 &&
- PL_strcasestr(font->szFacename, "bold") != nsnull) {
- metrics->fsSelection |= FM_SEL_BOLD;
- }
-
- // ... and add it to globalEntry
- metrics->mNext = globalEntry->mMetrics;
- globalEntry->mMetrics = metrics;
- globalEntry->mCodePage = font->usCodePage;
- }
-
-#ifdef DEBUG_pedemonte
- gGlobalFonts->EnumerateEntries(DebugOutputEnumFunc, nsnull);
- fflush(stdout);
-#endif
-
- nsMemory::Free(pFontMetrics);
-
- return NS_OK;
-}
-
-nsFontOS2*
-nsFontMetricsOS2::FindGlobalFont(HPS aPS, PRUint32 aChar)
-{
- nsFontOS2* fh = nsnull;
- nsAutoString fontname;
- if (!IsDBCS())
- fontname.AssignLiteral("Helv");
- else
- fontname.AssignLiteral("Helv Combined");
- fh = LoadFont(aPS, fontname);
- NS_ASSERTION(fh, "Couldn't load default font - BAD things are happening");
- return fh;
-}
-
-nsFontOS2*
-nsFontMetricsOS2::FindUserDefinedFont(HPS aPS, PRUint32 aChar)
-{
- if (mIsUserDefined) {
- // the user-defined font is always loaded as the first font
- nsFontOS2* font = LoadFont(aPS, mUserDefined);
- mIsUserDefined = PR_FALSE;
- if (font && font->HasGlyph(aPS, aChar)) {
- return font;
- }
- }
- return nsnull;
-}
-
-static nsFontFamilyName gFamilyNameTable[] =
-{
-#ifdef MOZ_MATHML
- { "-moz-math-text", "Times New Roman" },
- { "-moz-math-symbol", "Symbol" },
-#endif
- { "times", "Times New Roman" },
- { "times roman", "Times New Roman" },
-
- { nsnull, nsnull }
-};
-
-static nsFontFamilyName gFamilyNameTableDBCS[] =
-{
-#ifdef MOZ_MATHML
- { "-moz-math-text", "Times New Roman" },
- { "-moz-math-symbol", "Symbol" },
-#endif
- { "times", "Times New Roman" },
- { "times roman", "Times New Roman" },
- { "warpsans", "WarpSans Combined" },
-
- { nsnull, nsnull }
-};
-
-/*-----------------------
-** Hash table allocation
-**----------------------*/
-static PLHashNumber PR_CALLBACK
-HashKey(const void* aString)
-{
- const nsString* str = (const nsString*)aString;
- return (PLHashNumber) nsCRT::HashCode(str->get());
-}
-
-static PRIntn PR_CALLBACK
-CompareKeys(const void* aStr1, const void* aStr2)
-{
- return nsCRT::strcmp(((const nsString*) aStr1)->get(),
- ((const nsString*) aStr2)->get()) == 0;
-}
-
-PR_STATIC_CALLBACK(void*) familyname_AllocTable(void *pool, size_t size)
-{
- return nsMemory::Alloc(size);
-}
-
-PR_STATIC_CALLBACK(void) familyname_FreeTable(void *pool, void *item)
-{
- nsMemory::Free(item);
-}
-
-PR_STATIC_CALLBACK(PLHashEntry*) familyname_AllocEntry(void *pool, const void *key)
-{
- return PR_NEW(PLHashEntry);
-}
-
-PR_STATIC_CALLBACK(void) familyname_FreeEntry(void *pool, PLHashEntry *he, PRUint32 flag)
-{
- delete (nsString *) (he->value);
-
- if (flag == HT_FREE_ENTRY) {
- delete (nsString *) (he->key);
- nsMemory::Free(he);
- }
-}
-
-PLHashAllocOps familyname_HashAllocOps = {
- familyname_AllocTable, familyname_FreeTable,
- familyname_AllocEntry, familyname_FreeEntry
-};
-
-PLHashTable*
-nsFontMetricsOS2::InitializeFamilyNames(void)
-{
- if (!gFamilyNames) {
- gFamilyNames = PL_NewHashTable( 0, HashKey, CompareKeys, nsnull,
- &familyname_HashAllocOps, nsnull );
- if (!gFamilyNames) {
- return nsnull;
- }
-
- nsFontFamilyName* f;
- if (!IsDBCS()) {
- f = gFamilyNameTable;
- } else {
- f = gFamilyNameTableDBCS;
- }
-
- while (f->mName) {
- nsString* name = new nsString;
- nsString* winName = new nsString;
- if (name && winName) {
- name->AssignWithConversion(f->mName);
- winName->AssignWithConversion(f->mWinName);
- if (PL_HashTableAdd(gFamilyNames, name, (void*) winName)) {
- ++f;
- continue;
- }
- }
- // if we reach here, no FamilyName was added to the hashtable
- if (name) delete name;
- if (winName) delete winName;
- return nsnull;
- }
- }
-
- return gFamilyNames;
-}
-
-nsFontOS2*
-nsFontMetricsOS2::FindLocalFont(HPS aPS, PRUint32 aChar)
-{
- if (!gFamilyNames) {
- if (!InitializeFamilyNames()) {
- return nsnull;
- }
- }
- while (mFontsIndex < mFonts.Count()) {
- if (mFontsIndex == mGenericIndex) {
- return nsnull;
- }
-
- nsString* name = mFonts.StringAt(mFontsIndex++);
- nsAutoString low(*name);
- ToLowerCase(low);
- nsString* winName = (nsString*) PL_HashTableLookup(gFamilyNames, &low);
- if (!winName) {
- winName = name;
- }
-#ifdef DEBUG_FONT_SELECTION
- printf(" FindLocalFont(): attempting to load %s\n",
- NS_LossyConvertUTF16toASCII(*winName).get());
-#endif
- nsFontOS2* font = LoadFont(aPS, *winName);
- if (font && font->HasGlyph(aPS, aChar)) {
- return font;
- }
- }
- return nsnull;
-}
-
-nsFontOS2*
-nsFontMetricsOS2::LoadGenericFont(HPS aPS, PRUint32 aChar, const nsAString& aName)
-{
- for (int i = mLoadedFonts.Count()-1; i >= 0; --i) {
- // woah, this seems bad
- const nsACString& fontName =
- nsDependentCString(((nsFontOS2*)mLoadedFonts[i])->mFattrs.szFacename);
- if (aName.Equals(NS_ConvertASCIItoUTF16(fontName),
- nsCaseInsensitiveStringComparator()))
- return nsnull;
-
- }
-#ifdef DEBUG_FONT_SELECTION
- printf(" LoadGenericFont(): attempting to load %s\n",
- NS_LossyConvertUTF16toASCII(aName).get());
-#endif
- nsFontOS2* font = LoadFont(aPS, aName);
- if (font && font->HasGlyph(aPS, aChar)) {
- return font;
- }
- return nsnull;
-}
-
-struct GenericFontEnumContext
-{
- HPS mPS; // IN
- PRUint32 mChar; // IN
- nsFontOS2 *mFont; // OUT
- nsFontMetricsOS2 *mMetrics; // IN
-};
-
-static PRBool
-GenericFontEnumCallback(const nsString& aFamily, PRBool aGeneric, void* aData)
-{
- GenericFontEnumContext* context = (GenericFontEnumContext*)aData;
- HPS ps = context->mPS;
- PRUint32 ch = context->mChar;
- nsFontMetricsOS2* metrics = context->mMetrics;
- context->mFont = metrics->LoadGenericFont(ps, ch, aFamily);
- if (context->mFont) {
- return PR_FALSE; // stop enumerating the list
- }
- return PR_TRUE; // don't stop
-}
-
-#define MAKE_FONT_PREF_KEY(_pref, _s0, _s1) \
- _pref.Assign(_s0); \
- _pref.Append(_s1);
-
-static void
-AppendGenericFontFromPref(nsString& aFontname,
- const char* aLangGroup,
- const char* aGeneric)
-{
- nsresult res;
- nsCAutoString pref;
- nsXPIDLString value;
- nsCAutoString generic_dot_langGroup;
-
- generic_dot_langGroup.Assign(aGeneric);
- generic_dot_langGroup.Append('.');
- generic_dot_langGroup.Append(aLangGroup);
-
- // font.name.[generic].[langGroup]
- // the current user' selected font, it gives the first preferred font
- MAKE_FONT_PREF_KEY(pref, "font.name.", generic_dot_langGroup);
- res = gPref->CopyUnicharPref(pref.get(), getter_Copies(value));
- if (NS_SUCCEEDED(res)) {
- if(!aFontname.IsEmpty())
- aFontname.Append((PRUnichar)',');
- aFontname.Append(value);
- }
-
- // font.name-list.[generic].[langGroup]
- // the pre-built list of default fonts, it gives alternative fonts
- MAKE_FONT_PREF_KEY(pref, "font.name-list.", generic_dot_langGroup);
- res = gPref->CopyUnicharPref(pref.get(), getter_Copies(value));
- if (NS_SUCCEEDED(res)) {
- if(!aFontname.IsEmpty())
- aFontname.Append((PRUnichar)',');
- aFontname.Append(value);
- }
-}
-
-nsFontOS2*
-nsFontMetricsOS2::FindGenericFont(HPS aPS, PRUint32 aChar)
-{
- if (mTriedAllGenerics) {
- // don't bother anymore because mLoadedFonts[] already has all our generic fonts
- return nsnull;
- }
-
- // This is a nifty hook that we will use to just iterate over
- // the list of names using the callback mechanism of nsFont...
- nsFont font("", 0, 0, 0, 0, 0);
-
- if (mLangGroup) {
- const char* langGroup;
- mLangGroup->GetUTF8String(&langGroup);
-
- // x-unicode pseudo-langGroup should be the last resort to turn to.
- // That is, it should be refered to only when we don't recognize
- // |langGroup| specified by the authors of documents and the
- // determination of |langGroup| based on Unicode range also fails
- // in |FindPrefFont|.
-
- if (!strcmp(langGroup, "x-unicode")) {
- mTriedAllGenerics = 1;
- return nsnull;
- }
-
- AppendGenericFontFromPref(font.name, langGroup,
- NS_ConvertUTF16toUTF8(mGeneric).get());
- }
-
- // Iterate over the list of names using the callback mechanism of nsFont...
- GenericFontEnumContext context = {aPS, aChar, nsnull, this};
- font.EnumerateFamilies(GenericFontEnumCallback, &context);
- if (context.mFont) { // a suitable font was found
- return context.mFont;
- }
-
- mTriedAllGenerics = 1;
- return nsnull;
-}
-
-nsFontOS2*
-nsFontMetricsOS2::FindPrefFont(HPS aPS, PRUint32 aChar)
-{
- if (mTriedAllPref) {
- // don't bother anymore because mLoadedFonts[] already has all our pref fonts
- return nsnull;
- }
- nsFont font("", 0, 0, 0, 0, 0);
- // Try the pref of the user's ui lang group
- // For example, if the ui language is Japanese, try pref from "ja"
- // Make localized build work better on other OS
- if (gUsersLocale != mLangGroup) {
- nsAutoString langGroup;
- gUsersLocale->ToString(langGroup);
- AppendGenericFontFromPref(font.name,
- NS_ConvertUTF16toUTF8(langGroup).get(),
- NS_ConvertUTF16toUTF8(mGeneric).get());
- }
- // Try the pref of the user's system lang group
- // For example, if the os language is Simplified Chinese,
- // try pref from "zh-CN"
- // Make English build work better on other OS
- if ((gSystemLocale != mLangGroup) && (gSystemLocale != gUsersLocale)) {
- nsAutoString langGroup;
- gSystemLocale->ToString(langGroup);
- AppendGenericFontFromPref(font.name,
- NS_ConvertUTF16toUTF8(langGroup).get(),
- NS_ConvertUTF16toUTF8(mGeneric).get());
- }
-
- // Also try all the default pref fonts enlisted from other languages
- for (int i = 1; i < eCharset_COUNT; ++i) {
- nsIAtom* langGroup = NS_NewAtom(gCharsetInfo[i].mLangGroup);
- if((gUsersLocale != langGroup) && (gSystemLocale != langGroup)) {
- AppendGenericFontFromPref(font.name, gCharsetInfo[i].mLangGroup,
- NS_ConvertUTF16toUTF8(mGeneric).get());
- }
- NS_IF_RELEASE(langGroup);
- }
- GenericFontEnumContext context = {aPS, aChar, nsnull, this};
- font.EnumerateFamilies(GenericFontEnumCallback, &context);
- if (context.mFont) { // a suitable font was found
- return context.mFont;
- }
- mTriedAllPref = 1;
- return nsnull;
-}
-
-// returns family name of font that can display given char
-nsFontOS2*
-nsFontMetricsOS2::FindFont(HPS aPS, PRUint32 aChar)
-{
- nsFontOS2* font = FindUserDefinedFont(aPS, aChar);
- if (!font) {
- font = FindLocalFont(aPS, aChar);
- if (!font) {
- font = FindGenericFont(aPS, aChar);
- if (!font) {
- font = FindPrefFont(aPS, aChar);
- if (!font) {
- font = FindGlobalFont(aPS, aChar);
-#ifdef USE_FREETYPE
- if (!font) {
- font = FindSubstituteFont(aPS, aChar);
- }
-#endif
- }
- }
- }
- }
-#ifdef DEBUG_FONT_SELECTION
- if (font) {
- printf(" FindFont(): found font %s for char 0x%04x\n",
- font->mFattrs.szFacename, aChar);
- }
-#endif
- return font;
-}
-
-static PRBool
-FontEnumCallback(const nsString& aFamily, PRBool aGeneric, void *aData)
-{
- nsFontMetricsOS2* metrics = (nsFontMetricsOS2*) aData;
-
-#ifdef USE_FREETYPE
- if (!nsFontMetricsOS2::gUseFTFunctions)
-#endif
- {
- /* Hack for Truetype on OS/2 - if it's Arial and not 1252 or 0, just get another font */
- if (aFamily.Find("Arial", IGNORE_CASE) != -1) {
- if (metrics->mConvertCodePage != 1252) {
- if ((metrics->mConvertCodePage == 0) &&
- (gSystemCodePage != 850) &&
- (gSystemCodePage != 437)) {
- return PR_TRUE; // don't stop
- }
- }
- }
- }
-
- metrics->mFonts.AppendString(aFamily);
- if (aGeneric) {
- metrics->mGeneric.Assign(aFamily);
- ToLowerCase(metrics->mGeneric);
- return PR_FALSE; // stop
- }
- ++metrics->mGenericIndex;
-
- return PR_TRUE; // don't stop
-}
-
-PRBool
-nsFontMetricsOS2::GetVectorSubstitute(HPS aPS, const nsAString& aFamilyname,
- nsAString& aAlias)
-{
- if (aFamilyname.EqualsLiteral("Tms Rmn")) {
- aAlias.AssignLiteral("Times New Roman");
- } else if (aFamilyname.EqualsLiteral("Helv")) {
- aAlias.AssignLiteral("Helvetica");
- }
-
- // When printing, substitute vector fonts for these common bitmap fonts
- if (!mDeviceContext->SupportsRasterFonts()) {
- if (aFamilyname.EqualsLiteral("System Proportional") ||
- aFamilyname.EqualsLiteral("WarpSans"))
- {
- aAlias.AssignLiteral("Helvetica");
- } else if (aFamilyname.EqualsLiteral("System Monospaced") ||
- aFamilyname.EqualsLiteral("System VIO"))
- {
- aAlias.AssignLiteral("Courier");
- }
- }
-
- if (aAlias.IsEmpty())
- return PR_FALSE;
- else
- return PR_TRUE;
-}
-
-nsresult
-nsFontMetricsOS2::RealizeFont()
-{
- nsresult rv;
- HPS ps = NULL;
-
- if (mDeviceContext->mPrintDC){
- ps = mDeviceContext->mPrintPS;
- } else {
- HWND win = (HWND)mDeviceContext->mWidget;
- ps = ::WinGetPS(win);
- if (!ps) {
- ps = ::WinGetPS(HWND_DESKTOP);
- }
- }
-
- mFont.EnumerateFamilies(FontEnumCallback, this);
-
- nsCAutoString pref;
- nsXPIDLString value;
-
- // set a fallback generic font if the font-family list didn't have one
- if (mGeneric.IsEmpty()) {
- const char* langGroup = nsnull;
- mLangGroup->GetUTF8String(&langGroup);
- pref.Assign("font.default.");
- pref.Append(langGroup);
- rv = gPref->CopyUnicharPref(pref.get(), getter_Copies(value));
- if (NS_SUCCEEDED(rv)) {
- mGeneric.Assign(value);
- }
- else {
- mGeneric.AssignLiteral("serif");
- }
- }
-
- if (mLangGroup.get() == gUserDefined) {
- // See if this is a special user-defined font encoding by checking:
- // font.name.[generic].x-user-def
- pref.Assign("font.name.");
- pref.AppendWithConversion(mGeneric);
- pref.Append(".x-user-def");
- rv = gPref->CopyUnicharPref(pref.get(), getter_Copies(value));
- if (NS_SUCCEEDED(rv)) {
- mUserDefined.Assign(value);
- mIsUserDefined = 1;
- }
- }
-
- nsFontOS2* font = FindFont(ps, 'a');
- NS_ASSERTION(font, "FindFont() returned null. THIS IS BAD!");
- if (!font) {
- if (mDeviceContext->mPrintDC == NULL) {
- ::WinReleasePS(ps);
- }
- return NS_ERROR_FAILURE;
- }
-
- font->mConvertCodePage = mConvertCodePage;
-
- // Record font handle & record various font metrics to cache
- mFontHandle = font;
- CHK_SUCCESS (::GpiCreateLogFont(ps, 0, 1, &(font->mFattrs)), FONT_MATCH);
- font->SelectIntoPS( ps, 1 );
-
- FONTMETRICS fm;
- GFX (::GpiQueryFontMetrics(ps, sizeof(fm), &fm), FALSE);
- /* Due to a bug in OS/2 MINCHO, need to cast lInternalLeading */
- fm.lInternalLeading = (signed short)fm.lInternalLeading;
-
- float dev2app;
- dev2app = mDeviceContext->DevUnitsToAppUnits();
-
- mMaxAscent = NSToCoordRound( (fm.lMaxAscender-1) * dev2app );
- mMaxDescent = NSToCoordRound( (fm.lMaxDescender+1) * dev2app );
- mFontHandle->mMaxAscent = mMaxAscent;
- mFontHandle->mMaxDescent = mMaxDescent;
-
- mInternalLeading = NSToCoordRound( fm.lInternalLeading * dev2app );
- mExternalLeading = NSToCoordRound( fm.lExternalLeading * dev2app );
-
- /* These two values aren't really used by mozilla */
- mEmAscent = mMaxAscent - mInternalLeading;
- mEmDescent = mMaxDescent;
-
- mMaxHeight = mMaxAscent + mMaxDescent;
- mEmHeight = mEmAscent + mEmDescent;
-
- mMaxAdvance = NSToCoordRound( fm.lMaxCharInc * dev2app );
- mXHeight = NSToCoordRound( fm.lXHeight * dev2app );
-
- nscoord onePixel = NSToCoordRound(1 * dev2app);
-
- // Not all fonts specify these two values correctly, and some not at all
- mSuperscriptYOffset = mXHeight;
- mSubscriptYOffset = NSToCoordRound( mXHeight / 3.0f );
-
- // Using lStrikeoutPosition puts the strikeout too high
- // Use 50% of lXHeight instead
- mStrikeoutPosition = NSToCoordRound( mXHeight / 2.0f);
- mStrikeoutSize = PR_MAX(onePixel, NSToCoordRound(fm.lStrikeoutSize * dev2app));
-
-#if 1
- // Can't trust the fonts to give us good results for the underline position
- // and size. This calculation, though, gives very good results.
- float height = fm.lMaxAscender + fm.lMaxDescender;
- mUnderlinePosition = -PR_MAX(onePixel, NSToIntRound(floor(0.1 * height + 0.5) * dev2app));
- mUnderlineSize = PR_MAX(onePixel, NSToIntRound(floor(0.05 * height + 0.5) * dev2app));
-#else
- mUnderlinePosition = -NSToCoordRound( fm.lUnderscorePosition * dev2app );
- mUnderlineSize = PR_MAX(onePixel, NSToCoordRound(fm.lUnderscoreSize * dev2app));
-#endif
-
- mAveCharWidth = PR_MAX(1, NSToCoordRound(fm.lAveCharWidth * dev2app));
-
- // Cache the width of a single space.
- SIZEL size;
- GetTextExtentPoint32(ps, " ", 1, &size);
- mSpaceWidth = NSToCoordRound(float(size.cx) * dev2app);
-
- // 10) Clean up
- GFX (::GpiSetCharSet (ps, LCID_DEFAULT), FALSE);
- GFX (::GpiDeleteSetId (ps, 1), FALSE);
- if (mDeviceContext->mPrintDC == NULL)
- ::WinReleasePS(ps);
-
- return NS_OK;
-}
-
-NS_IMETHODIMP nsFontMetricsOS2::GetSpaceWidth(nscoord &aSpaceWidth)
-{
- aSpaceWidth = mSpaceWidth;
- return NS_OK;
-}
-
-// Other metrics
-NS_IMETHODIMP nsFontMetricsOS2::GetXHeight( nscoord &aResult)
-{
- aResult = mXHeight;
- return NS_OK;
-}
-
-NS_IMETHODIMP nsFontMetricsOS2::GetSuperscriptOffset(nscoord& aResult)
-{
- aResult = mSuperscriptYOffset;
- return NS_OK;
-}
-
-NS_IMETHODIMP nsFontMetricsOS2::GetSubscriptOffset(nscoord& aResult)
-{
- aResult = mSubscriptYOffset;
- return NS_OK;
-}
-
-NS_IMETHODIMP nsFontMetricsOS2::GetStrikeout(nscoord& aOffset, nscoord& aSize)
-{
- aOffset = mStrikeoutPosition;
- aSize = mStrikeoutSize;
- return NS_OK;
-}
-
-NS_IMETHODIMP nsFontMetricsOS2::GetUnderline(nscoord& aOffset, nscoord& aSize)
-{
- aOffset = mUnderlinePosition;
- aSize = mUnderlineSize;
- return NS_OK;
-}
-
-NS_IMETHODIMP nsFontMetricsOS2::GetHeight( nscoord &aHeight)
-{
- aHeight = mMaxHeight;
- return NS_OK;
-}
-
-#ifdef FONT_LEADING_APIS_V2
-NS_IMETHODIMP
-nsFontMetricsOS2::GetInternalLeading(nscoord &aLeading)
-{
- aLeading = mInternalLeading;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsFontMetricsOS2::GetExternalLeading(nscoord &aLeading)
-{
- aLeading = mExternalLeading;
- return NS_OK;
-}
-#else
-NS_IMETHODIMP nsFontMetricsOS2::GetLeading( nscoord &aLeading)
-{
- aLeading = mInternalLeading;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsFontMetricsOS2::GetNormalLineHeight(nscoord &aHeight)
-{
- aHeight = mEmHeight + mInternalLeading;
- return NS_OK;
-}
-#endif //FONT_LEADING_APIS_V2
-
-NS_IMETHODIMP nsFontMetricsOS2::GetMaxAscent( nscoord &aAscent)
-{
- aAscent = mMaxAscent;
- return NS_OK;
-}
-
-NS_IMETHODIMP nsFontMetricsOS2::GetMaxDescent( nscoord &aDescent)
-{
- aDescent = mMaxDescent;
- return NS_OK;
-}
-
-NS_IMETHODIMP nsFontMetricsOS2::GetMaxAdvance( nscoord &aAdvance)
-{
- aAdvance = mMaxAdvance;
- return NS_OK;
-}
-
-NS_IMETHODIMP nsFontMetricsOS2::GetFontHandle( nsFontHandle &aHandle)
-{
- aHandle = mFontHandle;
- return NS_OK;
-}
-
-NS_IMETHODIMP nsFontMetricsOS2::GetLangGroup(nsIAtom** aLangGroup)
-{
- NS_ENSURE_ARG_POINTER(aLangGroup);
- *aLangGroup = mLangGroup;
- NS_IF_ADDREF(*aLangGroup);
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsFontMetricsOS2::GetEmHeight(nscoord &aHeight)
-{
- aHeight = mEmHeight;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsFontMetricsOS2::GetEmAscent(nscoord &aAscent)
-{
- aAscent = mEmAscent;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsFontMetricsOS2::GetEmDescent(nscoord &aDescent)
-{
- aDescent = mEmDescent;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsFontMetricsOS2::GetMaxHeight(nscoord &aHeight)
-{
- aHeight = mMaxHeight;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsFontMetricsOS2::GetAveCharWidth(nscoord &aAveCharWidth)
-{
- aAveCharWidth = mAveCharWidth;
- return NS_OK;
-}
-
-nsFontOS2*
-nsFontMetricsOS2::LoadUnicodeFont(HPS aPS, const nsAString& aName)
-{
-#ifdef DEBUG_FONT_SELECTION
- printf(" LoadUnicodeFont(): attempting to load %s\n",
- NS_LossyConvertUTF16toASCII(aName).get());
-#endif
- nsFontOS2* font = LoadFont(aPS, aName);
- if (font) {
- return font;
- }
- return nsnull;
-}
-
-struct UnicodeFontEnumContext
-{
- HPS mPS; // IN
- nsFontOS2* mFont; // OUT
- nsFontMetricsOS2* mMetrics; // IN
-};
-
-static PRBool
-UnicodeFontEnumCallback(const nsString& aFamily, PRBool aGeneric, void* aData)
-{
- UnicodeFontEnumContext* context = (UnicodeFontEnumContext*)aData;
- HPS ps = context->mPS;
- nsFontMetricsOS2* metrics = context->mMetrics;
- context->mFont = metrics->LoadUnicodeFont(ps, aFamily);
- if (context->mFont) {
- return PR_FALSE; // stop enumerating the list
- }
- return PR_TRUE; // don't stop
-}
-
-void
-nsFontMetricsOS2::FindUnicodeFont(HPS aPS)
-{
- nsresult res;
- nsCAutoString pref, generic;
- nsXPIDLString value;
-
- generic.Assign(NS_ConvertUTF16toUTF8(mGeneric));
-
- pref.Assign("font.name.");
- pref.Append(generic);
- pref.Append(".x-unicode");
-
- res = gPref->CopyUnicharPref(pref.get(), getter_Copies(value));
- if (NS_FAILED(res))
- return;
-
- nsAutoString fontname;
- fontname.Assign(value);
-
- nsFontOS2* fh = nsnull;
- fh = LoadUnicodeFont(aPS, fontname);
- if (!fh)
- {
- // User defined unicode font did not load. Fall back to font
- // specified in font.name-list.%.x-unicode
- pref.Assign("font.name-list.");
- pref.Append(generic);
- pref.Append(".x-unicode");
-
- res = gPref->CopyUnicharPref(pref.get(), getter_Copies(value));
- if (NS_FAILED(res))
- return;
-
- nsFont font("", 0, 0, 0, 0, 0);
- font.name.Assign(value);
-
- // Iterate over the list of names using the callback mechanism of nsFont
- UnicodeFontEnumContext context = {aPS, nsnull, this};
- font.EnumerateFamilies(UnicodeFontEnumCallback, &context);
- fh = context.mFont;
- }
-
- if (fh) { // a suitable font was found
- fh->mFattrs.usCodePage = 1208;
- fh->mConvertCodePage = 1208;
- mUnicodeFont = fh;
-#ifdef DEBUG_FONT_SELECTION
- printf(" FindUnicodeFont(): found new Unicode font %s\n",
- mUnicodeFont->mFattrs.szFacename);
-#endif
- } else {
- NS_ERROR("Could not find a Unicode font");
- }
- return;
-}
-
-void
-nsFontMetricsOS2::FindWesternFont()
-{
- // Create a 'western' font by making a copy of the currently selected font
- // and changing the codepage 1252
- nsFontOS2* font = new nsFontOS2();
- font->mFattrs = mFontHandle->mFattrs;
- font->mFattrs.usCodePage = 1252;
- font->mCharbox = mFontHandle->mCharbox;
- font->mMaxAscent = mFontHandle->mMaxAscent;
- font->mMaxDescent = mFontHandle->mMaxDescent;
- font->mConvertCodePage = 1252;
- mLoadedFonts.AppendElement(font);
- mWesternFont = font;
-}
-
-#define IS_SPECIAL_WO_ELLIPSE(x) \
- ((x == 0x20AC) || /* euro */ \
- (x == 0x2022) || /* bull */ \
- (x == 0x201C) || /* ldquo */ \
- (x == 0x201D) || /* rdquo */ \
- (x == 0x2018) || /* lsquo */ \
- (x == 0x2019) || /* rsquo */ \
- (x == 0x2013) || /* ndash */ \
- (x == 0x2014)) /* mdash */
-
-#define IS_SPECIAL(x) \
- (IS_SPECIAL_WO_ELLIPSE(x) || \
- (x == 0x2026)) /* hellip */
-
-nsresult
-nsFontMetricsOS2::ResolveForwards(HPS aPS,
- const PRUnichar* aString,
- PRUint32 aLength,
- nsFontSwitchCallback aFunc,
- void* aData)
-{
- NS_ASSERTION(aString || !aLength, "invalid call");
- const PRUnichar* firstChar = aString;
- const PRUnichar* currChar = firstChar;
- const PRUnichar* lastChar = aString + aLength;
- PRBool running = PR_TRUE;
-
- nsFontSwitch fontSwitch;
- fontSwitch.mFont = 0;
-
- if (mConvertCodePage == 1252)
- {
- while (running && firstChar < lastChar)
- {
- if ((*currChar > 0x00FF) && !IS_SPECIAL(*currChar))
- {
- if (!mUnicodeFont) {
- FindUnicodeFont(aPS);
- if (!mUnicodeFont) {
- mUnicodeFont = FindGlobalFont(aPS, *currChar);
- }
- }
- fontSwitch.mFont = mUnicodeFont;
- while( ++currChar < lastChar ) {
- if (( *currChar <= 0x00FF ) || IS_SPECIAL(*currChar))
- break;
- }
- running = (*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData);
- } else {
- // Use currently selected font
- fontSwitch.mFont = mFontHandle;
- while( ++currChar < lastChar ) {
- if (( *currChar > 0x00FF ) && !IS_SPECIAL(*currChar))
- break;
- }
- running = (*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData);
- }
- firstChar = currChar;
- }
- }
- else
- {
- while (running && firstChar < lastChar)
- {
- if ((*currChar >= 0x0080 && *currChar <= 0x00FF) || IS_SPECIAL_WO_ELLIPSE(*currChar))
- {
- if (!mWesternFont) {
- FindWesternFont();
- }
- fontSwitch.mFont = mWesternFont;
- while( ++currChar < lastChar ) {
- if ((*currChar < 0x0080 || *currChar > 0x00FF) && !IS_SPECIAL_WO_ELLIPSE(*currChar))
- break;
- }
- running = (*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData);
- } else {
- // Use currently selected font
- fontSwitch.mFont = mFontHandle;
- while( ++currChar < lastChar ) {
- if ((*currChar >= 0x0080 && *currChar <= 0x00FF) || IS_SPECIAL_WO_ELLIPSE(*currChar))
- break;
- }
- running = (*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData);
- }
- firstChar = currChar;
- }
- }
- return NS_OK;
-}
-
-nsresult
-nsFontMetricsOS2::ResolveBackwards(HPS aPS,
- const PRUnichar* aString,
- PRUint32 aLength,
- nsFontSwitchCallback aFunc,
- void* aData)
-{
- NS_ASSERTION(aString || !aLength, "invalid call");
- const PRUnichar* firstChar = aString + aLength - 1;
- const PRUnichar* lastChar = aString - 1;
- const PRUnichar* currChar = firstChar;
- PRBool running = PR_TRUE;
-
- nsFontSwitch fontSwitch;
- fontSwitch.mFont = 0;
-
- if (mConvertCodePage == 1252)
- {
- while (running && firstChar > lastChar)
- {
- if ((*currChar > 0x00FF) && !IS_SPECIAL(*currChar))
- {
- if (!mUnicodeFont) {
- FindUnicodeFont(aPS);
- if (!mUnicodeFont) {
- mUnicodeFont = FindGlobalFont(aPS, *currChar);
- }
- }
- fontSwitch.mFont = mUnicodeFont;
- while( --currChar > lastChar ) {
- if (( *currChar <= 0x00FF ) || IS_SPECIAL(*currChar))
- break;
- }
- running = (*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData);
- }
- else
- {
- // Use currently selected font
- fontSwitch.mFont = mFontHandle;
- while( --currChar > lastChar ) {
- if (( *currChar > 0x00FF ) && !IS_SPECIAL(*currChar))
- break;
- }
- running = (*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData);
- }
- firstChar = currChar;
- }
- }
- else
- {
- while (running && firstChar > lastChar)
- {
- if ((*currChar >= 0x0080 && *currChar <= 0x00FF) || IS_SPECIAL(*currChar))
- {
- if (!mWesternFont) {
- FindWesternFont();
- }
- fontSwitch.mFont = mWesternFont;
- while( --currChar > lastChar ) {
- if ((*currChar < 0x0080 || *currChar > 0x00FF) && !IS_SPECIAL(*currChar))
- break;
- }
- running = (*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData);
- }
- else
- {
- // Use currently selected font
- fontSwitch.mFont = mFontHandle;
- while( --currChar > lastChar ) {
- if ((*currChar >= 0x0080 && *currChar <= 0x00FF) || IS_SPECIAL(*currChar))
- break;
- }
- running = (*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData);
- }
- firstChar = currChar;
- }
- }
- return NS_OK;
-}
-
-
-/**********************************************************
- nsFontOS2
- **********************************************************/
-#ifdef DEBUG_FONT_STRUCT_ALLOCS
-unsigned long nsFontOS2::mRefCount = 0;
-#endif
-
-nsFontOS2::nsFontOS2(void)
-{
- mFattrs.usRecordLength = sizeof(mFattrs);
- mHashMe = gCurrHashValue;
- gCurrHashValue++;
-#ifdef DEBUG_FONT_STRUCT_ALLOCS
- mRefCount++;
- printf("+++ nsFontOS2 total = %d\n", mRefCount);
-#endif
-}
-
-nsFontOS2::~nsFontOS2(void)
-{
-#ifdef DEBUG_FONT_STRUCT_ALLOCS
- mRefCount--;
- printf("--- nsFontOS2 total = %d\n", mRefCount);
-#endif
-}
-
-void
-nsFontOS2::SelectIntoPS( HPS aPS, long aLcid )
-{
- GFX (::GpiSetCharSet(aPS, aLcid), FALSE);
- GFX (::GpiSetCharBox(aPS, &mCharbox), FALSE);
-}
-
-PRInt32
-nsFontOS2::GetWidth(HPS aPS, const char* aString, PRUint32 aLength)
-{
- SIZEL size;
- GetTextExtentPoint32(aPS, aString, aLength, &size);
- return size.cx;
-}
-
-PRInt32
-nsFontOS2::GetWidth(HPS aPS, const PRUnichar* aString, PRUint32 aLength)
-{
- nsAutoCharBuffer buffer;
- PRInt32 destLength = aLength;
- WideCharToMultiByte(mConvertCodePage, aString, aLength, buffer, destLength);
-
- SIZEL size;
- GetTextExtentPoint32(aPS, buffer.get(), destLength, &size);
-
- return size.cx;
-}
-
-void
-nsFontOS2::DrawString(HPS aPS, nsDrawingSurfaceOS2* aSurface,
- PRInt32 aX, PRInt32 aY,
- const char* aString, PRUint32 aLength, INT* aDx0)
-{
- POINTL ptl = { aX, aY };
- aSurface->NS2PM(&ptl, 1);
- ExtTextOut(aPS, ptl.x, ptl.y, 0, NULL, aString, aLength, aDx0);
-}
-
-void
-nsFontOS2::DrawString(HPS aPS, nsDrawingSurfaceOS2* aSurface,
- PRInt32 aX, PRInt32 aY,
- const PRUnichar* aString, PRUint32 aLength)
-{
- nsAutoCharBuffer buffer;
- PRInt32 destLength = aLength;
- WideCharToMultiByte(mConvertCodePage, aString, aLength, buffer, destLength);
-
- POINTL ptl = { aX, aY };
- aSurface->NS2PM (&ptl, 1);
-
- ExtTextOut(aPS, ptl.x, ptl.y, 0, NULL, buffer.get(), destLength, NULL);
-}
-
-
-#ifdef USE_FREETYPE
-/**********************************************************
- nsFontMetricsOS2FT
- **********************************************************/
-Ft2EnableFontEngine nsFontMetricsOS2FT::pfnFt2EnableFontEngine = NULL;
-
-#define IsCJKLangGroupAtom(a) ((a)==gJA || (a)==gKO || (a)==gZHCN || \
- (a)==gZHTW || (a) == gZHHK)
-
-nsFontMetricsOS2FT::~nsFontMetricsOS2FT()
-{
- mSubstituteFont = nsnull; // released in ~nsFontMetricsOS2()
-}
-
-nsFontOS2*
-nsFontMetricsOS2FT::FindPrefFont(HPS aPS, PRUint32 aChar)
-{
- if (mTriedAllPref) {
- // don't bother anymore because mLoadedFonts[] already has all our pref fonts
- return nsnull;
- }
- nsFont font("", 0, 0, 0, 0, 0);
-
- // Sometimes we could not find the font in doc's suggested langGroup,(this usually means
- // the language specified by doc is incorrect). The characters can, to a certain degree,
- // tell us what language it is. This allows us to quickly locate and use a more appropriate
- // font as indicated by user's preference. In some situations a set of possible languages may
- // be identified instead of a single language (eg. CJK and latin). In this case we have to
- // try every language in the set. gUserLocale and gSystemLocale provide some hints about
- // which one should be tried first. This is important for CJK font, since the glyph for single
- // char varies dramatically in different languages. For latin languages, their glyphs are
- // similar. In fact, they almost always share identical fonts. It will be a waste of time to
- // figure out which one comes first. As a final fallback, unicode preference is always tried.
-
- PRUint32 unicodeRange = FindCharUnicodeRange(aChar);
- if (unicodeRange < kRangeSpecificItemNum) {
- // a single language is identified
- AppendGenericFontFromPref(font.name, LangGroupFromUnicodeRange(unicodeRange),
- NS_ConvertUTF16toUTF8(mGeneric).get());
- } else if (kRangeSetLatin == unicodeRange) {
- // Character is from a latin language set, so try western and central european
- // If mLangGroup is western or central european, this most probably will not be
- // used, but is here as a fallback scenario.
- AppendGenericFontFromPref(font.name, "x-western",
- NS_ConvertUTF16toUTF8(mGeneric).get());
- AppendGenericFontFromPref(font.name, "x-central-euro",
- NS_ConvertUTF16toUTF8(mGeneric).get());
- } else if (kRangeSetCJK == unicodeRange) {
- // CJK, we have to be careful about the order, use locale info as hint
-
- // then try user locale first, if it is CJK
- if ((gUsersLocale != mLangGroup) && IsCJKLangGroupAtom(gUsersLocale)) {
- nsCAutoString usersLocaleLangGroup;
- gUsersLocale->ToUTF8String(usersLocaleLangGroup);
- AppendGenericFontFromPref(font.name, usersLocaleLangGroup.get(),
- NS_ConvertUTF16toUTF8(mGeneric).get());
- }
-
- // then system locale (os language)
- if ((gSystemLocale != mLangGroup) && (gSystemLocale != gUsersLocale) && IsCJKLangGroupAtom(gSystemLocale)) {
- nsCAutoString systemLocaleLangGroup;
- gSystemLocale->ToUTF8String(systemLocaleLangGroup);
- AppendGenericFontFromPref(font.name, systemLocaleLangGroup.get(),
- NS_ConvertUTF16toUTF8(mGeneric).get());
- }
-
- // try all other languages in this set.
- if (mLangGroup != gJA && gUsersLocale != gJA && gSystemLocale != gJA)
- AppendGenericFontFromPref(font.name, "ja",
- NS_ConvertUTF16toUTF8(mGeneric).get());
- if (mLangGroup != gZHCN && gUsersLocale != gZHCN && gSystemLocale != gZHCN)
- AppendGenericFontFromPref(font.name, "zh-CN",
- NS_ConvertUTF16toUTF8(mGeneric).get());
- if (mLangGroup != gZHTW && gUsersLocale != gZHTW && gSystemLocale != gZHTW)
- AppendGenericFontFromPref(font.name, "zh-TW",
- NS_ConvertUTF16toUTF8(mGeneric).get());
- if (mLangGroup != gZHHK && gUsersLocale != gZHHK && gSystemLocale != gZHHK)
- AppendGenericFontFromPref(font.name, "zh-HK",
- NS_ConvertUTF16toUTF8(mGeneric).get());
- if (mLangGroup != gKO && gUsersLocale != gKO && gSystemLocale != gKO)
- AppendGenericFontFromPref(font.name, "ko",
- NS_ConvertUTF16toUTF8(mGeneric).get());
- }
-
- // always try unicode as fallback
- AppendGenericFontFromPref(font.name, "x-unicode",
- NS_ConvertUTF16toUTF8(mGeneric).get());
-
- // use the font list to find font
- GenericFontEnumContext context = {aPS, aChar, nsnull, this};
- font.EnumerateFamilies(GenericFontEnumCallback, &context);
- if (context.mFont) { // a suitable font was found
- return context.mFont;
- }
- mTriedAllPref = 1;
- return nsnull;
-}
-
-struct FindGlobalFontData
-{
- HPS ps; // IN
- PRUint32 ch; // IN - looking for font that has this char
- nsFontOS2FT* font; // IN - scratch object
- GlobalFontEntry* entry; // OUT - set to matching global font entry
-};
-
-PR_STATIC_CALLBACK(PLDHashOperator)
-FindGlobalFontEnumFunc(GlobalFontEntry* aEntry, void* aData)
-{
- FindGlobalFontData* data = static_cast<FindGlobalFontData*>(aData);
- strcpy(data->font->mFattrs.szFacename, aEntry->mMetrics->szFacename);
-#ifdef PERF_HASGLYPH_CHAR_MAP
- if (aEntry->mHaveCheckedCharMap == nsnull) {
- aEntry->mHaveCheckedCharMap = (PRUint32*)calloc(UCS2_MAP_LEN, sizeof(PRUint32));
- aEntry->mRepresentableCharMap = (PRUint32*)calloc(UCS2_MAP_LEN, sizeof(PRUint32));
- }
- data->font->mHaveCheckedCharMap = aEntry->mHaveCheckedCharMap;
- data->font->mRepresentableCharMap = aEntry->mRepresentableCharMap;
-#endif
-
- if (data->font->HasGlyph(data->ps, data->ch)) {
- data->entry = aEntry;
- return PL_DHASH_STOP;
- } else {
- return PL_DHASH_NEXT;
- }
-}
-
-nsFontOS2*
-nsFontMetricsOS2FT::FindGlobalFont(HPS aPS, PRUint32 aChar)
-{
- //now try global font
- if (!gGlobalFonts) {
- if (!InitializeGlobalFonts()) {
- return nsnull;
- }
- }
-
- FindGlobalFontData data = {aPS, aChar, nsnull, nsnull};
- data.font = new nsFontOS2FT();
- gGlobalFonts->EnumerateEntries(FindGlobalFontEnumFunc, &data);
- delete data.font;
- if (data.entry) {
- return LoadFont(aPS, data.entry->GetKey());
- }
- return nsnull;
-}
-
-nsFontOS2*
-nsFontMetricsOS2FT::FindSubstituteFont(HPS aPS, PRUint32 c)
-{
- /*
- When this function is called, it means all other alternatives have
- been unsuccessfully tried! So the idea is this:
-
- See if the "substitute font" is already loaded?
- a/ if yes, ADD_GLYPH(c), to record that the font should be used
- to render this char from now on.
- b/ if no, load the font, and ADD_GLYPH(c)
- */
-
- if (mSubstituteFont) {
- // Make the char representable so that we don't have to go over all fonts
- // before fallback to subsituteFont.
- ((nsFontOS2Substitute*)mSubstituteFont)->SetRepresentable(c);
- return mSubstituteFont;
- }
-
- // The "substitute font" has not yet been created...
- // The first font that has the
- // replacement char is taken and placed as the substitute font.
-
- // Try local/loaded fonts first
- int i, count = mLoadedFonts.Count();
- for (i = 0; i < count; ++i) {
- nsFontOS2* font = (nsFontOS2*)mLoadedFonts[i];
- if (font->HasGlyph(aPS, NS_REPLACEMENT_CHAR)) {
- nsFontOS2Substitute* subFont = new nsFontOS2Substitute(font);
- mLoadedFonts.AppendElement((nsFontOS2*)subFont);
- subFont->SetRepresentable(c);
- mSubstituteFont = subFont;
- return subFont;
- }
- }
-
- // Try global fonts
- // Since we reach here after FindGlobalFont() is called, we have already
- // scanned the global list of fonts and have set the attributes of interest
- FindGlobalFontData data = {aPS, NS_REPLACEMENT_CHAR, nsnull, nsnull};
- data.font = new nsFontOS2FT();
- gGlobalFonts->EnumerateEntries(FindGlobalFontEnumFunc, &data);
- delete data.font;
- if (data.entry) {
- nsFontOS2* font = LoadFont(aPS, data.entry->GetKey());
- if (font) {
- nsFontOS2Substitute* subFont = new nsFontOS2Substitute(font);
- // LoadFont() appends given font to end of mLoadedFonts. Just replace
- // font with our substitute font.
- mLoadedFonts.ReplaceElementAt((nsFontOS2*)subFont, mLoadedFonts.Count());
- subFont->SetRepresentable(c);
- mSubstituteFont = subFont;
- return subFont;
- }
- }
-
- NS_ERROR("Could not provide a substititute font");
- return nsnull;
-}
-
-nsFontOS2*
-nsFontMetricsOS2FT::LocateFont(HPS aPS, PRUint32 aChar, PRInt32 & aCount)
-{
- nsFontOS2* font;
- PRInt32 i;
-
- // see if one of our loaded fonts can represent the character
- for (i = 0; i < aCount; ++i) {
- font = (nsFontOS2*)mLoadedFonts[i];
- if (font->HasGlyph(aPS, aChar))
- return font;
- }
-
- font = FindFont(aPS, aChar);
- aCount = mLoadedFonts.Count(); // update since FindFont() can change it
- NS_ASSERTION(font && mLoadedFonts.IndexOf(font) >= 0,
- "Could not find a font");
- return font;
-}
-
-nsresult
-nsFontMetricsOS2FT::ResolveForwards(HPS aPS,
- const PRUnichar* aString,
- PRUint32 aLength,
- nsFontSwitchCallback aFunc,
- void* aData)
-{
- NS_ASSERTION(aString || !aLength, "invalid call");
- const PRUnichar* firstChar = aString;
- const PRUnichar* currChar = firstChar;
- const PRUnichar* lastChar = aString + aLength;
- nsFontOS2* currFont;
- nsFontOS2* nextFont;
- PRInt32 count;
- nsFontSwitch fontSwitch;
-
- if (firstChar == lastChar)
- return NS_OK;
-
- count = mLoadedFonts.Count();
-
- if (NS_IS_HIGH_SURROGATE(*currChar) && (currChar+1) < lastChar && NS_IS_LOW_SURROGATE(*(currChar+1))) {
- currFont = LocateFont(aPS, SURROGATE_TO_UCS4(*currChar, *(currChar+1)), count);
- currChar += 2;
- }
- else {
- currFont = LocateFont(aPS, *currChar, count);
- ++currChar;
- }
-
- //This if block is meant to speedup the process in normal situation, when
- //most characters can be found in first font
- if (currFont == mLoadedFonts[0]) {
- while (currChar < lastChar && (currFont->HasGlyph(aPS, *currChar)))
- ++currChar;
- fontSwitch.mFont = currFont;
- if (!(*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData))
- return NS_OK;
- if (currChar == lastChar)
- return NS_OK;
- // continue with the next substring, re-using the available loaded fonts
- firstChar = currChar;
- if (NS_IS_HIGH_SURROGATE(*currChar) && (currChar+1) < lastChar && NS_IS_LOW_SURROGATE(*(currChar+1))) {
- currFont = LocateFont(aPS, SURROGATE_TO_UCS4(*currChar, *(currChar+1)), count);
- currChar += 2;
- }
- else {
- currFont = LocateFont(aPS, *currChar, count);
- ++currChar;
- }
- }
-
- // see if we can keep the same font for adjacent characters
- PRInt32 lastCharLen;
- while (currChar < lastChar) {
- if (NS_IS_HIGH_SURROGATE(*currChar) && (currChar+1) < lastChar && NS_IS_LOW_SURROGATE(*(currChar+1))) {
- nextFont = LocateFont(aPS, SURROGATE_TO_UCS4(*currChar, *(currChar+1)), count);
- lastCharLen = 2;
- }
- else {
- nextFont = LocateFont(aPS, *currChar, count);
- lastCharLen = 1;
- }
- if (nextFont != currFont) {
- // We have a substring that can be represented with the same font, and
- // we are about to switch fonts, it is time to notify our caller.
- fontSwitch.mFont = currFont;
- if (!(*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData))
- return NS_OK;
- // continue with the next substring, re-using the available loaded fonts
- firstChar = currChar;
-
- currFont = nextFont; // use the font found earlier for the char
- }
- currChar += lastCharLen;
- }
-
- //do it for last part of the string
- fontSwitch.mFont = currFont;
- (*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData);
- return NS_OK;
-}
-
-nsresult
-nsFontMetricsOS2FT::ResolveBackwards(HPS aPS,
- const PRUnichar* aString,
- PRUint32 aLength,
- nsFontSwitchCallback aFunc,
- void* aData)
-{
- NS_ASSERTION(aString || !aLength, "invalid call");
- const PRUnichar* firstChar = aString + aLength - 1;
- const PRUnichar* lastChar = aString - 1;
- const PRUnichar* currChar = firstChar;
- nsFontOS2* currFont;
- nsFontOS2* nextFont;
- PRInt32 count;
- nsFontSwitch fontSwitch;
-
- if (firstChar == lastChar)
- return NS_OK;
-
- count = mLoadedFonts.Count();
-
- // see if one of our loaded fonts can represent the current character
- if (NS_IS_LOW_SURROGATE(*currChar) && (currChar-1) > lastChar && NS_IS_HIGH_SURROGATE(*(currChar-1))) {
- currFont = LocateFont(aPS, SURROGATE_TO_UCS4(*(currChar-1), *currChar), count);
- currChar -= 2;
- }
- else {
- currFont = LocateFont(aPS, *currChar, count);
- --currChar;
- }
-
- //This if block is meant to speedup the process in normal situation, when
- //most characters can be found in first font
- if (currFont == mLoadedFonts[0]) {
- while (currChar > lastChar && (currFont->HasGlyph(aPS, *currChar)))
- --currChar;
- fontSwitch.mFont = currFont;
- if (!(*aFunc)(&fontSwitch, currChar+1, firstChar - currChar, aData))
- return NS_OK;
- if (currChar == lastChar)
- return NS_OK;
- // continue with the next substring, re-using the available loaded fonts
- firstChar = currChar;
- if (NS_IS_LOW_SURROGATE(*currChar) && (currChar-1) > lastChar && NS_IS_HIGH_SURROGATE(*(currChar-1))) {
- currFont = LocateFont(aPS, SURROGATE_TO_UCS4(*(currChar-1), *currChar), count);
- currChar -= 2;
- }
- else {
- currFont = LocateFont(aPS, *currChar, count);
- --currChar;
- }
- }
-
- // see if we can keep the same font for adjacent characters
- PRInt32 lastCharLen;
- PRUint32 codepoint;
-
- while (currChar > lastChar) {
- if (NS_IS_LOW_SURROGATE(*currChar) && (currChar-1) > lastChar && NS_IS_HIGH_SURROGATE(*(currChar-1))) {
- codepoint = SURROGATE_TO_UCS4(*(currChar-1), *currChar);
- nextFont = LocateFont(aPS, codepoint, count);
- lastCharLen = 2;
- }
- else {
- codepoint = *currChar;
- nextFont = LocateFont(aPS, codepoint, count);
- lastCharLen = 1;
- }
- if (nextFont != currFont ||
- /* render right-to-left characters outside the BMP one by one, because
- OS/2 doesn't reorder them. */
- codepoint > 0xFFFF) {
- // We have a substring that can be represented with the same font, and
- // we are about to switch fonts, it is time to notify our caller.
- fontSwitch.mFont = currFont;
- if (!(*aFunc)(&fontSwitch, currChar+1, firstChar - currChar, aData))
- return NS_OK;
- // continue with the next substring, re-using the available loaded fonts
- firstChar = currChar;
- currFont = nextFont; // use the font found earlier for the char
- }
- currChar -= lastCharLen;
- }
-
- //do it for last part of the string
- fontSwitch.mFont = currFont;
- (*aFunc)(&fontSwitch, currChar+1, firstChar - currChar, aData);
-
- return NS_OK;
-}
-
-
-/**********************************************************
- nsFontOS2FT
- **********************************************************/
-Ft2FontSupportsUnicodeChar1 nsFontOS2FT::pfnFt2FontSupportsUnicodeChar1 = NULL;
-#ifdef USE_EXPANDED_FREETYPE_FUNCS
-Ft2QueryTextBoxW nsFontOS2FT::pfnFt2QueryTextBoxW = NULL;
-Ft2CharStringPosAtW nsFontOS2FT::pfnFt2CharStringPosAtW = NULL;
-#endif /* use_expanded_freetype_funcs */
-
-#ifdef DEBUG_FONT_STRUCT_ALLOCS
-unsigned long nsFontOS2FT::mRefCount = 0;
-#endif
-
-nsFontOS2FT::nsFontOS2FT(void) : nsFontOS2()
-{
- mFattrs.usCodePage = 1208;
-#ifdef DEBUG_FONT_STRUCT_ALLOCS
- mRefCount++;
- printf("+++ nsFontOS2FT total = %d\n", mRefCount);
-#endif
-}
-
-nsFontOS2FT::~nsFontOS2FT(void)
-{
-#ifdef DEBUG_FONT_STRUCT_ALLOCS
- mRefCount--;
- printf("--- nsFontOS2FT total = %d\n", mRefCount);
-#endif
-}
-
-PRBool
-nsFontOS2FT::HasGlyph(HPS aPS, PRUint32 aChar)
-{
-#ifdef PERF_HASGLYPH_CHAR_MAP
- if (IS_IN_BMP(aChar) && IS_REPRESENTABLE(mHaveCheckedCharMap, aChar)) {
- // we have already checked this char for this font
- return IS_REPRESENTABLE(mRepresentableCharMap, aChar);
- } else
-#endif
- {
- // If not in Plane 0, OS/2 can't render it.
- if (!IS_IN_BMP(aChar)) {
- return PR_FALSE;
- }
-
- PRBool rc = pfnFt2FontSupportsUnicodeChar1(0, &mFattrs, PR_TRUE, aChar);
-
-#ifdef PERF_HASGLYPH_CHAR_MAP
- // set that we have checked this char
- SET_REPRESENTABLE(mHaveCheckedCharMap, aChar);
- if (rc) {
- SET_REPRESENTABLE(mRepresentableCharMap, aChar);
- }
-#endif
-
- return rc;
- }
-}
-
-PRInt32
-nsFontOS2FT::GetWidth(HPS aPS, const PRUnichar* aString, PRUint32 aLength)
-{
- USHORT rc;
- SIZEL size;
-
- if (!IsSymbolFont()) {
-#ifdef USE_EXPANDED_FREETYPE_FUNCS
- POINTL ptls[5];
- rc = pfnFt2QueryTextBoxW(aPS, aLength, (LPWSTR)aString, 5, ptls);
- size.cx = ptls[TXTBOX_CONCAT].x;
-
-#ifdef DEBUG
- if (rc == FALSE) {
- // We only expect Ft2QueryTextBoxW() to fail with
- // PMERR_FUNCTION_NOT_SUPPORTED. If it fails with any other error, then
- // print out a warning message
- USHORT errorCode = ERRORIDERROR (::WinGetLastError(0));
- if (errorCode != PMERR_FUNCTION_NOT_SUPPORTED) {
- printf("GFX_Err: pfnFt2QueryTextBoxW = 0x%X, 0x%X (%s - %s, line %d)\n",
- rc, errorCode, __FILE__, __FUNCTION__, __LINE__);
- }
- }
-#endif /* debug */
-
- // Sometimes, Ft2QueryTextBoxW will fail with FALSE (WinGetLastError
- // will return PMERR_FUNCTION_NOT_SUPPORTED), particularly when printing
- // (this function is not supported when printing). So if it fails, fall back
- // to the straight GPI call case.
- if (rc == FALSE)
-#endif /* use_expanded_freetype_funcs */
- {
- NS_ConvertUTF16toUTF8 str(Substring(aString, aString + aLength));
- rc = GetTextExtentPoint32(aPS, (const char*)str.get(), str.Length(),
- &size);
- }
- } else {
- nsAutoCharBuffer buffer;
- PRInt32 destLength = aLength;
- WideCharToMultiByte(1252, aString, aLength, buffer, destLength);
- rc = GetTextExtentPoint32(aPS, buffer.get(), destLength, &size);
- }
-
- if (rc == TRUE) {
- return size.cx;
- } else {
- return 0;
- }
-}
-
-void
-nsFontOS2FT::DrawString(HPS aPS, nsDrawingSurfaceOS2* aSurface,
- PRInt32 aX, PRInt32 aY,
- const PRUnichar* aString, PRUint32 aLength)
-{
- USHORT rc;
- POINTL ptl = { aX, aY };
- aSurface->NS2PM(&ptl, 1);
-
- if (!IsSymbolFont()) {
-#ifdef USE_EXPANDED_FREETYPE_FUNCS
- rc = pfnFt2CharStringPosAtW(aPS, &ptl, NULL, 0, aLength,
- (LPWSTR)aString, NULL, NULL);
-
-#ifdef DEBUG
- if (rc == GPI_ERROR) {
- // We only expect Ft2CharStringPosAtW() to fail with
- // PMERR_FUNCTION_NOT_SUPPORTED. If it fails with any other error, then
- // print out a warning message
- USHORT errorCode = ERRORIDERROR (::WinGetLastError(0));
- if (errorCode != PMERR_FUNCTION_NOT_SUPPORTED) {
- printf("GFX_Err: pfnFt2CharStringPosAtW = 0x%X, 0x%X (%s - %s, line %d)\n",
- rc, errorCode, __FILE__, __FUNCTION__, __LINE__);
- }
- }
-#endif /* debug */
-
- // Sometimes, Ft2CharStringPosAtW will fail with GPI_ERROR (WinGetLastError
- // will return PMERR_FUNCTION_NOT_SUPPORTED), particularly when printing
- // (this function is not supported when printing). So if it fails, fall back
- // to the straight GPI call case.
- if (rc == GPI_ERROR)
-#endif /* use_expanded_freetype_funcs */
- {
- NS_ConvertUTF16toUTF8 str(Substring(aString, aString + aLength));
- ExtTextOut(aPS, ptl.x, ptl.y, 0, NULL, (const char*)str.get(),
- str.Length(), NULL);
- }
- } else {
- nsAutoCharBuffer buffer;
- PRInt32 destLength = aLength;
- WideCharToMultiByte(1252, aString, aLength, buffer, destLength);
- ExtTextOut(aPS, ptl.x, ptl.y, 0, NULL, buffer.get(), destLength, NULL);
- }
-}
-
-/**********************************************************
- nsFontOS2Substitute
- **********************************************************/
-nsFontOS2Substitute::nsFontOS2Substitute(nsFontOS2* aFont)
-{
- mHashMe = gCurrHashValue;
- gCurrHashValue++;
-
- mFattrs = aFont->mFattrs;
- mCharbox = aFont->mCharbox;
- mMaxAscent = aFont->mMaxAscent;
- mMaxDescent = aFont->mMaxDescent;
- mConvertCodePage = aFont->mConvertCodePage;
-
- memset(mRepresentableCharMap, 0, sizeof(mRepresentableCharMap));
-#ifdef DEBUG_FONT_STRUCT_ALLOCS
- mRefCount++;
- printf("+++ nsFontOS2Substitute total = %d\n", mRefCount);
-#endif
-}
-
-nsFontOS2Substitute::~nsFontOS2Substitute(void)
-{
-#ifdef DEBUG_FONT_STRUCT_ALLOCS
- mRefCount--;
- printf("--- nsFontOS2Substitute total = %d\n", mRefCount);
-#endif
-}
-
-static nsresult
-SubstituteChars(const PRUnichar* aString,
- PRUint32 aLength,
- nsAutoChar16Buffer& aResult,
- PRUint32* aCount)
-{
- nsresult res;
- if (!gFontSubstituteConverter) {
- CallCreateInstance(NS_SAVEASCHARSET_CONTRACTID, &gFontSubstituteConverter);
- if (gFontSubstituteConverter) {
- res = gFontSubstituteConverter->Init("ISO-8859-1",
- nsISaveAsCharset::attr_EntityAfterCharsetConv +
- nsISaveAsCharset::attr_FallbackQuestionMark +
- nsISaveAsCharset::attr_IgnoreIgnorables,
- nsIEntityConverter::transliterate);
- if (NS_FAILED(res)) {
- NS_RELEASE(gFontSubstituteConverter);
- }
- }
- }
-
- // do the transliteration if we have a converter
- PRUnichar* result;
- if (gFontSubstituteConverter) {
- nsXPIDLCString conv;
- nsAutoString tmp(aString, aLength); // we need to pass a null-terminated string
- res = gFontSubstituteConverter->Convert(tmp.get(), getter_Copies(conv));
- if (NS_SUCCEEDED(res)) {
- *aCount = conv.Length();
- if (*aCount > 0) {
- if (!aResult.EnsureElemCapacity(*aCount)) {
- return NS_ERROR_OUT_OF_MEMORY;
- }
- result = aResult.get();
- PRUnichar* u = result;
- const char* c = conv.get();
- for (; *c; ++c, ++u) {
- *u = *c;
- }
- }
- return NS_OK;
- }
- }
-
- // we reach here if we couldn't transliterate, so fallback to question marks
- if (!aResult.EnsureElemCapacity(aLength)) return NS_ERROR_OUT_OF_MEMORY;
- result = aResult.get();
- for (PRUint32 i = 0; i < aLength; i++) {
- result[i] = NS_REPLACEMENT_CHAR;
- }
- *aCount = aLength;
- return NS_OK;
-}
-
-PRInt32
-nsFontOS2Substitute::GetWidth(HPS aPS, const PRUnichar* aString,
- PRUint32 aLength)
-{
- nsAutoChar16Buffer buffer;
- nsresult rv = SubstituteChars(aString, aLength, buffer, &aLength);
- if (NS_FAILED(rv) || !aLength) return 0;
-
- SIZEL size;
- PRUnichar* string = buffer.get();
- NS_ConvertUTF16toUTF8 str(Substring(string, string + aLength));
- BOOL rc = GetTextExtentPoint32(aPS, (const char*)str.get(), str.Length(),
- &size);
- if (rc == TRUE) {
- return size.cx;
- } else {
- return 0;
- }
-}
-
-void
-nsFontOS2Substitute::DrawString(HPS aPS, nsDrawingSurfaceOS2* aSurface,
- PRInt32 aX, PRInt32 aY,
- const PRUnichar* aString, PRUint32 aLength)
-{
- nsAutoChar16Buffer buffer;
- nsresult rv = SubstituteChars(aString, aLength, buffer, &aLength);
- if (NS_FAILED(rv) || !aLength) return;
-
- POINTL ptl = { aX, aY };
- aSurface->NS2PM(&ptl, 1);
- PRUnichar* string = buffer.get();
- NS_ConvertUTF16toUTF8 str(Substring(string, string + aLength));
- ExtTextOut(aPS, ptl.x, ptl.y, 0, NULL, (const char*)str.get(), str.Length(), NULL);
-}
-#endif /* use_freetype */
-
-
-/**********************************************************
- nsFontEnumeratorOS2
- **********************************************************/
-nsFontEnumeratorOS2::nsFontEnumeratorOS2()
-{
-}
-
-NS_IMPL_ISUPPORTS1(nsFontEnumeratorOS2, nsIFontEnumerator)
-
-// We want vertical fonts (those whose name start with '@') to appear
-// immediately following the non-vertical font of the same name.
-static int
-CompareFontNames(const void* aArg1, const void* aArg2, void* aClosure)
-{
- const PRUnichar* str1 = *((const PRUnichar**) aArg1);
- const PRUnichar* str2 = *((const PRUnichar**) aArg2);
-
- int rc = 9;
- if ((char)str1[0] == '@') {
- str1++;
- rc = nsCRT::strcmp(str1, str2);
- if (rc == 0)
- return 1;
- }
- if ((char)str2[0] == '@') {
- str2++;
- rc = nsCRT::strcmp(str1, str2);
- if (rc == 0)
- return -1;
- }
-
- if (rc == 9)
- rc = nsCRT::strcmp(str1, str2);
- return rc;
-}
-
-NS_IMETHODIMP
-nsFontEnumeratorOS2::EnumerateFonts(const char* aLangGroup,
- const char* aGeneric, PRUint32* aCount, PRUnichar*** aResult)
-{
- return EnumerateAllFonts(aCount, aResult);
-}
-
-struct EnumerateAllFontsData
-{
- PRUnichar** array; // OUT - array of family names
- int count; // IN/OUT - running count of names in array
-};
-
-PR_STATIC_CALLBACK(PLDHashOperator)
-EnumerateAllFontsCallback(GlobalFontEntry* aEntry, void* aData)
-{
- EnumerateAllFontsData* data = static_cast<EnumerateAllFontsData*>(aData);
- data->array[data->count++] = ToNewUnicode(aEntry->GetKey());
- return PL_DHASH_NEXT;
-}
-
-NS_IMETHODIMP
-nsFontEnumeratorOS2::EnumerateAllFonts(PRUint32* aCount, PRUnichar*** aResult)
-{
- NS_ENSURE_ARG_POINTER(aCount);
- NS_ENSURE_ARG_POINTER(aResult);
-
- if (!nsFontMetricsOS2::gGlobalFonts) {
- nsresult res = nsFontMetricsOS2::InitializeGlobalFonts();
- if (NS_FAILED(res)) {
- FreeGlobals();
- return res;
- }
- }
-
- *aCount = nsFontMetricsOS2::gGlobalFonts->Count();
- PRUnichar** array = (PRUnichar**)nsMemory::Alloc(*aCount * sizeof(PRUnichar*));
- NS_ENSURE_TRUE(array, NS_ERROR_OUT_OF_MEMORY);
-
- EnumerateAllFontsData data = {array, 0};
- nsFontMetricsOS2::gGlobalFonts->EnumerateEntries(EnumerateAllFontsCallback,
- &data);
-
- NS_QuickSort(array, *aCount, sizeof(PRUnichar*), CompareFontNames, nsnull);
-
- *aResult = array;
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsFontEnumeratorOS2::HaveFontFor(const char* aLangGroup, PRBool* aResult)
-{
- NS_ENSURE_ARG_POINTER(aLangGroup);
- NS_ENSURE_ARG_POINTER(aResult);
- *aResult = PR_FALSE;
-
- // XXX stub
- NS_ASSERTION( 0, "HaveFontFor is not implemented" );
-
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
-nsFontEnumeratorOS2::GetDefaultFont(const char *aLangGroup,
- const char *aGeneric, PRUnichar **aResult)
-{
- // aLangGroup=null or "" means any (i.e., don't care)
- // aGeneric=null or "" means any (i.e, don't care)
-
- NS_ENSURE_ARG_POINTER(aResult);
- *aResult = nsnull;
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsFontEnumeratorOS2::UpdateFontList(PRBool *updateFontList)
-{
- *updateFontList = PR_FALSE; // always return false for now
- NS_ASSERTION( 0, "UpdateFontList is not implemented" );
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-
deleted file mode 100644
--- a/gfx/src/os2/nsFontMetricsOS2.h
+++ /dev/null
@@ -1,461 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Mozilla OS/2 libraries.
- *
- * The Initial Developer of the Original Code is
- * John Fairhurst, <john_fairhurst@iname.com>.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK *****
- *
- * This Original Code has been modified by IBM Corporation.
- * Modifications made by IBM described herein are
- * Copyright (c) International Business Machines
- * Corporation, 2000
- *
- * Modifications to Mozilla code or documentation
- * identified per MPL Section 3.3
- *
- * Date Modified by Description of modification
- * 03/28/2000 IBM Corp. Changes to make os2.h file similar to windows.h file
- */
-
-#ifndef _nsFontMetricsOS2_h
-#define _nsFontMetricsOS2_h
-
-#include "nsGfxDefs.h"
-
-#include "plhash.h"
-#include "nsIFontMetrics.h"
-#include "nsIFontEnumerator.h"
-#include "nsFont.h"
-#include "nsString.h"
-#include "nsUnitConversion.h"
-#include "nsIDeviceContext.h"
-#include "nsCRT.h"
-#include "nsDeviceContextOS2.h"
-#include "nsCOMPtr.h"
-#include "nsVoidArray.h"
-#include "nsICharRepresentable.h"
-#include "nsUnicharUtils.h"
-#include "nsDrawingSurfaceOS2.h"
-#include "nsTHashtable.h"
-#include "nsHashKeys.h"
-
-#ifndef FM_DEFN_LATIN1
-#define FM_DEFN_LATIN1 0x0010 /* Base latin character set */
-#define FM_DEFN_PC 0x0020 /* PC characters */
-#define FM_DEFN_LATIN2 0x0040 /* Extended latin character set */
-#define FM_DEFN_CYRILLIC 0x0080 /* Cyrillic character set */
-#define FM_DEFN_HEBREW 0x0100 /* Base Hebrew characters */
-#define FM_DEFN_GREEK 0x0200 /* Base Greek characters */
-#define FM_DEFN_ARABIC 0x0400 /* Base Arabic characters */
-#define FM_DEFN_UGLEXT 0x0800 /* Additional UGL chars */
-#define FM_DEFN_KANA 0x1000 /* Katakana and hiragana chars */
-#define FM_DEFN_THAI 0x2000 /* Thai characters */
-
-#define FM_DEFN_UGL383 0x0070 /* Chars in OS/2 2.1 */
-#define FM_DEFN_UGL504 0x00F0 /* Chars in OS/2 Warp 4 */
-#define FM_DEFN_UGL767 0x0FF0 /* Chars in ATM fonts */
-#define FM_DEFN_UGL1105 0x3FF0 /* Chars in bitmap fonts */
-#endif
-
-// Debug defines
-//#define DEBUG_FONT_SELECTION
-//#define DEBUG_FONT_STRUCT_ALLOCS
-
-#define USE_FREETYPE
-
-#ifdef USE_FREETYPE
- #define PERF_HASGLYPH_CHAR_MAP
- #define USE_EXPANDED_FREETYPE_FUNCS
-#endif
-
-struct nsMiniMetrics
-{
- char szFacename[FACESIZE];
- USHORT fsType;
- USHORT fsDefn;
- USHORT fsSelection;
- nsMiniMetrics* mNext;
-};
-
-// GlobalFontEntry->mStr is an nsString which contains the family name of font.
-class GlobalFontEntry : public nsStringHashKey
-{
-public:
- GlobalFontEntry(KeyTypePointer aStr) : nsStringHashKey(aStr) { }
- GlobalFontEntry(const GlobalFontEntry& aToCopy)
- : nsStringHashKey(aToCopy) { }
- ~GlobalFontEntry()
- {
- nsMiniMetrics* metrics = mMetrics;
- while (metrics) {
- nsMiniMetrics* nextMetrics = metrics->mNext;
- if (metrics)
- delete metrics;
- metrics = nextMetrics;
- }
-#ifdef PERF_HASGLYPH_CHAR_MAP
- if (mHaveCheckedCharMap) {
- nsMemory::Free(mHaveCheckedCharMap);
- nsMemory::Free(mRepresentableCharMap);
- }
-#endif
- }
-
- // Override, since we want to compare font names as case insensitive
- PRBool KeyEquals(const KeyTypePointer aKey) const
- {
- return GetKey().Equals(*aKey, nsCaseInsensitiveStringComparator());
- }
- static PLDHashNumber HashKey(const KeyTypePointer aKey)
- {
- nsAutoString low(*aKey);
- ToLowerCase(low);
- return HashString(low);
- }
-
- USHORT mCodePage;
- nsMiniMetrics* mMetrics;
-
-#ifdef PERF_HASGLYPH_CHAR_MAP
- PRUint32* mHaveCheckedCharMap;
- PRUint32* mRepresentableCharMap;
-#endif
-};
-
-// An nsFontHandle is actually a pointer to one of these.
-// It knows how to select itself into a ps.
-class nsFontOS2
-{
-public:
- NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
-
- nsFontOS2(void);
- virtual ~nsFontOS2(void);
-
- inline void SelectIntoPS(HPS hps, long lcid);
- virtual PRBool HasGlyph(HPS aPS, PRUint32 aChar) { return PR_TRUE; };
- virtual PRInt32 GetWidth(HPS aPS, const char* aString, PRUint32 aLength);
- virtual PRInt32 GetWidth(HPS aPS, const PRUnichar* aString, PRUint32 aLength);
- virtual void DrawString(HPS aPS, nsDrawingSurfaceOS2* aSurface,
- PRInt32 aX, PRInt32 aY,
- const char* aString, PRUint32 aLength, INT* aDx0);
- virtual void DrawString(HPS aPS, nsDrawingSurfaceOS2* aSurface,
- PRInt32 aX, PRInt32 aY,
- const PRUnichar* aString, PRUint32 aLength);
-
- FATTRS mFattrs;
- SIZEF mCharbox;
- ULONG mHashMe;
- nscoord mMaxAscent;
- nscoord mMaxDescent;
- int mConvertCodePage; /* XXX do we need this, or is it just a copy of mFattrs.usCodePage */
-#ifdef DEBUG_FONT_STRUCT_ALLOCS
- static unsigned long mRefCount;
-#endif
-
-#ifdef PERF_HASGLYPH_CHAR_MAP
- PRUint32* mHaveCheckedCharMap;
- PRUint32* mRepresentableCharMap;
-#endif
-};
-
-/**
- * nsFontSwitchCallback
- *
- * Font-switching callback function. Used by ResolveForwards() and
- * ResolveBackwards(). aFontSwitch points to a structure that gives
- * details about the current font needed to represent the current
- * substring. In particular, this struct contains a handler to the font
- * and some metrics of the font. These metrics may be different from
- * the metrics obtained via nsIFontMetrics.
- * Return PR_FALSE to stop the resolution of the remaining substrings.
- */
-
-struct nsFontSwitch {
- // Simple wrapper on top of nsFontOS2 for the moment
- // Could hold other attributes of the font
- nsFontOS2* mFont;
-};
-
-typedef PRBool (*PR_CALLBACK nsFontSwitchCallback)
- (const nsFontSwitch* aFontSwitch,
- const PRUnichar* aSubstring,
- PRUint32 aSubstringLength,
- void* aData);
-
-
-class nsFontMetricsOS2 : public nsIFontMetrics
-{
-public:
- NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
- NS_DECL_ISUPPORTS
-
- nsFontMetricsOS2();
- virtual ~nsFontMetricsOS2();
-
- NS_IMETHOD Init(const nsFont& aFont, nsIAtom* aLangGroup,
- nsIDeviceContext* aContext);
- NS_IMETHOD Destroy();
-
- NS_IMETHOD GetXHeight(nscoord& aResult);
- NS_IMETHOD GetSuperscriptOffset(nscoord& aResult);
- NS_IMETHOD GetSubscriptOffset(nscoord& aResult);
- NS_IMETHOD GetStrikeout(nscoord& aOffset, nscoord& aSize);
- NS_IMETHOD GetUnderline(nscoord& aOffset, nscoord& aSize);
- NS_IMETHOD GetHeight(nscoord& aHeight);
-#ifdef FONT_LEADING_APIS_V2
- NS_IMETHOD GetInternalLeading(nscoord &aLeading);
- NS_IMETHOD GetExternalLeading(nscoord &aLeading);
-#else
- NS_IMETHOD GetLeading(nscoord &aLeading);
- NS_IMETHOD GetNormalLineHeight(nscoord &aHeight);
-#endif //FONT_LEADING_APIS_V2
- NS_IMETHOD GetEmHeight(nscoord &aHeight);
- NS_IMETHOD GetEmAscent(nscoord &aAscent);
- NS_IMETHOD GetEmDescent(nscoord &aDescent);
- NS_IMETHOD GetMaxHeight(nscoord &aHeight);
- NS_IMETHOD GetMaxAscent(nscoord &aAscent);
- NS_IMETHOD GetMaxDescent(nscoord &aDescent);
- NS_IMETHOD GetMaxAdvance(nscoord &aAdvance);
- NS_IMETHOD GetLangGroup(nsIAtom** aLangGroup);
- NS_IMETHOD GetFontHandle(nsFontHandle &aHandle);
- NS_IMETHOD GetAveCharWidth(nscoord &aAveCharWidth);
- NS_IMETHOD GetSpaceWidth(nscoord &aSpaceWidth);
- // No known string length limits on OS/2
- virtual PRInt32 GetMaxStringLength() { return PR_INT32_MAX; }
-
- virtual nsresult
- ResolveForwards(HPS aPS,
- const PRUnichar* aString,
- PRUint32 aLength,
- nsFontSwitchCallback aFunc,
- void* aData);
-
- virtual nsresult
- ResolveBackwards(HPS aPS,
- const PRUnichar* aString,
- PRUint32 aLength,
- nsFontSwitchCallback aFunc,
- void* aData);
-
- nsFontOS2* FindFont(HPS aPS, PRUint32 aChar);
- nsFontOS2* FindUserDefinedFont(HPS aPS, PRUint32 aChar);
- nsFontOS2* FindLocalFont(HPS aPS, PRUint32 aChar);
- nsFontOS2* FindGenericFont(HPS aPS, PRUint32 aChar);
- virtual nsFontOS2* FindPrefFont(HPS aPS, PRUint32 aChar);
- virtual nsFontOS2* FindGlobalFont(HPS aPS, PRUint32 aChar);
-#ifdef USE_FREETYPE
- virtual nsFontOS2* FindSubstituteFont(HPS aPS, PRUint32 aChar)
- { return nsnull; };
-#endif
-
- nsFontOS2* LoadFont(HPS aPS, const nsAString& aName);
- nsFontOS2* LoadGenericFont(HPS aPS, PRUint32 aChar, const nsAString& aName);
- nsFontOS2* LoadUnicodeFont(HPS aPS, const nsAString& aName);
- static nsresult InitializeGlobalFonts();
-
- static nsTHashtable<GlobalFontEntry>* gGlobalFonts;
- static PLHashTable* gFamilyNames;
- static PRBool gSubstituteVectorFonts;
-#ifdef USE_FREETYPE
- static PRBool gUseFTFunctions;
-#endif
-
- nsCOMPtr<nsIAtom> mLangGroup;
- nsStringArray mFonts;
- PRInt32 mFontsIndex;
- nsVoidArray mLoadedFonts;
- nsFontOS2* mUnicodeFont;
- nsFontOS2* mWesternFont;
-
- PRInt32 mGenericIndex;
- nsString mGeneric;
- nsString mUserDefined;
-
- PRBool mTriedAllGenerics;
- PRBool mTriedAllPref;
- PRBool mIsUserDefined;
-
- int mConvertCodePage;
-
-protected:
- nsresult RealizeFont(void);
- PRBool GetVectorSubstitute(HPS aPS, const nsAString& aFacename,
- nsAString& aAlias);
- void FindUnicodeFont(HPS aPS);
- void FindWesternFont();
- nsFontOS2* SetFontHandle(HPS aPS, GlobalFontEntry* aEntry,
- nsMiniMetrics* aMetrics, PRBool aDoFakeEffects);
- PLHashTable* InitializeFamilyNames(void);
-
- nscoord mSuperscriptYOffset;
- nscoord mSubscriptYOffset;
- nscoord mStrikeoutPosition;
- nscoord mStrikeoutSize;
- nscoord mUnderlinePosition;
- nscoord mUnderlineSize;
- nscoord mExternalLeading;
- nscoord mInternalLeading;
- nscoord mEmHeight;
- nscoord mEmAscent;
- nscoord mEmDescent;
- nscoord mMaxHeight;
- nscoord mMaxAscent;
- nscoord mMaxDescent;
- nscoord mMaxAdvance;
- nscoord mSpaceWidth;
- nscoord mXHeight;
- nscoord mAveCharWidth;
-
- nsFontOS2 *mFontHandle;
- nsDeviceContextOS2 *mDeviceContext;
-
-#ifdef DEBUG_FONT_STRUCT_ALLOCS
- static unsigned long mRefCount;
-#endif
-};
-
-class nsFontEnumeratorOS2 : public nsIFontEnumerator
-{
-public:
- nsFontEnumeratorOS2();
- NS_DECL_ISUPPORTS
- NS_DECL_NSIFONTENUMERATOR
-
-protected:
-};
-
-#ifdef USE_FREETYPE
-typedef BOOL (APIENTRY * Ft2EnableFontEngine) (BOOL fEnable);
-
-class nsFontMetricsOS2FT : public nsFontMetricsOS2
-{
-public:
- virtual ~nsFontMetricsOS2FT();
-
- virtual nsresult
- ResolveForwards(HPS aPS,
- const PRUnichar* aString,
- PRUint32 aLength,
- nsFontSwitchCallback aFunc,
- void* aData);
-
- virtual nsresult
- ResolveBackwards(HPS aPS,
- const PRUnichar* aString,
- PRUint32 aLength,
- nsFontSwitchCallback aFunc,
- void* aData);
-
- virtual nsFontOS2* FindPrefFont(HPS aPS, PRUint32 aChar);
- virtual nsFontOS2* FindGlobalFont(HPS aPS, PRUint32 aChar);
- virtual nsFontOS2* FindSubstituteFont(HPS aPS, PRUint32 aChar);
-
- static Ft2EnableFontEngine pfnFt2EnableFontEngine;
-
- nsFontOS2* mSubstituteFont;
-
-protected:
- nsFontOS2* LocateFont(HPS aPS, PRUint32 aChar, PRInt32 & aCount);
-};
-
-typedef BOOL (APIENTRY * Ft2FontSupportsUnicodeChar1) (PSTR8 pName,
- PFATTRS pfatAttrs,
- BOOL isUnicode,
- UniChar ch);
-#ifdef USE_EXPANDED_FREETYPE_FUNCS
-typedef USHORT *LPWSTR;
-typedef BOOL (APIENTRY * Ft2QueryTextBoxW) (HPS hps, LONG lCount1,
- LPWSTR pchString,LONG lCount2,
- PPOINTL aptlPoints);
-typedef LONG (APIENTRY * Ft2CharStringPosAtW) (HPS hps, PPOINTL pptlStart,
- PRECTL prclRect, ULONG flOptions,
- LONG lCount, LPWSTR pchString,
- PLONG alAdx, ULONG fuWin32Options);
-#endif /* use_expanded_freetype_funcs */
-
-
-class nsFontOS2FT : public nsFontOS2
-{
-public:
- nsFontOS2FT(void);
- virtual ~nsFontOS2FT(void);
-
- virtual PRBool HasGlyph(HPS aPS, PRUint32 aChar);
-
- using nsFontOS2::GetWidth;
- using nsFontOS2::DrawString;
- virtual PRInt32 GetWidth(HPS aPS, const PRUnichar* aString, PRUint32 aLength);
- virtual void DrawString(HPS aPS, nsDrawingSurfaceOS2* aSurface,
- PRInt32 aX, PRInt32 aY,
- const PRUnichar* aString, PRUint32 aLength);
-
- PRBool IsSymbolFont() { return mFattrs.usCodePage == 65400; };
-
- static Ft2FontSupportsUnicodeChar1 pfnFt2FontSupportsUnicodeChar1;
-#ifdef USE_EXPANDED_FREETYPE_FUNCS
- static Ft2QueryTextBoxW pfnFt2QueryTextBoxW;
- static Ft2CharStringPosAtW pfnFt2CharStringPosAtW;
-#endif /* use_expanded_freetype_funcs */
-#ifdef DEBUG_FONT_STRUCT_ALLOCS
- static unsigned long mRefCount;
-#endif
-};
-
-// A "substitute font" to deal with missing glyphs -- see bug 6585
-// We now use transliteration+fallback to the REPLACEMENT CHAR +
-// HEX representation to handle this issue.
-class nsFontOS2Substitute : public nsFontOS2
-{
-public:
- nsFontOS2Substitute(nsFontOS2* aFont);
- virtual ~nsFontOS2Substitute(void);
-
- virtual PRBool HasGlyph(HPS aPS, PRUint32 ch)
- { return !IS_IN_BMP(ch) || IS_REPRESENTABLE(mRepresentableCharMap, ch); };
- virtual void SetRepresentable(PRUint32 ch)
- { if (IS_IN_BMP(ch)) SET_REPRESENTABLE(mRepresentableCharMap, ch); };
-
- using nsFontOS2::GetWidth;
- using nsFontOS2::DrawString;
- virtual PRInt32 GetWidth(HPS aPS, const PRUnichar* aString, PRUint32 aLength);
- virtual void DrawString(HPS aPS, nsDrawingSurfaceOS2* aSurface,
- PRInt32 aX, PRInt32 aY,
- const PRUnichar* aString, PRUint32 aLength);
-
-private:
- //We need to have a easily operatable charmap for substitute font
- PRUint32 mRepresentableCharMap[UCS2_MAP_LEN];
-};
-#endif /* use_freetype */
-
-#endif
deleted file mode 100644
--- a/gfx/src/os2/nsGfxDefs.cpp
+++ /dev/null
@@ -1,179 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Mozilla OS/2 libraries.
- *
- * The Initial Developer of the Original Code is
- * John Fairhurst, <john_fairhurst@iname.com>.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsGfxDefs.h"
-
-#ifdef DEBUG
- #include <string.h>
- #include <ctype.h>
-
-//DJ #include "nsLog.h"
-//DJ NS_IMPL_LOG_ENABLED (GFXLog)
-//DJ #define DPRINTF NS_LOG_PRINTF(GFXLog)
- #include <stdio.h>
- #define DPRINTF printf
-#else
- #include <stdio.h>
- #define DPRINTF printf
-#endif
-
-#include "nsDeviceContextSpecOS2.h"
-
-#include <stdlib.h>
-
-BOOL GetTextExtentPoint32(HPS aPS, const char* aString, int aLength, PSIZEL aSizeL)
-{
- BOOL rc = TRUE;
- POINTL ptls[5];
-
- aSizeL->cx = 0;
-
- while(aLength > 0 && rc == TRUE) {
- ULONG thislen = min(aLength, 512);
- rc = GFX (::GpiQueryTextBox(aPS, thislen, (PCH)aString, 5, ptls), FALSE);
- aSizeL->cx += ptls[TXTBOX_CONCAT].x;
- aLength -= thislen;
- aString += thislen;
- }
-
- aSizeL->cy = ptls[TXTBOX_TOPLEFT].y - ptls[TXTBOX_BOTTOMLEFT].y;
- return rc;
-}
-
-BOOL ExtTextOut(HPS aPS, int X, int Y, UINT fuOptions, const RECTL* lprc,
- const char* aString, unsigned int aLength, const int* pSpacing)
-{
- long rc = GPI_OK;
- POINTL ptl = {X, Y};
-
- GFX (::GpiMove(aPS, &ptl), FALSE);
-
- // GpiCharString has a max length of 512 chars at a time...
- while (aLength > 0 && rc == GPI_OK) {
- ULONG ulChunkLen = min(aLength, 512);
- if (pSpacing) {
- rc = GFX (::GpiCharStringPos(aPS, nsnull, CHS_VECTOR, ulChunkLen,
- (PCH)aString, (PLONG)pSpacing), GPI_ERROR);
- pSpacing += ulChunkLen;
- } else {
- rc = GFX (::GpiCharString(aPS, ulChunkLen, (PCH)aString), GPI_ERROR);
- }
- aLength -= ulChunkLen;
- aString += ulChunkLen;
- }
-
- if (rc == GPI_OK)
- return TRUE;
- else
- return FALSE;
-}
-
-static BOOL bIsDBCS;
-static BOOL bIsDBCSSet = FALSE;
-
-BOOL IsDBCS()
-{
- if (!bIsDBCSSet) {
- // the following lines of code determine whether the system is a DBCS country
- APIRET rc;
- COUNTRYCODE ctrycodeInfo = {0};
- CHAR achDBCSInfo[12] = {0}; // DBCS environmental vector
- ctrycodeInfo.country = 0; // current country
- ctrycodeInfo.codepage = 0; // current codepage
-
- rc = DosQueryDBCSEnv(sizeof(achDBCSInfo), &ctrycodeInfo, achDBCSInfo);
- if (rc == NO_ERROR)
- {
- // NON-DBCS countries will have four bytes in the first four bytes of the
- // DBCS environmental vector
- if (achDBCSInfo[0] != 0 || achDBCSInfo[1] != 0 ||
- achDBCSInfo[2] != 0 || achDBCSInfo[3] != 0)
- {
- bIsDBCS = TRUE;
- }
- else
- {
- bIsDBCS = FALSE;
- }
- } else {
- bIsDBCS = FALSE;
- } /* endif */
- bIsDBCSSet = TRUE;
- } /* endif */
- return bIsDBCS;
-}
-
-
-
-
-// Module-level data ---------------------------------------------------------
-#ifdef DEBUG
-void DEBUG_LogErr(long ReturnCode, const char* ErrorExpression,
- const char* FileName, const char* FunctionName, long LineNum)
-{
- char TempBuf [300];
-
- strcpy (TempBuf, ErrorExpression);
- char* APIName = TempBuf;
-
- char* ch = strstr (APIName , "("); // Find start of function parameter list
- if (ch != NULL) // Opening parenthesis found - it is a function
- {
- while (isspace (*--ch)) {} // Remove whitespaces before opening parenthesis
- *++ch = '\0';
-
- if (APIName [0] == ':' && APIName [1] == ':') // Remove global scope operator
- APIName += 2;
-
- while (isspace (*APIName)) // Remove spaces before function name
- APIName++;
- }
-
-
- USHORT ErrorCode = ERRORIDERROR (::WinGetLastError(0));
-
- printf("GFX_Err: %s = 0x%X, 0x%X (%s - %s, line %ld)\n", APIName, ReturnCode,
- ErrorCode, FileName, FunctionName, LineNum);
-}
-#endif
-
-void PMERROR( const char *api)
-{
- ERRORID eid = ::WinGetLastError(0);
- USHORT usError = ERRORIDERROR(eid);
- DPRINTF ( "%s failed, error = 0x%X\n", api, usError);
-}
-
deleted file mode 100644
--- a/gfx/src/os2/nsGfxDefs.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Mozilla OS/2 libraries.
- *
- * The Initial Developer of the Original Code is
- * John Fairhurst, <john_fairhurst@iname.com>.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef _nsgfxdefs_h
-#define _nsgfxdefs_h
-
-// nsGfxDefs.h - common includes etc. for gfx library
-
-#include "nscore.h"
-
-#define INCL_PM
-#define INCL_DOS
-#define INCL_DOSERRORS
-#define INCL_DEV
-#include <os2.h>
-#include "prlog.h"
-#include "nsHashtable.h"
-
-#include <uconv.h> // XXX hack XXX
-
-#define COLOR_CUBE_SIZE 216
-
-void PMERROR(const char *str);
-
-// Wrapper code for all OS/2 system calls to check the return code for error condition in debug build.
-// Could be used like this:
-//
-// HDC hdc = GFX (::GpiQueryDevice (ps), HDC_ERROR);
-// GFX (::GpiAssociate (mPrintPS, 0), FALSE);
-// return GFX (::GpiDestroyPS (mPrintPS), FALSE);
-
-#ifdef DEBUG
- extern void DEBUG_LogErr(long ReturnCode, const char* ErrorExpression,
- const char* FileName, const char* FunctionName,
- long LineNum);
-
- inline long CheckSuccess(long ReturnCode, long SuccessCode,
- const char* ErrorExpression, const char* FileName,
- const char* FunctionName, long LineNum)
- {
- if (ReturnCode != SuccessCode) {
- DEBUG_LogErr(ReturnCode, ErrorExpression, FileName, FunctionName, LineNum);
- }
- return ReturnCode;
- }
-
- #define CHK_SUCCESS(ReturnCode, SuccessCode) \
- CheckSuccess(ReturnCode, SuccessCode, #ReturnCode, __FILE__, \
- __FUNCTION__, __LINE__)
-
- inline long CheckFailure(long ReturnCode, long ErrorCode,
- const char* ErrorExpression, const char* FileName,
- const char* FunctionName, long LineNum)
- {
- if (ReturnCode == ErrorCode) {
- DEBUG_LogErr(ReturnCode, ErrorExpression, FileName, FunctionName, LineNum);
- }
- return ReturnCode;
- }
-
-/* #define CHK_FAIL(ReturnCode, ErrorCode) \ */
- #define GFX(ReturnCode, ErrorCode) \
- CheckFailure(ReturnCode, ErrorCode, #ReturnCode, __FILE__, \
- __FUNCTION__, __LINE__)
-
-#else // Retail build
- #define CHK_SUCCESS(ReturnCode, SuccessCode) ReturnCode
-/* #define CHK_FAIL(ReturnCode, ErrorCode) ReturnCode */
- #define GFX(ReturnCode, ErrorCode) ReturnCode
-#endif
-
-class nsString;
-class nsIDeviceContext;
-
-
-BOOL GetTextExtentPoint32(HPS aPS, const char* aString, int aLength, PSIZEL aSizeL);
-BOOL ExtTextOut(HPS aPS, int X, int Y, UINT fuOptions, const RECTL* lprc,
- const char* aString, unsigned int aLength, const int* pDx);
-
-BOOL IsDBCS();
-
-#ifndef min
-#define min(a,b) (((a) < (b)) ? (a) : (b))
-#endif
-
-#define MK_RGB(r,g,b) ((r) * 65536) + ((g) * 256) + (b)
-
-#ifdef DEBUG
-extern PRLogModuleInfo *gGFXOS2LogModule;
-#endif
-
-#endif
deleted file mode 100644
--- a/gfx/src/os2/nsGfxFactoryOS2.cpp
+++ /dev/null
@@ -1,327 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Christopher Blizzard.
- * Portions created by the Initial Developer are Copyright (C) 2000
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Christopher Blizzzard <blizzard@mozilla.org>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsIGenericFactory.h"
-#include "nsIModule.h"
-#include "nsCOMPtr.h"
-#include "nsGfxCIID.h"
-
-#include "nsBlender.h"
-#include "nsFontMetricsOS2.h"
-#include "nsRenderingContextOS2.h"
-#include "nsScriptableRegion.h"
-#include "nsDeviceContextOS2.h"
-#include "nsImageOS2.h"
-#include "nsRegionOS2.h"
-#include "gfxImageFrame.h"
-#include "nsFontList.h"
-#include "nsIServiceManager.h"
-#include "prenv.h"
-#include "nsOS2Uni.h"
-#include "nsPaletteOS2.h"
-
-// objects that just require generic constructors
-
-#if !defined(USE_FREETYPE)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontMetricsOS2)
-#endif
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextOS2)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsRenderingContextOS2)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageOS2)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsBlender)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsRegionOS2)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontEnumeratorOS2)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontList)
-NS_GENERIC_FACTORY_CONSTRUCTOR(gfxImageFrame)
-
-#ifdef USE_FREETYPE
-// Can't include os2win.h, since it screws things up. So definitions go here.
-typedef ULONG HKEY;
-#define HKEY_LOCAL_MACHINE 0xFFFFFFEFL
-#define HKEY_CURRENT_USER 0xFFFFFFEEL
-#define READ_CONTROL 0x00020000
-#define KEY_QUERY_VALUE 0x0001
-#define KEY_ENUMERATE_SUB_KEYS 0x0008
-#define KEY_NOTIFY 0x0010
-#define KEY_READ READ_CONTROL | KEY_QUERY_VALUE | \
- KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY
-#define ERROR_SUCCESS 0L
-
-static PRBool
-UseFTFunctions()
-{
- static PRBool init = PR_FALSE;
- if (!init) {
- init = PR_TRUE;
-
- // For now, since this is somewhat experimental, we'll check for an
- // environment variable, rather than making this the default for anyone
- // that uses the FT2LIB.
- char* useFT = PR_GetEnv("MOZILLA_USE_EXTENDED_FT2LIB");
- if (useFT == nsnull || *useFT == '\0' || stricmp(useFT, "t") != 0) {
- return PR_FALSE;
- }
-
- // Test for availability of registry functions and query their addresses
- APIRET rc;
- HMODULE hmod = NULLHANDLE;
- char LoadError[CCHMAXPATH];
- rc = DosLoadModule(LoadError, CCHMAXPATH, "REGISTRY", &hmod);
- if (rc != NO_ERROR) {
- NS_WARNING("REGISTRY.DLL could not be loaded");
- return PR_FALSE;
- }
- LONG _System (*APIENTRY RegOpenKeyEx)(HKEY, const char*, ULONG, ULONG,
- HKEY* );
- LONG _System (*APIENTRY RegQueryValueEx)(HKEY, const char*, ULONG*, ULONG*,
- UCHAR*, ULONG*);
-
- rc = DosQueryProcAddr(hmod, 0L, "RegOpenKeyExA", (PFN*)&RegOpenKeyEx);
- rc += DosQueryProcAddr(hmod, 0L, "RegQueryValueExA", (PFN*)&RegQueryValueEx);
- if (rc != NO_ERROR) {
- NS_WARNING("Registry function(s) were not found in REGISTRY.DLL");
- DosFreeModule(hmod);
- return PR_FALSE;
- }
-
- // Is FT2LIB enabled?
- HKEY key;
- LONG result = RegOpenKeyEx(HKEY_CURRENT_USER,
- "Software\\Innotek\\InnoTek Font Engine", 0,
- KEY_READ, &key);
- if (result != ERROR_SUCCESS) {
- result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- "Software\\Innotek\\InnoTek Font Engine", 0,
- KEY_READ, &key);
- if (result != ERROR_SUCCESS) {
- DosFreeModule(hmod);
- return PR_FALSE;
- }
- }
-
- ULONG value;
- ULONG length = sizeof(value);
- result = RegQueryValueEx(key, "Enabled", NULL, NULL, (UCHAR*)&value,
- &length);
- if (result != ERROR_SUCCESS || value == 0) {
- // check if "Innotek Font Engine" is disabled (value == 0)
- DosFreeModule(hmod);
- return PR_FALSE;
- }
-
- // Is FT2LIB enabled for this app?
- PPIB ppib;
- PTIB ptib;
- char buffer[CCHMAXPATH], name[_MAX_FNAME], ext[_MAX_EXT], keystr[256];
- DosGetInfoBlocks(&ptib, &ppib);
- DosQueryModuleName(ppib->pib_hmte, CCHMAXPATH, buffer);
- _splitpath(buffer, NULL, NULL, name, ext);
- strcpy(keystr, "Software\\Innotek\\InnoTek Font Engine\\Applications\\");
- strcat(keystr, name);
- strcat(keystr, ext);
- result = RegOpenKeyEx(HKEY_CURRENT_USER, keystr, 0, KEY_READ, &key);
- if (result != ERROR_SUCCESS) {
- result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, keystr, 0, KEY_READ, &key);
- if (result != ERROR_SUCCESS) {
- DosFreeModule(hmod);
- return PR_FALSE;
- }
- }
- result = RegQueryValueEx(key, "Enabled", NULL, NULL, (UCHAR*)&value,
- &length);
- if (result != ERROR_SUCCESS || value == 0) {
- // check if FT2LIB is disabled for our application (value == 0)
- DosFreeModule(hmod);
- return PR_FALSE;
- }
-
- // REGISTRY.DLL use ends here
- DosFreeModule(hmod);
-
- // Load lib and functions
- rc = DosLoadModule(LoadError, 0, "FT2LIB", &hmod);
- if (rc == NO_ERROR) {
- rc = DosQueryProcAddr(hmod, 0, "Ft2EnableFontEngine",
- (PFN*)&nsFontMetricsOS2FT::pfnFt2EnableFontEngine);
- if (rc == NO_ERROR) {
- DosQueryProcAddr(hmod, 0, "Ft2FontSupportsUnicodeChar1",
- (PFN*)&nsFontOS2FT::pfnFt2FontSupportsUnicodeChar1);
-#ifdef USE_EXPANDED_FREETYPE_FUNCS
- DosQueryProcAddr(hmod, 0, "Ft2QueryTextBoxW",
- (PFN*)&nsFontOS2FT::pfnFt2QueryTextBoxW);
- DosQueryProcAddr(hmod, 0, "Ft2CharStringPosAtW",
- (PFN*)&nsFontOS2FT::pfnFt2CharStringPosAtW);
-#endif /* use_expanded_freetype_funcs */
- NS_WARNING("*** Now using Freetype functions ***");
- nsFontMetricsOS2::gUseFTFunctions = PR_TRUE;
- }
- DosFreeModule(hmod);
- }
- }
- return nsFontMetricsOS2::gUseFTFunctions;
-}
-
-static NS_IMETHODIMP
-nsFontMetricsOS2Constructor(nsISupports* aOuter, REFNSIID aIID, void** aResult)
-{
- *aResult = nsnull;
-
- if (aOuter)
- return NS_ERROR_NO_AGGREGATION;
-
- nsFontMetricsOS2* result;
- if (UseFTFunctions())
- result = new nsFontMetricsOS2FT();
- else
- result = new nsFontMetricsOS2();
-
- if (! result)
- return NS_ERROR_OUT_OF_MEMORY;
-
- nsresult rv;
- NS_ADDREF(result);
- rv = result->QueryInterface(aIID, aResult);
- NS_RELEASE(result);
- return rv;
-}
-#endif /* use_freetype */
-
-static NS_IMETHODIMP
-nsScriptableRegionConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
-{
- nsresult rv;
-
- nsIScriptableRegion *inst = NULL;
-
- if ( !aResult )
- {
- rv = NS_ERROR_NULL_POINTER;
- return rv;
- }
- *aResult = nsnull;
- if (aOuter)
- {
- rv = NS_ERROR_NO_AGGREGATION;
- return rv;
- }
- // create an nsRegionOS2 and get the scriptable region from it
- nsCOMPtr <nsIRegion> rgn;
- NS_NEWXPCOM(rgn, nsRegionOS2);
- nsCOMPtr<nsIScriptableRegion> scriptableRgn;
- if (rgn != nsnull)
- {
- scriptableRgn = new nsScriptableRegion(rgn);
- inst = scriptableRgn;
- }
- if (!inst)
- {
- rv = NS_ERROR_OUT_OF_MEMORY;
- return rv;
- }
- NS_ADDREF(inst);
- // release our variable above now that we have created our owning
- // reference - we don't want this to go out of scope early!
- scriptableRgn = nsnull;
- rv = inst->QueryInterface(aIID, aResult);
- NS_RELEASE(inst);
-
- return rv;
-}
-
-static const nsModuleComponentInfo components[] =
-{
- { "OS/2 Font Metrics",
- NS_FONT_METRICS_CID,
- // "@mozilla.org/gfx/font_metrics/gtk;1",
- "@mozilla.org/gfx/fontmetrics;1",
- nsFontMetricsOS2Constructor },
- { "OS/2 Device Context",
- NS_DEVICE_CONTEXT_CID,
- // "@mozilla.org/gfx/device_context/gtk;1",
- "@mozilla.org/gfx/devicecontext;1",
- nsDeviceContextOS2Constructor },
- { "OS/2 Rendering Context",
- NS_RENDERING_CONTEXT_CID,
- // "@mozilla.org/gfx/rendering_context/gtk;1",
- "@mozilla.org/gfx/renderingcontext;1",
- nsRenderingContextOS2Constructor },
- { "OS/2 Image",
- NS_IMAGE_CID,
- // "@mozilla.org/gfx/image/gtk;1",
- "@mozilla.org/gfx/image;1",
- nsImageOS2Constructor },
- { "OS/2 Region",
- NS_REGION_CID,
- "@mozilla.org/gfx/region/gtk;1",
- nsRegionOS2Constructor },
- { "Scriptable Region",
- NS_SCRIPTABLE_REGION_CID,
- // "@mozilla.org/gfx/scriptable_region;1",
- "@mozilla.org/gfx/region;1",
- nsScriptableRegionConstructor },
- { "Blender",
- NS_BLENDER_CID,
- // "@mozilla.org/gfx/blender;1",
- "@mozilla.org/gfx/blender;1",
- nsBlenderConstructor },
- { "OS2 Font Enumerator",
- NS_FONT_ENUMERATOR_CID,
- // "@mozilla.org/gfx/font_enumerator/gtk;1",
- "@mozilla.org/gfx/fontenumerator;1",
- nsFontEnumeratorOS2Constructor },
- { "Font List",
- NS_FONTLIST_CID,
- // "@mozilla.org/gfx/fontlist;1"
- NS_FONTLIST_CONTRACTID,
- nsFontListConstructor },
- { "windows image frame",
- GFX_IMAGEFRAME_CID,
- "@mozilla.org/gfx/image/frame;2",
- gfxImageFrameConstructor, },
-};
-
-PR_STATIC_CALLBACK(void)
-nsGfxOS2ModuleDtor(nsIModule *self)
-{
- OS2Uni::FreeUconvObjects();
- nsPaletteOS2::FreeGlobalPalette();
-// nsRenderingContextOS2::Shutdown();
-}
-
-NS_IMPL_NSGETMODULE_WITH_DTOR(nsGfxOS2Module, components, nsGfxOS2ModuleDtor)
-
deleted file mode 100644
--- a/gfx/src/os2/nsIRenderingContextOS2.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef nsIRenderingContextOS2_h___
-#define nsIRenderingContextOS2_h___
-
-#include "nsIRenderingContext.h"
-#include <os2.h>
-
-// IID for the nsIRenderingContext interface
-#define NS_IRENDERING_CONTEXT_OS2_IID \
-{ 0x0fcde820, 0x8ae2, 0x11d2, \
-{ 0xa8, 0x48, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } }
-
-// RenderingContextWin interface
-class nsIRenderingContextOS2 : public nsISupports
-{
-public:
- NS_DECLARE_STATIC_IID_ACCESSOR(NS_IRENDERING_CONTEXT_OS2_IID)
- /**
- * Create a new drawing surface to represent an HPS.
- * @param aPS Windows HPS.
- * @param aSurface out parameter for new drawing surface
- * @result error status
- */
- NS_IMETHOD CreateDrawingSurface(HPS aPS, nsIDrawingSurface* &aSurface, nsIWidget *aWidget) = 0;
-};
-
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIRenderingContextOS2,
- NS_IRENDERING_CONTEXT_OS2_IID)
-
-#endif /* nsIRenderingContextOS2_h___ */
deleted file mode 100644
--- a/gfx/src/os2/nsImageOS2.cpp
+++ /dev/null
@@ -1,1012 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Mozilla OS/2 libraries.
- *
- * The Initial Developer of the Original Code is
- * John Fairhurst, <john_fairhurst@iname.com>.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK *****
- *
- * This Original Code has been modified by IBM Corporation. Modifications made by IBM
- * described herein are Copyright (c) International Business Machines Corporation, 2000.
- * Modifications to Mozilla code or documentation identified per MPL Section 3.3
- *
- * Date Modified by Description of modification
- * 05/11/2000 IBM Corp. Make it look more like Windows.
- */
-
-#include "nsGfxDefs.h"
-#include <stdlib.h>
-
-#include "nsImageOS2.h"
-#include "nsRenderingContextOS2.h"
-#include "nsDeviceContextOS2.h"
-#include "imgScaler.h"
-
-#define MAX_BUFFER_WIDTH 128
-#define MAX_BUFFER_HEIGHT 128
-
-#ifdef XP_OS2_VACPP
-// Needed to zero the stack since there is an uninitialized var in the engine
-// If you find that printing bitmaps with transparency results in black images then
-// take off the # define and use for all OS2 compilers
-// This was discovered when the temp bitmap bit depth used in images2::Draw was changed
-// from 8 to 24. It worked in debug but failed in retail. Investigation revealed GpiErase
-// was failing due to a function receiving an uninitialized variable and the stack had invalid
-// values (for retail). This function will zero the stack and return leaving a clean stack.
-// A parameter is used to ensure the optimizer will compile the code. Make sure the parameter
-// is not larger than the buff size
-// The OS2 defect 272592 will fix this in future releases of the engine
-extern "C" int zeroStack(int index)
-{
- #define CLEAR_BUF_SIZE 1024
- BYTE buf[CLEAR_BUF_SIZE];
- memset(buf, 0, CLEAR_BUF_SIZE * sizeof(BYTE));
- return buf[index];
-}
-#else
-#define zeroStack(x)
-#endif
-
-struct MONOBITMAPINFO
-{
- BITMAPINFOHEADER2 bmpInfo;
- RGB2 argbColor [2];
-
- operator PBITMAPINFO2 () { return (PBITMAPINFO2) &bmpInfo; }
- operator PBITMAPINFOHEADER2 () { return &bmpInfo; }
-
- MONOBITMAPINFO( PBITMAPINFO2 pBI)
- {
- memcpy( &bmpInfo, pBI, sizeof( BITMAPINFOHEADER2));
- bmpInfo.cBitCount = 1;
-
- argbColor [0].bRed = 0;
- argbColor [0].bGreen = 0;
- argbColor [0].bBlue = 0;
- argbColor [0].fcOptions = 0;
- argbColor [1].bRed = 255;
- argbColor [1].bGreen = 255;
- argbColor [1].bBlue = 255;
- argbColor [1].fcOptions = 0;
- }
-};
-
-
-PRUint8 nsImageOS2::gBlenderLookup [65536]; // Global table for fast alpha blending
-PRBool nsImageOS2::gBlenderReady = PR_FALSE;
-
-
-
-NS_IMPL_ISUPPORTS1(nsImageOS2, nsIImage)
-
-//------------------------------------------------------------
-nsImageOS2::nsImageOS2()
-: mInfo(0)
-, mDeviceDepth(0)
-, mRowBytes(0)
-, mImageBits(0)
-, mIsOptimized(PR_FALSE)
-, mColorMap(0)
-, mDecodedRect()
-, mAlphaBits(0)
-, mAlphaDepth(0)
-, mARowBytes(0)
-{
- if (gBlenderReady != PR_TRUE)
- BuildBlenderLookup ();
-}
-
-nsImageOS2::~nsImageOS2()
-{
- CleanUp(PR_TRUE);
-}
-
-nsresult nsImageOS2::Init( PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth,
- nsMaskRequirements aMaskRequirements)
-{
- // gfxIImageFrame only allows one init of nsImageOS2
-
- // (copying windows code - what about monochrome? Oh well.)
- NS_ASSERTION( aDepth == 24 || aDepth == 8, "Bad image depth");
-
- // Work out size of bitmap to allocate
- mRowBytes = RASWIDTH(aWidth,aDepth);
-
- mImageBits = new PRUint8 [ aHeight * mRowBytes ];
-
- // Set up bitmapinfo header
- int cols = -1;
- if( aDepth == 8) cols = COLOR_CUBE_SIZE;
- else if( aDepth <= 32) cols = 0;
-
- int szStruct = sizeof( BITMAPINFOHEADER2) + cols * sizeof( RGB2);
-
- mInfo = (PBITMAPINFO2) calloc( szStruct, 1);
- mInfo->cbFix = sizeof( BITMAPINFOHEADER2);
- mInfo->cx = aWidth;
- mInfo->cy = aHeight;
- mInfo->cPlanes = 1;
- mInfo->cBitCount = (USHORT) aDepth;
-
- // We can't set up the bitmap colour table yet.
-
- // init color map.
- // XP will update the color map & then call ImageUpdated(), at which
- // point we can change the color table in the bitmapinfo.
- if( aDepth == 8)
- {
- mColorMap = new nsColorMap;
- mColorMap->NumColors = COLOR_CUBE_SIZE;
- mColorMap->Index = new PRUint8[3 * mColorMap->NumColors];
- }
-
- // Allocate stuff for mask bitmap
- if( aMaskRequirements != nsMaskRequirements_kNoMask)
- {
- if( aMaskRequirements == nsMaskRequirements_kNeeds1Bit)
- {
- mAlphaDepth = 1;
- }
- else
- {
- NS_ASSERTION( nsMaskRequirements_kNeeds8Bit == aMaskRequirements,
- "unexpected mask depth");
- mAlphaDepth = 8;
- }
-
- // 32-bit align each row
- mARowBytes = RASWIDTH (aWidth, mAlphaDepth);
-
- mAlphaBits = new PRUint8 [ aHeight * mARowBytes];
- }
-
- return NS_OK;
-}
-
-void nsImageOS2::CleanUp(PRBool aCleanUpAll)
-{
- // OS2TODO to handle aCleanUpAll param
-
- if( mImageBits) {
- delete [] mImageBits;
- mImageBits = 0;
- }
- if( mInfo) {
- free( mInfo);
- mInfo = 0;
- }
- if( mColorMap) {
- if( mColorMap->Index)
- delete [] mColorMap->Index;
- delete mColorMap;
- mColorMap = 0;
- }
- if( mAlphaBits) {
- delete [] mAlphaBits;
- mAlphaBits = 0;
- }
-}
-
-void nsImageOS2::ImageUpdated( nsIDeviceContext *aContext,
- PRUint8 aFlags, nsRect *aUpdateRect)
-{
- mDecodedRect.UnionRect(mDecodedRect, *aUpdateRect);
-
- if (!aContext) {
- return;
- } /* endif */
- // This is where we can set the bitmap colour table, as the XP code
- // has filled in the colour map. It would be cute to be able to alias
- // the bitmap colour table as the mColorMap->Index thing, but the formats
- // are unfortunately different. Rats.
-
- aContext->GetDepth( mDeviceDepth);
-
- if( (aFlags & nsImageUpdateFlags_kColorMapChanged) && mInfo->cBitCount == 8)
- {
- PRGB2 pBmpEntry = mInfo->argbColor;
- PRUint8 *pMapByte = mColorMap->Index;
-
- for( PRInt32 i = 0; i < mColorMap->NumColors; i++, pBmpEntry++)
- {
- pBmpEntry->bRed = *pMapByte++;
- pBmpEntry->bGreen = *pMapByte++;
- pBmpEntry->bBlue = *pMapByte++;
- }
- }
- else if( aFlags & nsImageUpdateFlags_kBitsChanged)
- {
- // jolly good...
- }
-}
-
-/** ---------------------------------------------------
- * See documentation in nsIImage.h
- */
-PRBool nsImageOS2::GetIsImageComplete() {
- return mInfo &&
- mDecodedRect.x == 0 &&
- mDecodedRect.y == 0 &&
- mDecodedRect.width == mInfo->cx &&
- mDecodedRect.height == mInfo->cy;
-}
-
-void nsImageOS2::BuildBlenderLookup (void)
-{
- for (int y = 0 ; y < 256 ; y++)
- for (int x = 0 ; x < 256 ; x++)
- gBlenderLookup [y * 256 + x] = y * x / 255;
-
- gBlenderReady = PR_TRUE;
-}
-
-nsresult nsImageOS2::Draw( nsIRenderingContext &aContext,
- nsIDrawingSurface* aSurface,
- PRInt32 aX, PRInt32 aY,
- PRInt32 aWidth, PRInt32 aHeight)
-{
- return Draw( aContext, aSurface,
- 0, 0, mInfo->cx, mInfo->cy,
- aX, aY, aWidth, aHeight);
-}
-
-/** ---------------------------------------------------
- * This is a helper routine to do the blending for the Draw method
- */
-void nsImageOS2 :: DrawComposited24(unsigned char *aBits,
- PRUint8 *aImageRGB, PRUint32 aStrideRGB,
- PRUint8 *aImageAlpha, PRUint32 aStrideAlpha,
- int aWidth, int aHeight)
-{
- PRInt32 targetRowBytes = ((aWidth * 3) + 3) & ~3;
-
- for (int y = 0; y < aHeight; y++) {
- unsigned char *targetRow = aBits + y * targetRowBytes;
- unsigned char *imageRow = aImageRGB + y * aStrideRGB;
- unsigned char *alphaRow = aImageAlpha + y * aStrideAlpha;
-
- for (int x = 0; x < aWidth;
- x++, targetRow += 3, imageRow += 3, alphaRow++) {
- unsigned alpha = *alphaRow;
- MOZ_BLEND(targetRow[0], targetRow[0], imageRow[0], alpha);
- MOZ_BLEND(targetRow[1], targetRow[1], imageRow[1], alpha);
- MOZ_BLEND(targetRow[2], targetRow[2], imageRow[2], alpha);
- }
- }
-}
-
-NS_IMETHODIMP
-nsImageOS2 :: Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface,
- PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
- PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight)
-{
- nsresult rv = NS_OK;
-
- PRInt32 origSHeight = aSHeight, origDHeight = aDHeight;
- PRInt32 origSWidth = aSWidth, origDWidth = aDWidth;
-
- if (mInfo == nsnull || aSWidth < 0 || aDWidth < 0 || aSHeight < 0 || aDHeight < 0)
- return NS_ERROR_FAILURE;
-
- if (0 == aSWidth || 0 == aDWidth || 0 == aSHeight || 0 == aDHeight)
- return NS_OK;
-
- // limit the size of the blit to the amount of the image read in
- PRInt32 aSX2 = aSX + aSWidth;
-
- if (aSX2 > mDecodedRect.XMost())
- aSX2 = mDecodedRect.XMost();
-
- if (aSX < mDecodedRect.x) {
- aDX += (mDecodedRect.x - aSX) * origDWidth / origSWidth;
- aSX = mDecodedRect.x;
- }
-
- aSWidth = aSX2 - aSX;
- aDWidth -= (origSWidth - aSWidth) * origDWidth / origSWidth;
-
- if (aSWidth <= 0 || aDWidth <= 0)
- return NS_OK;
-
- PRInt32 aSY2 = aSY + aSHeight;
-
- if (aSY2 > mDecodedRect.YMost())
- aSY2 = mDecodedRect.YMost();
-
- if (aSY < mDecodedRect.y) {
- aDY += (mDecodedRect.y - aSY) * origDHeight / origSHeight;
- aSY = mDecodedRect.y;
- }
-
- aSHeight = aSY2 - aSY;
- aDHeight -= (origSHeight - aSHeight) * origDHeight / origSHeight;
-
- if (aSHeight <= 0 || aDHeight <= 0)
- return NS_OK;
-
- nsDrawingSurfaceOS2 *surf = (nsDrawingSurfaceOS2*) aSurface;
-
-
- nsRect trect( aDX, aDY, aDWidth, aDHeight);
- RECTL rcl;
- surf->NS2PM_ININ (trect, rcl);
-
- // Set up blit coord array
- POINTL aptl[ 4] = { { rcl.xLeft, rcl.yBottom }, // TLL
- { rcl.xRight, rcl.yTop }, // TUR
- { aSX, mInfo->cy - (aSY + aSHeight) }, // SLL
- { aSX + aSWidth, mInfo->cy - aSY } }; // SUR
-
- PRBool fPrinting = PR_FALSE;
- nsCOMPtr<nsIDeviceContext> context;
- aContext.GetDeviceContext(*getter_AddRefs(context));
- if (((nsDeviceContextOS2 *)context.get())->mPrintDC) {
- fPrinting = PR_TRUE;
- }
-
- if( mAlphaDepth == 0)
- {
- // no transparency, just blit it
- GFX (::GpiDrawBits (surf->GetPS (), mImageBits, mInfo, 4, aptl, ROP_SRCCOPY, BBO_IGNORE), GPI_ERROR);
- }
- else if( mAlphaDepth == 1)
- {
- if (!fPrinting) {
- // > The transparent areas of the mask are coloured black (0).
- // > the transparent areas of the pixmap are coloured black (0).
- // > Note this does *not* mean that all black pels are transparent!
- // >
- // > Thus all we need to do is AND the mask onto the target, taking
- // > out pels that are not transparent, and then OR the image onto
- // > the target.
- // >
- // > For monochrome bitmaps GPI replaces 1 with IMAGEBUNDLE foreground
- // > color and 0 with background color. To make this work with ROP_SRCAND
- // > we set foreground to black and background to white. Thus AND with
- // > 1 (opaque) in mask maps to AND with IMAGEBUNDLE foreground (which is 0)
- // > always gives 0 - clears opaque region to zeros.
-
- // Apply mask to target, clear pels we will fill in from the image
- MONOBITMAPINFO MaskBitmapInfo (mInfo);
- GFX (::GpiDrawBits (surf->GetPS (), mAlphaBits, MaskBitmapInfo, 4, aptl, ROP_SRCAND, BBO_IGNORE), GPI_ERROR);
-
- // Now combine image with target
- GFX (::GpiDrawBits (surf->GetPS (), mImageBits, mInfo, 4, aptl, ROP_SRCPAINT, BBO_IGNORE), GPI_ERROR);
- } else {
- // Find the compatible device context and create a memory one
- HDC hdcCompat = GFX (::GpiQueryDevice (surf->GetPS ()), HDC_ERROR);
-
- rv = NS_ERROR_FAILURE;
-
- // create non-inclusive rect for GpiBitBlt
- RECTL dest;
- surf->NS2PM_INEX (trect, dest);
-
- DEVOPENSTRUC dop = { 0, 0, 0, 0, 0 };
- HDC MemDC = ::DevOpenDC( (HAB)0, OD_MEMORY, "*", 5, (PDEVOPENDATA) &dop, hdcCompat);
-
- if( MemDC != DEV_ERROR )
- {
- // create the PS
- SIZEL sizel = { 0, 0 };
- HPS MemPS = GFX (::GpiCreatePS (0, MemDC, &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC), GPI_ERROR);
-
- if( MemPS != GPI_ERROR )
- {
- GFX (::GpiCreateLogColorTable (MemPS, 0, LCOLF_RGB, 0, 0, 0), FALSE);
-
- // now create a bitmap of the right size
- HBITMAP hMemBmp;
- BITMAPINFOHEADER2 bihMem = { 0 };
-
- bihMem.cbFix = sizeof (BITMAPINFOHEADER2);
- bihMem.cx = aSWidth;
- bihMem.cy = aSHeight;
- bihMem.cPlanes = 1;
- LONG lBitCount = 0;
- GFX (::DevQueryCaps( hdcCompat, CAPS_COLOR_BITCOUNT, 1, &lBitCount), FALSE);
- lBitCount = 24; // For printing
- bihMem.cBitCount = lBitCount;
-
- hMemBmp = GFX (::GpiCreateBitmap (MemPS, &bihMem, 0, 0, 0), GPI_ERROR);
-
- if( hMemBmp != GPI_ERROR )
- {
- GFX (::GpiSetBitmap (MemPS, hMemBmp), HBM_ERROR);
- zeroStack(10);
- GpiErase(MemPS);
-
- // Now combine image with target
- // Set up blit coord array
- POINTL aptlNew[ 4] = { { 0, 0 }, // TLL
- { bihMem.cx, bihMem.cy }, // TUR
- { aSX, mInfo->cy - (aSY + aSHeight) }, // SLL
- { aSX + aSWidth+1, mInfo->cy - aSY+1 } }; // SUR
-
- // Apply mask to target, clear pels we will fill in from the image
- MONOBITMAPINFO MaskBitmapInfo (mInfo);
- GFX (::GpiDrawBits (MemPS, mAlphaBits, MaskBitmapInfo, 4, aptlNew, ROP_SRCAND, BBO_IGNORE), GPI_ERROR);
-
- // Now combine image with target
- GFX (::GpiDrawBits (MemPS, mImageBits, mInfo, 4, aptlNew, ROP_SRCPAINT, BBO_IGNORE), GPI_ERROR);
-
- // Transfer bitmap from memory bitmap back to device
- POINTL aptlMemToDev [4] = { {dest.xLeft, dest.yBottom}, // TLL - device (Dx1, Dy2)
- {dest.xRight, dest.yTop}, // TUR - device (Dx2, Dy1)
- {0, 0}, // SLL - mem bitmap (0, 0)
- {bihMem.cx, bihMem.cy} }; // SUR - mem bitmap (cx, cy)
-
- GFX (::GpiBitBlt (surf->GetPS (), MemPS, 4, aptlMemToDev, ROP_SRCCOPY, BBO_IGNORE), GPI_ERROR);
-
- rv = NS_OK;
-
- GFX (::GpiSetBitmap (MemPS, NULLHANDLE), HBM_ERROR);
- GFX (::GpiDeleteBitmap (hMemBmp), FALSE);
- }
-
- GFX (::GpiDestroyPS (MemPS), FALSE);
- }
-
- ::DevCloseDC (MemDC);
- }
- }
- } else
- {
- // Find the compatible device context and create a memory one
- HDC hdcCompat = GFX (::GpiQueryDevice (surf->GetPS ()), HDC_ERROR);
-
- rv = NS_ERROR_FAILURE;
-
- // create non-inclusive rect for GpiBitBlt
- RECTL dest;
- surf->NS2PM_INEX (trect, dest);
-
- DEVOPENSTRUC dop = { 0, 0, 0, 0, 0 };
- HDC MemDC = ::DevOpenDC( (HAB)0, OD_MEMORY, "*", 5, (PDEVOPENDATA) &dop, hdcCompat);
-
- if( MemDC != DEV_ERROR )
- {
- // create the PS
- SIZEL sizel = { 0, 0 };
- HPS MemPS = GFX (::GpiCreatePS (0, MemDC, &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC), GPI_ERROR);
-
- if( MemPS != GPI_ERROR )
- {
- GFX (::GpiCreateLogColorTable (MemPS, 0, LCOLF_RGB, 0, 0, 0), FALSE);
-
- // now create a bitmap of the right size
- HBITMAP hMemBmp;
- BITMAPINFOHEADER2 bihMem = { 0 };
-
- bihMem.cbFix = sizeof (BITMAPINFOHEADER2);
- bihMem.cx = aDWidth;
- bihMem.cy = aDHeight;
- bihMem.cPlanes = 1;
- LONG lBitCount = 0;
- GFX (::DevQueryCaps( hdcCompat, CAPS_COLOR_BITCOUNT, 1, &lBitCount), FALSE);
- if (!fPrinting)
- {
- bihMem.cBitCount = (USHORT) lBitCount;
- }
- else // Printing
- {
- // bihMem.cBitCount = (USHORT) lBitCount;
- bihMem.cBitCount = 24;
- }
-
- hMemBmp = GFX (::GpiCreateBitmap (MemPS, &bihMem, 0, 0, 0), GPI_ERROR);
-
- if( hMemBmp != GPI_ERROR )
- {
- GFX (::GpiSetBitmap (MemPS, hMemBmp), HBM_ERROR);
-
- POINTL aptlDevToMem [4] = { {0, 0}, // TLL - mem bitmap (0, 0)
- {bihMem.cx, bihMem.cy}, // TUR - mem bitmap (cx, cy)
- {dest.xLeft, dest.yBottom}, // SLL - device (Dx1, Dy2)
- {dest.xRight, dest.yTop} }; // SUR - device (Dx2, Dy1)
-
- GFX (::GpiBitBlt (MemPS, surf->GetPS (), 4, aptlDevToMem, ROP_SRCCOPY, BBO_IGNORE), GPI_ERROR);
-
- // Now we want direct access to bitmap raw data.
- // Must copy data again because GpiSetBitmap doesn't provide pointer to
- // start of raw bit data ?? (DJ)
- BITMAPINFOHEADER2 bihDirect = { 0 };
- bihDirect.cbFix = sizeof (BITMAPINFOHEADER2);
- bihDirect.cPlanes = 1;
- bihDirect.cBitCount = 24;
-
- int RawDataSize = bihMem.cy * RASWIDTH (bihMem.cx, 24);
- PRUint8* pRawBitData = (PRUint8*)malloc (RawDataSize);
-
- if( pRawBitData )
- {
- LONG rc = GFX (::GpiQueryBitmapBits (MemPS, 0, bihMem.cy, (PBYTE)pRawBitData, (PBITMAPINFO2)&bihDirect), GPI_ALTERROR);
-
- if( rc != GPI_ALTERROR )
- {
- PRUint8 *imageRGB, *imageAlpha;
- PRUint32 strideRGB, strideAlpha;
-
- /* Both scaled and unscaled images come through this code - save
- work if not scaling */
- if ((aSWidth != aDWidth) || (aSHeight != aDHeight)) {
- /* Scale our image to match */
- imageRGB = (PRUint8 *)nsMemory::Alloc(3*aDWidth*aDHeight);
- imageAlpha = (PRUint8 *)nsMemory::Alloc(aDWidth*aDHeight);
-
- if (!imageRGB || !imageAlpha) {
- if (imageRGB)
- nsMemory::Free(imageRGB);
- if (imageAlpha)
- nsMemory::Free(imageAlpha);
-
- free(pRawBitData);
- GFX (::GpiSetBitmap (MemPS, NULLHANDLE), HBM_ERROR);
- GFX (::GpiDeleteBitmap (hMemBmp), FALSE);
- GFX (::GpiDestroyPS (MemPS), FALSE);
- ::DevCloseDC (MemDC);
-
- return NS_ERROR_FAILURE;
- }
-
- strideRGB = 3 * aDWidth;
- strideAlpha = aDWidth;
- RectStretch(aSWidth, aSHeight, aDWidth, aDHeight, 0, 0, aDWidth-1, aDHeight-1,
- mImageBits, mRowBytes, imageRGB, strideRGB, 24);
- RectStretch(aSWidth, aSHeight, aDWidth, aDHeight, 0, 0, aDWidth-1, aDHeight-1,
- mAlphaBits, mARowBytes, imageAlpha, strideAlpha, 8);
- } else {
- PRUint32 srcy = mInfo->cy - (aSY + aSHeight);
- imageRGB = mImageBits + srcy * mRowBytes + aSX * 3;
- imageAlpha = mAlphaBits + srcy * mARowBytes + aSX;
- strideRGB = mRowBytes;
- strideAlpha = mARowBytes;
- }
-
- /* Do composite */
- DrawComposited24(pRawBitData, imageRGB, strideRGB, imageAlpha, strideAlpha,
- aDWidth, aDHeight);
-
- if ((aSWidth != aDWidth) || (aSHeight != aDHeight)) {
- /* Free scaled images */
- nsMemory::Free(imageRGB);
- nsMemory::Free(imageAlpha);
- }
-
- // Copy modified memory back to memory bitmap
- GFX (::GpiSetBitmapBits (MemPS, 0, bihMem.cy, (PBYTE)pRawBitData, (PBITMAPINFO2)&bihDirect), GPI_ALTERROR);
-
- // Transfer bitmap from memory bitmap back to device
- POINTL aptlMemToDev [4] = { {dest.xLeft, dest.yBottom}, // TLL - device (Dx1, Dy2)
- {dest.xRight, dest.yTop}, // TUR - device (Dx2, Dy1)
- {0, 0}, // SLL - mem bitmap (0, 0)
- {bihMem.cx, bihMem.cy} }; // SUR - mem bitmap (cx, cy)
-
- GFX (::GpiBitBlt (surf->GetPS (), MemPS, 4, aptlMemToDev, ROP_SRCCOPY, BBO_IGNORE), GPI_ERROR);
-
- rv = NS_OK;
- }
-
- free (pRawBitData);
- }
-
- GFX (::GpiSetBitmap (MemPS, NULLHANDLE), HBM_ERROR);
- GFX (::GpiDeleteBitmap (hMemBmp), FALSE);
- }
-
- GFX (::GpiDestroyPS (MemPS), FALSE);
- }
-
- ::DevCloseDC (MemDC);
- }
- }
-
- return rv;
-}
-
-nsresult nsImageOS2::Optimize( nsIDeviceContext* aContext)
-{
- // Defer this until we have a PS...
- mIsOptimized = PR_TRUE;
- return NS_OK;
-}
-
-//------------------------------------------------------------
-// lock the image pixels. implement this if you need it
-NS_IMETHODIMP
-nsImageOS2::LockImagePixels(PRBool aMaskPixels)
-{
- return NS_OK;
-}
-
-//------------------------------------------------------------
-// unlock the image pixels. implement this if you need it
-NS_IMETHODIMP
-nsImageOS2::UnlockImagePixels(PRBool aMaskPixels)
-{
- return NS_OK;
-}
-
-void
-nsImageOS2::BuildTile (HPS hpsTile, PRUint8* pImageBits, PBITMAPINFO2 pBitmapInfo,
- nscoord aTileWidth, nscoord aTileHeight, float scale)
-{
- // If bitmap not fully loaded, then first fill area with background color.
- if (nsRect (0, 0, mInfo->cx, mInfo->cy) != mDecodedRect)
- {
- POINTL pt1 = { 0, 0 }; // LL - in
- POINTL pt2 = { mInfo->cx, mInfo->cy }; // UR - ex
-
-#ifdef DEBUG
- GFX (::GpiSetColor (hpsTile, MK_RGB (255, 255, 0)), FALSE); // yellow eye-catcher
-#else
- GFX (::GpiSetColor (hpsTile, MK_RGB (255, 255, 255)), FALSE);
-#endif
- GFX (::GpiMove (hpsTile, &pt1), FALSE);
- GFX (::GpiBox (hpsTile, DRO_FILL, &pt2, 0, 0), GPI_ERROR);
- }
-
- // Set up blit coord array
- POINTL aptl [4] = { {mDecodedRect.x, mDecodedRect.y}, // TLL - in
- {mDecodedRect.XMost () - 1, mDecodedRect.YMost () - 1}, // TUR - in
- {mDecodedRect.x, mDecodedRect.y}, // SLL - in
- {mDecodedRect.XMost (), mDecodedRect.YMost ()} }; // SUR - ex
-
- // Scale up
- aptl[0].x = (LONG)(aptl[0].x * scale);
- aptl[0].y = (LONG)(aptl[0].y * scale);
- aptl[1].x = (LONG)(mDecodedRect.XMost() * scale) - 1;
- aptl[1].y = (LONG)(mDecodedRect.YMost() * scale) - 1;
-
- // Draw bitmap once into temporary PS
- GFX (::GpiDrawBits (hpsTile, (PBYTE)pImageBits, pBitmapInfo, 4, aptl, ROP_SRCCOPY, BBO_IGNORE), GPI_ERROR);
-
- PRInt32 DestWidth = (PRInt32)(mInfo->cx * scale);
- PRInt32 DestHeight = (PRInt32)(mInfo->cy * scale);
-
- // Copy bitmap horizontally, doubling each time
- if (DestWidth > 0) {
- while (DestWidth < aTileWidth)
- {
- POINTL aptlCopy [3] = { {DestWidth, 0}, // TLL - in
- {2 * DestWidth, DestHeight}, // TUR - ex
- {0, 0} }; // SLL - in
-
- GFX (::GpiBitBlt (hpsTile, hpsTile, 3, aptlCopy, ROP_SRCCOPY, 0L), GPI_ERROR);
- DestWidth *= 2;
- }
- }
-
- // Copy bitmap vertically, doubling each time
- if (DestHeight > 0) {
- while (DestHeight < aTileHeight)
- {
- POINTL aptlCopy [4] = { {0, DestHeight}, // TLL - in
- {DestWidth, 2 * DestHeight}, // TUR - ex
- {0, 0} }; // SLL - in
-
- GFX (::GpiBitBlt (hpsTile, hpsTile, 3, aptlCopy, ROP_SRCCOPY, 0L), GPI_ERROR);
- DestHeight *= 2;
- }
- }
-}
-
-/** ---------------------------------------------------
- * See documentation in nsIRenderingContext.h
- * @update 3/16/00 dwc
- */
-NS_IMETHODIMP nsImageOS2::DrawTile(nsIRenderingContext &aContext,
- nsIDrawingSurface* aSurface,
- PRInt32 aSXOffset, PRInt32 aSYOffset,
- PRInt32 aPadX, PRInt32 aPadY,
- const nsRect &aTileRect)
-{
- if (aTileRect.IsEmpty ())
- return NS_OK;
-
- PRBool didTile = PR_FALSE;
- PRInt32 ImageWidth = mInfo->cx;
- PRInt32 ImageHeight = mInfo->cy;
- PRBool padded = (aPadX || aPadY);
-
- // Get the scale - if greater than 1 then do slow tile which
- nsCOMPtr<nsIDeviceContext> theDeviceContext;
- float scale;
- aContext.GetDeviceContext(*getter_AddRefs(theDeviceContext));
- theDeviceContext->GetCanonicalPixelScale(scale);
-
- nsRect ValidRect (0, 0, ImageWidth, ImageHeight);
- ValidRect.IntersectRect (ValidRect, mDecodedRect);
- PRInt32 DestScaledWidth = PR_MAX(PRInt32(ValidRect.width * scale), 1);
- PRInt32 DestScaledHeight = PR_MAX(PRInt32(ValidRect.height * scale), 1);
-
- nsRect DrawRect = aTileRect;
- DrawRect.MoveBy (-aSXOffset, -aSYOffset);
- DrawRect.SizeBy (aSXOffset, aSYOffset);
-
- // Don't bother tiling if we only have to draw the bitmap a couple of times
- // Can't tile with 8bit alpha masks because need access destination bitmap values
- if ((ImageWidth < DrawRect.width / 2 || ImageHeight < DrawRect.height / 2) &&
- (ImageWidth <= MAX_BUFFER_WIDTH) && (ImageHeight <= MAX_BUFFER_HEIGHT) &&
- mAlphaDepth <= 1 &&
- !padded)
- {
- nsDrawingSurfaceOS2 *surf = (nsDrawingSurfaceOS2*) aSurface;
-
- // Find the compatible device context and create a memory one
- HDC hdcCompat = GFX (::GpiQueryDevice (surf->GetPS ()), HDC_ERROR);
-
- DEVOPENSTRUC dop = { 0, 0, 0, 0, 0 };
- HDC MemDC = GFX (::DevOpenDC( (HAB)0, OD_MEMORY, "*", 5, (PDEVOPENDATA) &dop, hdcCompat), DEV_ERROR);
-
- if( DEV_ERROR != MemDC)
- {
- // create the PS
- SIZEL sizel = { 0, 0 };
- HPS MemPS = GFX (::GpiCreatePS (0, MemDC, &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC), GPI_ERROR);
-
- if( GPI_ERROR != MemPS)
- {
- GFX (::GpiCreateLogColorTable (MemPS, 0, LCOLF_RGB, 0, 0, 0), FALSE);
-
- // now create a bitmap of the right size
- BITMAPINFOHEADER2 hdr = { 0 };
-
- hdr.cbFix = sizeof( BITMAPINFOHEADER2);
- // Maximum size of tiled area (could do this better)
- PRInt32 endWidth = DestScaledWidth;
- while( endWidth < DrawRect.width)
- endWidth *= 2;
-
- PRInt32 endHeight = DestScaledHeight;
- while( endHeight < DrawRect.height)
- endHeight *= 2;
-
- hdr.cx = endWidth;
- hdr.cy = endHeight;
- hdr.cPlanes = 1;
-
- // find bitdepth
- LONG lBitCount = 0;
- GFX (::DevQueryCaps( hdcCompat, CAPS_COLOR_BITCOUNT, 1, &lBitCount), FALSE);
- hdr.cBitCount = (USHORT) lBitCount;
-
- RECTL rcl;
- surf->NS2PM_INEX (aTileRect, rcl);
-
- POINTL aptlTile [3] = { {rcl.xLeft, rcl.yBottom}, // TLL - in
- {rcl.xRight, rcl.yTop}, // TUR - ex
- {aSXOffset, endHeight - aTileRect.height - aSYOffset} }; // SLL - in
- // For some reason offset does not work well with scaled output
- if (scale > 1.0)
- {
- aptlTile[2].x = 0;
- aptlTile[2].y = endHeight - aTileRect.height;
- }
- HBITMAP hMemBmp = GFX (::GpiCreateBitmap (MemPS, &hdr, 0, 0, 0), GPI_ERROR);
- if (hMemBmp != GPI_ERROR)
- {
- LONG ImageROP = ROP_SRCCOPY;
-
- GFX (::GpiSetBitmap (MemPS, hMemBmp), HBM_ERROR);
-
- if (mAlphaDepth == 1)
- {
- LONG BlackColor = GFX (::GpiQueryColorIndex (MemPS, 0, MK_RGB (0x00, 0x00, 0x00)), GPI_ALTERROR); // CLR_BLACK;
- LONG WhiteColor = GFX (::GpiQueryColorIndex (MemPS, 0, MK_RGB (0xFF, 0xFF, 0xFF)), GPI_ALTERROR); // CLR_WHITE;
-
- // WORKAROUND:
- // PostScript drivers up to version 30.732 have problems with GpiQueryColorIndex.
- // If we are in LCOL_RGB mode it doesn't return passed RGB color but returns error instead.
-
- if (BlackColor == GPI_ALTERROR) BlackColor = MK_RGB (0x00, 0x00, 0x00);
- if (WhiteColor == GPI_ALTERROR) WhiteColor = MK_RGB (0xFF, 0xFF, 0xFF);
-
- // Set image foreground and background colors. These are used in transparent images for blitting 1-bit masks.
- // To invert colors on ROP_SRCAND we map 1 to black and 0 to white
- IMAGEBUNDLE ib;
- ib.lColor = BlackColor; // map 1 in mask to 0x000000 (black) in destination
- ib.lBackColor = WhiteColor; // map 0 in mask to 0xFFFFFF (white) in destination
- ib.usMixMode = FM_OVERPAINT;
- ib.usBackMixMode = BM_OVERPAINT;
- GFX (::GpiSetAttrs (MemPS, PRIM_IMAGE, IBB_COLOR | IBB_BACK_COLOR | IBB_MIX_MODE | IBB_BACK_MIX_MODE, 0, (PBUNDLE)&ib), FALSE);
-
- MONOBITMAPINFO MaskBitmapInfo (mInfo);
- BuildTile (MemPS, mAlphaBits, MaskBitmapInfo, DrawRect.width, DrawRect.height, scale);
-
- // Apply mask to target, clear pels we will fill in from the image
- GFX (::GpiBitBlt (surf->GetPS (), MemPS, 3, aptlTile, ROP_SRCAND, 0L), GPI_ERROR);
-
- ImageROP = ROP_SRCPAINT; // Original image must be combined with mask
- }
-
- BuildTile (MemPS, mImageBits, mInfo, DrawRect.width, DrawRect.height, scale);
-
- GFX (::GpiBitBlt (surf->GetPS (), MemPS, 3, aptlTile, ImageROP, 0L), GPI_ERROR);
-
- didTile = PR_TRUE;
-
- // Must deselect bitmap from PS before freeing bitmap and PS.
- GFX (::GpiSetBitmap (MemPS, NULLHANDLE), HBM_ERROR);
- GFX (::GpiDeleteBitmap (hMemBmp), FALSE);
- }
- GFX (::GpiDestroyPS (MemPS), FALSE);
- }
- GFX (::DevCloseDC (MemDC), DEV_ERROR);
- }
- }
-
- // If we failed to tile the bitmap, then use the old, slow, reliable way
- if( didTile == PR_FALSE)
- {
- // put the DestRect into absolute coordintes of the device
- PRInt32 y0 = aTileRect.y - aSYOffset;
- PRInt32 x0 = aTileRect.x - aSXOffset;
- PRInt32 y1 = aTileRect.y + aTileRect.height;
- PRInt32 x1 = aTileRect.x + aTileRect.width;
-
- // this is the width and height of the image in pixels
- // we need to map this to the pixel height of the device
- nscoord ScaledTileWidth = PR_MAX(PRInt32(ImageWidth*scale), 1);
- nscoord ScaledTileHeight = PR_MAX(PRInt32(ImageHeight*scale), 1);
-
- for (PRInt32 y = y0; y < y1; y += (PRInt32)(ScaledTileHeight + aPadY * scale))
- {
- for (PRInt32 x = x0; x < x1; x += (PRInt32)(ScaledTileWidth + aPadX * scale))
- {
- Draw(aContext, aSurface,
- 0, 0, PR_MIN(ValidRect.width, x1 - x), PR_MIN(ValidRect.height, y1 - y),
- x, y, PR_MIN(DestScaledWidth, x1-x), PR_MIN(DestScaledHeight, y1 - y));
- }
- }
- }
- return NS_OK;
-}
-
-
-void nsImageOS2::NS2PM_ININ( const nsRect &in, RECTL &rcl)
-{
- PRUint32 ulHeight = GetHeight ();
-
- rcl.xLeft = in.x;
- rcl.xRight = in.x + in.width - 1;
- rcl.yTop = ulHeight - in.y - 1;
- rcl.yBottom = rcl.yTop - in.height + 1;
-}
-
-
-// ---------------------------------------------------
-// Update mImageBits with content of new mBitmap
-//
-NS_IMETHODIMP nsImageOS2::UpdateImageBits( HPS aPS )
-{
- BITMAPINFOHEADER2 rawInfo = { 0 };
- rawInfo.cbFix = sizeof (BITMAPINFOHEADER2);
- rawInfo.cPlanes = 1;
- rawInfo.cBitCount = mInfo->cBitCount;
-
- int RawDataSize = mInfo->cy * RASWIDTH (mInfo->cx, mInfo->cBitCount);
- PRUint8* pRawBitData = new PRUint8 [RawDataSize];
-
- if (pRawBitData)
- {
- GFX (::GpiQueryBitmapBits (aPS, 0, mInfo->cy, (PBYTE)pRawBitData, (PBITMAPINFO2)&rawInfo), GPI_ALTERROR);
- delete [] mImageBits;
- mImageBits = pRawBitData;
- return NS_OK;
- }
- else
- return NS_ERROR_OUT_OF_MEMORY;
-}
-
-NS_IMETHODIMP nsImageOS2::DrawToImage(nsIImage* aDstImage,
- nscoord aDX, nscoord aDY,
- nscoord aDWidth, nscoord aDHeight)
-{
- nsresult rc = NS_OK;
-
- DEVOPENSTRUC dop = { 0, 0, 0, 0, 0 };
- SIZEL sizel = { 0, 0 };
-
- if (mInfo == nsnull || aDWidth < 0 || aDHeight < 0)
- return NS_ERROR_FAILURE;
-
- if (0 == aDWidth || 0 == aDHeight)
- return NS_OK;
-
- // Create a memory DC that is compatible with the screen
- HDC MemDC = GFX (::DevOpenDC( 0/*hab*/, OD_MEMORY, "*", 5,
- (PDEVOPENDATA) &dop, (HDC)0), DEV_ERROR);
-
- // create the PS
- HPS MemPS = GFX (::GpiCreatePS (0/*hab*/, MemDC, &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC), GPI_ERROR);
-
- GFX (::GpiCreateLogColorTable (MemPS, 0, LCOLF_RGB, 0, 0, 0), FALSE);
-
- nsImageOS2* destImg = static_cast<nsImageOS2*>(aDstImage);
-
- HBITMAP hTmpBitmap = GFX (::GpiCreateBitmap (MemPS, (PBITMAPINFOHEADER2)destImg->mInfo,
- CBM_INIT, (PBYTE)destImg->mImageBits,
- destImg->mInfo), GPI_ERROR);
- GFX (::GpiSetBitmap (MemPS, hTmpBitmap), HBM_ERROR);
-
- nsRect trect( aDX, aDY, aDWidth, aDHeight);
- RECTL rcl;
- destImg->NS2PM_ININ (trect, rcl);
-
- // Set up blit coord array
- POINTL aptl [4] = { {rcl.xLeft, rcl.yBottom}, // TLL - in
- {rcl.xRight, rcl.yTop}, // TUR - in
- {0, 0}, // SLL - in
- {mInfo->cx, mInfo->cy} }; // SUR - ex
-
- if( 1==mAlphaDepth && mAlphaBits)
- {
- LONG BlackColor = GFX (::GpiQueryColorIndex (MemPS, 0, MK_RGB (0x00, 0x00, 0x00)), GPI_ALTERROR); // CLR_BLACK;
- LONG WhiteColor = GFX (::GpiQueryColorIndex (MemPS, 0, MK_RGB (0xFF, 0xFF, 0xFF)), GPI_ALTERROR); // CLR_WHITE;
- if (BlackColor == GPI_ALTERROR) BlackColor = MK_RGB (0x00, 0x00, 0x00);
- if (WhiteColor == GPI_ALTERROR) WhiteColor = MK_RGB (0xFF, 0xFF, 0xFF);
-
- // Set image foreground and background colors. These are used in transparent images for blitting 1-bit masks.
- // To invert colors on ROP_SRCAND we map 1 to black and 0 to white
- IMAGEBUNDLE ib;
- ib.lColor = BlackColor; // map 1 in mask to 0x000000 (black) in destination
- ib.lBackColor = WhiteColor; // map 0 in mask to 0xFFFFFF (white) in destination
- ib.usMixMode = FM_OVERPAINT;
- ib.usBackMixMode = BM_OVERPAINT;
- GFX (::GpiSetAttrs (MemPS, PRIM_IMAGE, IBB_COLOR | IBB_BACK_COLOR | IBB_MIX_MODE | IBB_BACK_MIX_MODE, 0, (PBUNDLE)&ib), FALSE);
-
- // Apply mask to target, clear pels we will fill in from the image
- MONOBITMAPINFO MaskBitmapInfo (mInfo);
- GFX (::GpiDrawBits (MemPS, mAlphaBits, MaskBitmapInfo, 4, aptl, ROP_SRCAND,
- BBO_IGNORE), GPI_ERROR);
-
- // Now combine image with target
- GFX (::GpiDrawBits (MemPS, mImageBits, mInfo, 4, aptl, ROP_SRCPAINT,
- BBO_IGNORE), GPI_ERROR);
- } else {
- // alpha depth of 8 not used (yet?)
- NS_ASSERTION( mAlphaDepth != 8, "Alpha depth of 8 not implemented in DrawToImage" );
-
- // no transparency, just blit it
- GFX (::GpiDrawBits (MemPS, mImageBits, mInfo, 4, aptl, ROP_SRCCOPY,
- BBO_IGNORE), GPI_ERROR);
- }
-
- rc = destImg->UpdateImageBits (MemPS);
-
- GFX (::GpiSetBitmap (MemPS, NULLHANDLE), HBM_ERROR);
- GFX (::GpiDeleteBitmap (hTmpBitmap), FALSE);
- GFX (::GpiDestroyPS (MemPS), FALSE);
- GFX (::DevCloseDC (MemDC), DEV_ERROR);
-
- return rc;
-}
deleted file mode 100644
--- a/gfx/src/os2/nsImageOS2.h
+++ /dev/null
@@ -1,218 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Mozilla OS/2 libraries.
- *
- * The Initial Developer of the Original Code is
- * John Fairhurst, <john_fairhurst@iname.com>.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Pierre Phaneuf <pp@ludusdesign.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK *****
- *
- * This Original Code has been modified by IBM Corporation. Modifications made by IBM
- * described herein are Copyright (c) International Business Machines Corporation, 2000.
- * Modifications to Mozilla code or documentation identified per MPL Section 3.3
- *
- * Date Modified by Description of modification
- * 05/11/2000 IBM Corp. Make it look more like Windows.
- */
-
-#ifndef _nsImageOS2_h_
-#define _nsImageOS2_h_
-
-#include "nsIImage.h"
-#include "nsRect.h"
-
-struct nsDrawingSurfaceOS2;
-
-class nsImageOS2 : public nsIImage{
-public:
- nsImageOS2();
- ~nsImageOS2();
-
- NS_DECL_ISUPPORTS
-
- /**
- @see nsIImage.h
- */
- virtual PRInt32 GetBytesPix() { return mInfo ? (mInfo->cBitCount <= 8 ? 1 : mInfo->cBitCount / 8) : 0; }
- virtual PRInt32 GetHeight() { return mInfo ? mInfo->cy : 0; }
- virtual PRBool GetIsRowOrderTopToBottom() { return PR_FALSE; }
- virtual PRInt32 GetWidth() { return mInfo ? mInfo->cx : 0; }
- virtual PRUint8* GetBits() { return mImageBits; }
- virtual PRInt32 GetLineStride() { return mRowBytes; }
-
- virtual PRBool GetHasAlphaMask() { return mAlphaBits != nsnull; }
-
- NS_IMETHOD Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface, PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
- NS_IMETHOD Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface, PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
- PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
- virtual nsColorMap* GetColorMap() {return mColorMap;}
- virtual void ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRect *aUpdateRect);
- virtual PRBool GetIsImageComplete();
- virtual nsresult Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequirements aMaskRequirements);
- virtual nsresult Optimize(nsIDeviceContext* aContext);
- virtual PRUint8* GetAlphaBits() { return mAlphaBits; }
- virtual PRInt32 GetAlphaLineStride(){ return mARowBytes; }
-
- /**
- * Draw a tiled version of the bitmap
- * @param aSurface the surface to blit to
- * @param aSXOffset Offset from image's upper right corner that will be located at
- * @param aSYOffset upper right corner of filled area
- * @param aTileRect Area which must be filled with tiled image
- * @return if TRUE, no errors
- */
- NS_IMETHOD DrawTile(nsIRenderingContext &aContext,
- nsIDrawingSurface* aSurface,
- PRInt32 aSXOffset, PRInt32 aSYOffset,
- PRInt32 aPadX, PRInt32 aPadY,
- const nsRect &aTileRect);
-
- NS_IMETHOD DrawToImage(nsIImage* aDstImage, nscoord aDX, nscoord aDY,
- nscoord aDWidth, nscoord aDHeight);
-
- /**
- * Return the header size of the Device Independent Bitmap(DIB).
- * @return size of header in bytes
- */
-#if 0 // OS2TODO
- PRIntn GetSizeHeader(){return sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * mNumPaletteColors;}
-#endif
-
- /**
- * Return the image size of the Device Independent Bitmap(DIB).
- * @update dc - 10/29/98
- * @return size of image in bytes
- */
-#if 0 // OS2TODO
- PRIntn GetSizeImage(){ return mSizeImage; }
-#endif
-
- /**
- * Calculate the number of bytes spaned for this image for a given width
- * @param aWidth is the width to calculate the number of bytes for
- * @return the number of bytes in this span
- */
-#if 0 // OS2TODO
- PRInt32 CalcBytesSpan(PRUint32 aWidth);
-#endif
-
- /**
- * Get the alpha depth for the image mask
- * @update - lordpixel 2001/05/16
- * @return the alpha mask depth for the image, ie, 0, 1 or 8
- */
- virtual PRInt8 GetAlphaDepth() {return(mAlphaDepth);}
-
- /**
- * Get the DIB specific informations for this bitmap.
- * @update dc - 10/29/98
- * @return VOID
- */
- void* GetBitInfo() { return mInfo; }
-
- NS_IMETHOD LockImagePixels(PRBool aMaskPixels);
- NS_IMETHOD UnlockImagePixels(PRBool aMaskPixels);
-
-
- private:
- /**
- * Clean up the memory used nsImageWin.
- * @update dc - 10/29/98
- * @param aCleanUpAll - if True, all the memory used will be released otherwise just clean up the DIB memory
- */
- void CleanUp(PRBool aCleanUpAll);
-
- void DrawComposited24(unsigned char *aBits,
- PRUint8 *aImageRGB, PRUint32 aStrideRGB,
- PRUint8 *aImageAlpha, PRUint32 aStrideAlpha,
- int aWidth, int aHeight);
-
-#ifdef OS2TODO
- /**
- * Create a Device Dependent bitmap from a drawing surface
- * @update dc - 05/20/99
- * @param aSurface - The drawingsurface to create the DIB from.
- * @param aWidth - width of DIB
- * @param aHeight - height of DIB
- */
- nsresult ConvertDDBtoDIB(PRInt32 aWidth,PRInt32 aHeight);
-
-
- /**
- * Print a DDB
- * @update dc - 05/20/99
- * @param aSurface - The drawingsurface to create the DIB from.
- * @param aX - x location to place image
- * @param aX - y location to place image
- * @param aWidth - width of DIB
- * @param aHeight - height of DIB
- */
- nsresult PrintDDB(nsIDrawingSurface* aSurface,PRInt32 aX,PRInt32 aY,PRInt32 aWidth,PRInt32 aHeight);
-
-
- /**
- * Get an index in the palette that matches as closly as possible the passed in RGB colors
- * @update dc - 10/29/98
- * @param aR - Red component of the color to match
- * @param aG - Green component of the color to match
- * @param aB - Blue component of the color to match
- * @return - The closest palette match
- */
- PRUint8 PaletteMatch(PRUint8 r, PRUint8 g, PRUint8 b);
-#endif
- BITMAPINFO2* mInfo;
- PRUint32 mDeviceDepth;
- PRInt32 mRowBytes; // number of bytes per row
- PRUint8* mImageBits; // starting address of DIB bits
- PRBool mIsOptimized; // Did we convert our DIB to a HBITMAP
- nsColorMap* mColorMap; // Redundant with mColorTable, but necessary
-
- nsRect mDecodedRect; // Keeps track of what part of image has been decoded.
-
- // alpha layer members
- PRUint8 *mAlphaBits; // alpha layer if we made one
- PRInt8 mAlphaDepth; // alpha layer depth
- PRInt16 mARowBytes; // number of bytes per row in the image for tha alpha
-
- static PRUint8 gBlenderLookup [65536]; // Lookup table for fast alpha blending
- static PRBool gBlenderReady;
- static void BuildBlenderLookup (void);
- static PRUint8 FAST_BLEND (PRUint8 Source, PRUint8 Dest, PRUint8 Alpha) { return gBlenderLookup [(Alpha << 8) + Source] +
- gBlenderLookup [((255 - Alpha) << 8) + Dest]; }
-
- NS_IMETHODIMP UpdateImageBits( HPS mPS );
- void NS2PM_ININ( const nsRect &in, RECTL &rcl);
- void CreateBitmaps( nsDrawingSurfaceOS2 *surf);
-
- void BuildTile (HPS hpsTile, PRUint8* pImageBits, PBITMAPINFO2 pBitmapInfo, nscoord aTileWidth, nscoord aTileHeight, float scale);
-};
-
-#endif
deleted file mode 100644
--- a/gfx/src/os2/nsOS2Uni.cpp
+++ /dev/null
@@ -1,181 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is an API for accessing OS/2 Unicode support.
- *
- * The Initial Developer of the Original Code is
- * IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2002
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsOS2Uni.h"
-#include "nsIServiceManager.h"
-#include "nsIPlatformCharset.h"
-#include <stdlib.h>
-
-
-/**********************************************************
- OS2Uni
- **********************************************************/
-nsICharsetConverterManager* OS2Uni::gCharsetManager = nsnull;
-
-struct ConverterInfo
-{
- PRUint16 mCodePage;
- char* mConvName;
- nsIUnicodeEncoder* mEncoder;
- nsIUnicodeDecoder* mDecoder;
-};
-
-#define eCONVERTER_COUNT 17
-ConverterInfo gConverterInfo[eCONVERTER_COUNT] =
-{
- { 0, "", nsnull, nsnull },
- { 1252, "windows-1252", nsnull, nsnull },
- { 1208, "UTF-8", nsnull, nsnull },
- { 1250, "windows-1250", nsnull, nsnull },
- { 1251, "windows-1251", nsnull, nsnull },
- { 813, "ISO-8859-7", nsnull, nsnull },
- { 1254, "windows-1254", nsnull, nsnull },
- { 864, "IBM864", nsnull, nsnull },
- { 1257, "windows-1257", nsnull, nsnull },
- { 874, "windows-874", nsnull, nsnull },
- { 932, "Shift_JIS", nsnull, nsnull },
- { 943, "Shift_JIS", nsnull, nsnull },
- { 1381, "GB2312", nsnull, nsnull },
- { 1386, "GB2312", nsnull, nsnull },
- { 949, "x-windows-949", nsnull, nsnull },
- { 950, "Big5", nsnull, nsnull },
- { 1361, "x-johab", nsnull, nsnull }
-};
-
-nsISupports*
-OS2Uni::GetUconvObject(int aCodePage, ConverterRequest aReq)
-{
- if (gCharsetManager == nsnull) {
- CallGetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &gCharsetManager);
- }
-
- nsresult rv;
- nsISupports* uco = nsnull;
- for (int i = 0; i < eCONVERTER_COUNT; i++) {
- if (aCodePage == gConverterInfo[i].mCodePage) {
- if (gConverterInfo[i].mEncoder == nsnull) {
- const char* convname;
- nsCAutoString charset;
- if (aCodePage == 0) {
- nsCOMPtr<nsIPlatformCharset>
- plat(do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv));
- if (NS_SUCCEEDED(rv)) {
- plat->GetCharset(kPlatformCharsetSel_FileName, charset);
- } else {
- // default to IBM850 if this should fail
- charset = "IBM850";
- }
- convname = charset.get();
- } else {
- convname = gConverterInfo[i].mConvName;
- }
- rv = gCharsetManager->GetUnicodeEncoderRaw(convname,
- &gConverterInfo[i].mEncoder);
- gConverterInfo[i].mEncoder->
- SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace,
- nsnull, '?');
- gCharsetManager->GetUnicodeDecoderRaw(convname,
- &gConverterInfo[i].mDecoder);
- NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to get converter");
- }
- if (aReq == eConv_Encoder) {
- uco = gConverterInfo[i].mEncoder;
- } else {
- uco = gConverterInfo[i].mDecoder;
- }
- break;
- }
- }
-
- return uco;
-}
-
-void OS2Uni::FreeUconvObjects()
-{
- for (int i = 0; i < eCONVERTER_COUNT; i++) {
- NS_IF_RELEASE(gConverterInfo[i].mEncoder);
- NS_IF_RELEASE(gConverterInfo[i].mDecoder);
- }
- NS_IF_RELEASE(gCharsetManager);
-}
-
-/**********************************************************
- WideCharToMultiByte
- **********************************************************/
-NS_GFX_(nsresult)
-WideCharToMultiByte(int aCodePage, const PRUnichar* aSrc,
- PRInt32 aSrcLength, nsAutoCharBuffer& aResult,
- PRInt32& aResultLength)
-{
- nsresult rv;
- nsISupports* sup = OS2Uni::GetUconvObject(aCodePage, eConv_Encoder);
- nsCOMPtr<nsIUnicodeEncoder> uco = do_QueryInterface(sup);
-
- if (NS_FAILED(uco->GetMaxLength(aSrc, aSrcLength, &aResultLength))) {
- return NS_ERROR_UNEXPECTED;
- }
- if (!aResult.EnsureElemCapacity(aResultLength + 1))
- return NS_ERROR_OUT_OF_MEMORY;
- char* str = aResult.get();
-
- rv = uco->Convert(aSrc, &aSrcLength, str, &aResultLength);
- aResult.get()[aResultLength] = '\0';
- return rv;
-}
-
-/**********************************************************
- MultiByteToWideChar
- **********************************************************/
-NS_GFX_(nsresult)
-MultiByteToWideChar(int aCodePage, const char* aSrc,
- PRInt32 aSrcLength, nsAutoChar16Buffer& aResult,
- PRInt32& aResultLength)
-{
- nsresult rv;
- nsISupports* sup = OS2Uni::GetUconvObject(aCodePage, eConv_Decoder);
- nsCOMPtr<nsIUnicodeDecoder> uco = do_QueryInterface(sup);
-
- if (NS_FAILED(uco->GetMaxLength(aSrc, aSrcLength, &aResultLength))) {
- return NS_ERROR_UNEXPECTED;
- }
- if (!aResult.EnsureElemCapacity(aResultLength + 1))
- return NS_ERROR_OUT_OF_MEMORY;
- PRUnichar* str = aResult.get();
-
- rv = uco->Convert(aSrc, &aSrcLength, str, &aResultLength);
- aResult.get()[aResultLength] = '\0';
- return rv;
-}
deleted file mode 100644
--- a/gfx/src/os2/nsOS2Uni.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is an API for accessing OS/2 Unicode support.
- *
- * The Initial Developer of the Original Code is
- * IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2002
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef _nsos2uni_h
-#define _nsos2uni_h
-
-#define INCL_WIN
-#include <os2.h>
-#include <uconv.h>
-#include "nsAutoBuffer.h"
-#include "nsICharsetConverterManager.h"
-#include "gfxCore.h"
-
-
-enum ConverterRequest {
- eConv_Encoder,
- eConv_Decoder
-};
-
-class NS_GFX OS2Uni {
-public:
- static nsISupports* GetUconvObject(int CodePage, ConverterRequest aReq);
- static void FreeUconvObjects();
-private:
- static nsICharsetConverterManager* gCharsetManager;
-};
-
-
-#define CHAR_BUFFER_SIZE 1024
-typedef nsAutoBuffer<char, CHAR_BUFFER_SIZE> nsAutoCharBuffer;
-typedef nsAutoBuffer<PRUnichar, CHAR_BUFFER_SIZE> nsAutoChar16Buffer;
-
-NS_GFX_(nsresult) WideCharToMultiByte(int aCodePage, const PRUnichar* aSrc,
- PRInt32 aSrcLength, nsAutoCharBuffer& aResult,
- PRInt32& aResultLength);
-NS_GFX_(nsresult) MultiByteToWideChar(int aCodePage, const char* aSrc,
- PRInt32 aSrcLength, nsAutoChar16Buffer& aResult,
- PRInt32& aResultLength);
-
-#endif
deleted file mode 100644
--- a/gfx/src/os2/nsPaletteOS2.cpp
+++ /dev/null
@@ -1,177 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is an API for using the OS/2 Palette Manager.
- *
- * The Initial Developer of the Original Code is
- * IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2002
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsPaletteOS2.h"
-#include "nsGfxDefs.h"
-#ifdef DEBUG
-#include <stdio.h>
-#endif
-
-HPAL nsPaletteOS2::hGlobalPalette = NULLHANDLE;
-BOOL nsPaletteOS2::fPaletteInitialized = FALSE;
-ULONG nsPaletteOS2::aulTable[256];
-
-#define NUM_SYS_COLORS 24
-
-typedef struct _MYRGB {
- BYTE red;
- BYTE green;
- BYTE blue;
-} MYRGB;
-
-MYRGB sysColors[NUM_SYS_COLORS] =
-{
- 0x00, 0x00, 0x00, // CLR_BLACK
- 0x00, 0x00, 0x80, // CLR_DARKBLUE
- 0x00, 0x80, 0x00, // CLR_DARKGREEN
- 0x00, 0x80, 0x80, // CLR_DARKCYAN
- 0x80, 0x00, 0x00, // CLR_DARKRED
- 0x80, 0x00, 0x80, // CLR_DARKPINK
- 0x80, 0x80, 0x00, // CLR_BROWN
- 0x80, 0x80, 0x80, // CLR_DARKGRAY
- 0xCC, 0xCC, 0xCC, // CLR_PALEGRAY
- 0x00, 0x00, 0xFF, // CLR_BLUE
- 0x00, 0xFF, 0x00, // CLR_GREEN
- 0x00, 0xFF, 0xFF, // CLR_CYAN
- 0xFF, 0x00, 0x00, // CLR_RED
- 0xFF, 0x00, 0xFF, // CLR_PINK
- 0xFF, 0xFF, 0x00, // CLR_YELLOW
- 0xFE, 0xFE, 0xFE, // CLR_OFFWHITE - can only use white at index 255
-
- 0xC0, 0xC0, 0xC0, // Gray (Windows)
- 0xFF, 0xFB, 0xF0, // Pale Yellow (Windows)
- 0xC0, 0xDC, 0xC0, // Pale Green (Windows)
- 0xA4, 0xC8, 0xF0, // Light Blue (Windows)
- 0xA4, 0xA0, 0xA4, // Medium Gray (Windows)
-
- 0xFF, 0xFF, 0xE4, // Tooltip color - see nsLookAndFeel.cpp
-
- 0x71, 0x71, 0x71, // Interpolated color for entryfields
- 0xEF, 0xEF, 0xEF // Interpolated color for entryfields
-
-};
-
-void nsPaletteOS2::InitializeGlobalPalette()
-{
- fPaletteInitialized = TRUE;
- LONG lCaps;
- HPS hps = ::WinGetScreenPS(HWND_DESKTOP);
- HDC hdc = ::GpiQueryDevice (hps);
- ::DevQueryCaps(hdc, CAPS_ADDITIONAL_GRAPHICS, 1, &lCaps);
- ::WinReleasePS(hps);
-
- if (lCaps & CAPS_PALETTE_MANAGER) {
- /* Create the color table */
- int i,j,k,l, ulCurTableEntry = 0;
-
- /* First add the system colors */
- for (i = 0; i < NUM_SYS_COLORS; i++) {
- aulTable[ulCurTableEntry] = MK_RGB(sysColors[i].red, sysColors[i].green, sysColors[i].blue);
- ulCurTableEntry++;
- }
-
- /* Then put the color cube into the table, excluding */
- /* any entry that is also in the system color table */
- for (i=0x00;i <= 0xff;i+=0x33) {
- for (j=0x00;j <= 0xff;j+=0x33) {
- for (k=0x00;k <= 0xff ;k+=0x33) {
- for (l=0;l<ulCurTableEntry;l++) {
- if (aulTable[l] == MK_RGB(i, j, k))
- break;
- }
- if (l == ulCurTableEntry) {
- aulTable[ulCurTableEntry] = MK_RGB(i, j, k);
- ulCurTableEntry++;
- }
- }
- }
- }
-
- /* Back current table entry up one so we overwrite the white that was written */
- /* by the color cube */
- ulCurTableEntry--;
-
- /* Then fudge the rest of the table to have entries that are neither white */
- /* nor black - we'll use an offwhite */
- while (ulCurTableEntry < 255) {
- aulTable[ulCurTableEntry] = MK_RGB(254, 254, 254);
- ulCurTableEntry++;
- }
-
- /* Finally, make the last entry white */
- aulTable[ulCurTableEntry] = MK_RGB(255, 255, 255);
-
-#ifdef DEBUG_mikek
- for (i=0;i<256 ;i++ )
- printf("Entry[%d] in 256 color table is %x\n", i, aulTable[i]);
-#endif
-
- /* Create the palette */
- hGlobalPalette = ::GpiCreatePalette ((HAB)0, 0,
- LCOLF_CONSECRGB, 256, aulTable);
- }
-}
-
-void nsPaletteOS2::FreeGlobalPalette()
-{
- if (hGlobalPalette) {
- GpiDeletePalette(hGlobalPalette);
- hGlobalPalette = NULLHANDLE;
- }
-}
-
-void nsPaletteOS2::SelectGlobalPalette(HPS hps, HWND hwnd)
-{
- if (!fPaletteInitialized)
- InitializeGlobalPalette();
- if (hGlobalPalette) {
- GpiSelectPalette(hps, hGlobalPalette);
- if (hwnd != NULLHANDLE) {
- ULONG cclr;
- WinRealizePalette(hwnd, hps, &cclr);
- }
- }
-}
-
-LONG nsPaletteOS2::QueryColorIndex(LONG lColor)
-{
- for (int i=0;i<256;i++) {
- if (lColor == aulTable[i]) {
- return i;
- }
- }
- return 0;
-}
deleted file mode 100644
--- a/gfx/src/os2/nsPaletteOS2.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is an API for using the OS/2 Palette Manager.
- *
- * The Initial Developer of the Original Code is
- * IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2002
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef _nspaletteos2_h
-#define _nspaletteos2_h
-
-#define INCL_WIN
-#define INCL_GPI
-#include <os2.h>
-#include "gfxCore.h"
-
-class NS_GFX nsPaletteOS2 {
-public:
- static void FreeGlobalPalette();
- static void InitializeGlobalPalette();
- static void SelectGlobalPalette(HPS hps, HWND hwnd = NULLHANDLE);
- static LONG QueryColorIndex(LONG lColor);
-private:
- static HPAL hGlobalPalette;
- static BOOL fPaletteInitialized;
- static ULONG aulTable[256];
-};
-
-#endif
deleted file mode 100644
--- a/gfx/src/os2/nsPrintOS2.cpp
+++ /dev/null
@@ -1,467 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Mozilla OS/2 libraries.
- *
- * The Initial Developer of the Original Code is
- * John Fairhurst, <john_fairhurst@iname.com>.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Pierre Phaneuf <pp@ludusdesign.com>
- * Peter Weilbacher <mozilla@weilbacher.org>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsPrintOS2.h"
-
-#include "nsOS2Uni.h"
-
-#include <stdlib.h>
-
-//---------------------------------------------------------------------------
-// OS/2 Printing - was in libprint.cpp
-//---------------------------------------------------------------------------
-static HMODULE hmodRes;
-
-#define SHIFT_PTR(ptr,offset) ( *((LONG*)&ptr) += offset )
-
-
-class NS_GFX PRTQUEUE
-{
-public:
- PRTQUEUE (const PRQINFO3* pPQI3) { InitWithPQI3 (pPQI3); }
- PRTQUEUE (const PRTQUEUE& PQInfo);
- ~PRTQUEUE (void) { free (mpPQI3); }
-
- PRQINFO3& PQI3 () const { return *mpPQI3; }
- const char* DriverName () const { return mDriverName; }
- const char* DeviceName () const { return mDeviceName; }
- const char* PrinterName() const { return mPrinterName; }
- const char* QueueName () const { return mpPQI3->pszComment; }
-
-private:
- PRTQUEUE& operator = (const PRTQUEUE& z); // prevent copying
- void InitWithPQI3 (const PRQINFO3* pInfo);
-
- PRQINFO3* mpPQI3;
- unsigned mPQI3BufSize;
- char mDriverName [DRIV_NAME_SIZE + 1]; // Driver name
- char mDeviceName [DRIV_DEVICENAME_SIZE + 1]; // Device name
- char mPrinterName [PRINTERNAME_SIZE + 1]; // Printer name
-};
-
-
-PRTQUEUE::PRTQUEUE (const PRTQUEUE& PQInfo)
-{
- mPQI3BufSize = PQInfo.mPQI3BufSize;
- mpPQI3 = (PRQINFO3*)malloc (mPQI3BufSize);
- memcpy (mpPQI3, PQInfo.mpPQI3, mPQI3BufSize); // Copy entire buffer
-
- long Diff = (long)mpPQI3 - (long)PQInfo.mpPQI3; // Calculate the difference between addresses
- SHIFT_PTR (mpPQI3->pszName, Diff); // Modify internal pointers accordingly
- SHIFT_PTR (mpPQI3->pszSepFile, Diff);
- SHIFT_PTR (mpPQI3->pszPrProc, Diff);
- SHIFT_PTR (mpPQI3->pszParms, Diff);
- SHIFT_PTR (mpPQI3->pszComment, Diff);
- SHIFT_PTR (mpPQI3->pszPrinters, Diff);
- SHIFT_PTR (mpPQI3->pszDriverName, Diff);
- SHIFT_PTR (mpPQI3->pDriverData, Diff);
-
- strcpy (mDriverName, PQInfo.mDriverName);
- strcpy (mDeviceName, PQInfo.mDeviceName);
- strcpy (mPrinterName, PQInfo.mPrinterName);
-}
-
-void PRTQUEUE::InitWithPQI3(const PRQINFO3* pInfo)
-{
- // Make local copy of PPRQINFO3 object
- ULONG SizeNeeded;
- ::SplQueryQueue (NULL, pInfo->pszName, 3, NULL, 0, &SizeNeeded);
- mpPQI3 = (PRQINFO3*)malloc (SizeNeeded);
- ::SplQueryQueue (NULL, pInfo->pszName, 3, mpPQI3, SizeNeeded, &SizeNeeded);
-
- mPQI3BufSize = SizeNeeded;
-
- PCHAR sep = strchr (pInfo->pszDriverName, '.');
-
- if (sep)
- {
- *sep = '\0';
- strcpy (mDriverName, pInfo->pszDriverName);
- strcpy (mDeviceName, sep + 1);
- *sep = '.';
- } else
- {
- strcpy (mDriverName, pInfo->pszDriverName);
- mDeviceName [0] = '\0';
- }
-
-
- sep = strchr (pInfo->pszPrinters, ',');
-
- if (sep)
- {
- *sep = '\0';
- strcpy (mPrinterName, pInfo->pszPrinters);
- *sep = '.';
- } else
- {
- strcpy (mPrinterName, pInfo->pszPrinters);
- }
-}
-
-
-//===========================================================================
-
-PRINTDLG::PRINTDLG()
-{
- mQueueCount = 0;
-
- ULONG TotalQueues = 0;
- ULONG MemNeeded = 0;
- SPLERR rc;
-
- rc = ::SplEnumQueue(NULL, 3, NULL, 0, &mQueueCount, &TotalQueues, &MemNeeded, NULL);
- PRQINFO3* pPQI3Buf = (PRQINFO3*) malloc (MemNeeded);
- rc = ::SplEnumQueue(NULL, 3, pPQI3Buf, MemNeeded, &mQueueCount, &TotalQueues, &MemNeeded, NULL);
-
- if (mQueueCount > MAX_PRINT_QUEUES)
- mQueueCount = MAX_PRINT_QUEUES;
-
- ULONG defaultQueue = 0;
- for (ULONG cnt = 0; cnt < mQueueCount; cnt++) {
- if (pPQI3Buf[cnt].fsType & PRQ3_TYPE_APPDEFAULT)
- defaultQueue = cnt;
- mPQBuf[cnt] = new PRTQUEUE(&pPQI3Buf[cnt]);
- }
-
- // move the entry for the default printer to index 0 (if necessary)
- if (defaultQueue > 0) {
- PRTQUEUE* temp = mPQBuf[0];
- mPQBuf[0] = mPQBuf[defaultQueue];
- mPQBuf[defaultQueue] = temp;
- }
-
- free(pPQI3Buf);
-}
-
-PRINTDLG::~PRINTDLG()
-{
- for (ULONG index = 0; index < mQueueCount; index++)
- delete mPQBuf[index];
-}
-
-void PRINTDLG::RefreshPrintQueue()
-{
- ULONG newQueueCount = 0;
- ULONG TotalQueues = 0;
- ULONG MemNeeded = 0;
- SPLERR rc;
-
- rc = ::SplEnumQueue(NULL, 3, NULL, 0, &newQueueCount, &TotalQueues, &MemNeeded, NULL);
- PRQINFO3* pPQI3Buf = (PRQINFO3*)malloc(MemNeeded);
- rc = ::SplEnumQueue(NULL, 3, pPQI3Buf, MemNeeded, &newQueueCount, &TotalQueues, &MemNeeded, NULL);
-
- if (newQueueCount > MAX_PRINT_QUEUES)
- newQueueCount = MAX_PRINT_QUEUES;
-
- PRTQUEUE* tmpBuf[MAX_PRINT_QUEUES];
-
- ULONG defaultQueue = 0;
- for (ULONG cnt = 0; cnt < newQueueCount; cnt++) {
- if (pPQI3Buf[cnt].fsType & PRQ3_TYPE_APPDEFAULT)
- defaultQueue = cnt;
-
- BOOL found = FALSE;
- for (ULONG index = 0; index < mQueueCount && !found; index++) {
- //Compare printer from requeried list with what's already in Mozilla's printer list(mPQBuf)
- //If printer is already there, use current properties; otherwise create a new printer in list
- if (mPQBuf[index] != 0) {
- if ((strcmp(pPQI3Buf[cnt].pszPrinters, mPQBuf[index]->PrinterName()) == 0) &&
- (strcmp(pPQI3Buf[cnt].pszDriverName, mPQBuf[index]->PQI3().pszDriverName) == 0)) {
- found = TRUE;
- tmpBuf[cnt] = mPQBuf[index];
- mPQBuf[index] = 0;
- }
- }
- }
- if (!found)
- tmpBuf[cnt] = new PRTQUEUE(&pPQI3Buf[cnt]);
- }
-
- for (ULONG index = 0; index < newQueueCount; index++) {
- if (mPQBuf[index] != 0)
- delete(mPQBuf[index]);
- mPQBuf[index] = tmpBuf[index];
- }
-
- if (mQueueCount > newQueueCount)
- for (ULONG index = newQueueCount; index < mQueueCount; index++)
- if (mPQBuf[index] != 0)
- delete(mPQBuf[index]);
-
- mQueueCount = newQueueCount;
-
- // move the entry for the default printer to index 0 (if necessary)
- if (defaultQueue > 0) {
- PRTQUEUE* temp = mPQBuf[0];
- mPQBuf[0] = mPQBuf[defaultQueue];
- mPQBuf[defaultQueue] = temp;
- }
-
- free(pPQI3Buf);
-}
-
-ULONG PRINTDLG::GetNumPrinters()
-{
- return mQueueCount;
-}
-
-void PRINTDLG::GetPrinter(ULONG printerNdx, char** printerName)
-{
- if (printerNdx >= mQueueCount)
- return;
-
- nsCAutoString pName(mPQBuf[printerNdx]->QueueName());
-
- pName.ReplaceChar('\r', ' ');
- pName.StripChars("\n");
- *printerName = ToNewCString(pName);
-}
-
-PRTQUEUE* PRINTDLG::SetPrinterQueue(ULONG printerNdx)
-{
- PRTQUEUE *pPQ = NULL;
-
- if (printerNdx >= mQueueCount)
- return NULL;
-
- pPQ = mPQBuf[printerNdx];
-
- return new PRTQUEUE(*pPQ);
-}
-
-LONG PRINTDLG::GetPrintDriverSize(ULONG printerNdx)
-{
- return mPQBuf[printerNdx]->PQI3().pDriverData->cb;
-}
-
-PDRIVDATA PRINTDLG::GetPrintDriver(ULONG printerNdx)
-{
- if (printerNdx >= mQueueCount)
- return NULL;
-
- return mPQBuf[printerNdx]->PQI3().pDriverData;
-}
-
-HDC PRINTDLG::GetDCHandle(ULONG printerNdx)
-{
- HDC hdc = 0;
- DEVOPENSTRUC dop;
-
- dop.pszLogAddress = 0;
- dop.pszDriverName = (char *)mPQBuf[printerNdx]->DriverName();
- dop.pdriv = mPQBuf[printerNdx]->PQI3().pDriverData;
- dop.pszDataType = 0;
- dop.pszComment = 0;
- dop.pszQueueProcName = 0;
- dop.pszQueueProcParams = 0;
- dop.pszSpoolerParams = 0;
- dop.pszNetworkParams = 0;
-
- hdc = ::DevOpenDC(0, OD_INFO, "*", 9, (PDEVOPENDATA) &dop, NULLHANDLE);
- return hdc;
-}
-
-char* PRINTDLG::GetDriverType(ULONG printerNdx)
-{
- return (char *)mPQBuf[printerNdx]->DriverName ();
-}
-
-BOOL PRINTDLG::ShowProperties(ULONG printerNdx)
-{
- BOOL rc = FALSE;
- LONG devrc = FALSE;
- PDRIVDATA pOldDrivData;
- PDRIVDATA pNewDrivData = NULL;
- LONG buflen;
-
-/* check size of buffer required for job properties */
- buflen = DevPostDeviceModes( 0 /*hab*/,
- NULL,
- mPQBuf[printerNdx]->DriverName (),
- mPQBuf[printerNdx]->DeviceName (),
- mPQBuf[printerNdx]->PrinterName (),
- DPDM_POSTJOBPROP);
-
-/* return error to caller */
- if (buflen <= 0)
- return(buflen);
-
-/* allocate some memory for larger job properties and */
-/* return error to caller */
-
- if (buflen != mPQBuf[printerNdx]->PQI3().pDriverData->cb)
- {
- if (DosAllocMem((PPVOID)&pNewDrivData,buflen,fALLOC))
- return(FALSE); // DPDM_ERROR
-
-/* copy over old data so driver can use old job */
-/* properties as base for job properties dialog */
- pOldDrivData = mPQBuf[printerNdx]->PQI3().pDriverData;
- mPQBuf[printerNdx]->PQI3().pDriverData = pNewDrivData;
- memcpy( (PSZ)pNewDrivData, (PSZ)pOldDrivData, pOldDrivData->cb );
- }
-
-/* display job properties dialog and get updated */
-/* job properties from driver */
-
- devrc = DevPostDeviceModes( 0 /*hab*/,
- mPQBuf[printerNdx]->PQI3().pDriverData,
- mPQBuf[printerNdx]->DriverName (),
- mPQBuf[printerNdx]->DeviceName (),
- mPQBuf[printerNdx]->PrinterName (),
- DPDM_POSTJOBPROP);
- rc = (devrc != DPDM_ERROR);
- return rc;
-}
-
-/****************************************************************************/
-/* Job management */
-/****************************************************************************/
-
-NS_GFX_(HDC) PrnOpenDC( PRTQUEUE *pInfo, PSZ pszApplicationName, int copies, int destination, char *file )
-{
- HDC hdc = 0;
- PSZ pszLogAddress;
- PSZ pszDataType;
- LONG dcType;
- DEVOPENSTRUC dop;
-
- if (!pInfo || !pszApplicationName)
- return hdc;
-
- if ( destination ) {
- pszLogAddress = pInfo->PQI3 ().pszName;
- pszDataType = "PM_Q_STD";
- if ( destination == 2 )
- dcType = OD_METAFILE;
- else
- dcType = OD_QUEUED;
- } else {
- if (file && *file)
- pszLogAddress = (PSZ) file;
- else
- pszLogAddress = "FILE";
- pszDataType = "PM_Q_RAW";
- dcType = OD_DIRECT;
- }
-
- dop.pszLogAddress = pszLogAddress;
- dop.pszDriverName = (char*)pInfo->DriverName ();
- dop.pdriv = pInfo->PQI3 ().pDriverData;
- dop.pszDataType = pszDataType;
- dop.pszComment = pszApplicationName;
- dop.pszQueueProcName = pInfo->PQI3 ().pszPrProc;
- dop.pszQueueProcParams = 0;
- dop.pszSpoolerParams = 0;
- dop.pszNetworkParams = 0;
-
- hdc = ::DevOpenDC( 0, dcType, "*", 9, (PDEVOPENDATA) &dop, NULLHANDLE);
-
-#ifdef DEBUG
- if (hdc == 0)
- {
- ULONG ErrorCode = ERRORIDERROR (::WinGetLastError (0));
- printf ("!ERROR! - Can't open DC for printer %04lX\a\n", ErrorCode);
- }
-#endif
-
- return hdc;
-}
-
-/* find the selected form */
-NS_GFX_(BOOL) PrnQueryHardcopyCaps( HDC hdc, PHCINFO pHCInfo)
-{
- BOOL rc = FALSE;
-
- if( hdc && pHCInfo)
- {
- PHCINFO pBuffer;
- long lAvail, i;
-
- /* query how many forms are available */
- lAvail = ::DevQueryHardcopyCaps( hdc, 0, 0, NULL);
-
- pBuffer = (PHCINFO) malloc( lAvail * sizeof(HCINFO));
-
- ::DevQueryHardcopyCaps( hdc, 0, lAvail, pBuffer);
-
- for( i = 0; i < lAvail; i++)
- if( pBuffer[ i].flAttributes & HCAPS_CURRENT)
- {
- memcpy( pHCInfo, pBuffer + i, sizeof(HCINFO));
- rc = TRUE;
- break;
- }
-
- free( pBuffer);
- }
-
- return rc;
-}
-
-
-/****************************************************************************/
-/* Library-level data and functions -Printing */
-/****************************************************************************/
-
-NS_GFX_(BOOL) PrnInitialize( HMODULE hmodResources)
-{
- hmodRes = hmodResources;
- return TRUE;
-}
-
-NS_GFX_(BOOL) PrnTerminate()
-{
- /* nop for now, may do something eventually */
- return TRUE;
-}
-
-NS_GFX_(BOOL) PrnClosePrinter( PRTQUEUE *pPrintQueue)
-{
- BOOL rc = FALSE;
-
- if (pPrintQueue)
- {
- delete pPrintQueue;
- rc = TRUE;
- }
-
- return rc;
-}
-
deleted file mode 100644
--- a/gfx/src/os2/nsPrintOS2.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * John Fairhurst <john_fairhurst@iname.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef nsPrintOS2_h___
-#define nsPrintOS2_h___
-
-#define INCL_PM
-#define INCL_DOS
-#define INCL_DOSERRORS
-#define INCL_SPLDOSPRINT
-#define INCL_DEV
-#define INCL_DEVDJP
-#define INCL_GRE_DEVICE
-#include <os2.h>
-#include <pmddim.h>
-#include "gfxCore.h"
-
-//---------------------------------------------------------------------------
-// OS/2 Printing - was in libprint
-//---------------------------------------------------------------------------
-// Library init and term; job properties per queue are cached during run.
-NS_GFX_(BOOL) PrnInitialize(HMODULE hmodResources);
-NS_GFX_(BOOL) PrnTerminate(void);
-
-// opaque type to describe a print queue (printer)
-class NS_GFX PRTQUEUE;
-
-#define MAX_PRINT_QUEUES (128)
-
-class NS_GFX PRINTDLG
-{
-public:
- PRINTDLG();
- ~PRINTDLG();
- void RefreshPrintQueue();
- ULONG GetNumPrinters();
- void GetPrinter(ULONG printerNdx, char** printerName);
- PRTQUEUE* SetPrinterQueue(ULONG printerNdx);
- LONG GetPrintDriverSize(ULONG printerNdx);
- PDRIVDATA GetPrintDriver(ULONG printerNdx);
- HDC GetDCHandle(ULONG printerNdx);
- char* GetDriverType(ULONG printerNdx);
- BOOL ShowProperties(ULONG printerNdx);
-
-private:
- ULONG mQueueCount;
- PRTQUEUE* mPQBuf[MAX_PRINT_QUEUES];
-};
-
-
-// Release app. resources associated with a printer
-NS_GFX_(BOOL) PrnClosePrinter( PRTQUEUE *pPrintQueue);
-
-// Get a DC for the selected printer. Must supply the application name.
-NS_GFX_(HDC) PrnOpenDC( PRTQUEUE *pPrintQueue, PSZ pszApplicationName, int copies, int destination, char *file);
-
-// Get the hardcopy caps for the selected form
-NS_GFX_(BOOL) PrnQueryHardcopyCaps( HDC hdc, PHCINFO pHCInfo);
-
-// Abort the current job started with PrnStartJob().
-NS_GFX_(BOOL) PrnAbortJob( HDC hdc);
-
-
-
-#endif
deleted file mode 100644
--- a/gfx/src/os2/nsRegionOS2.cpp
+++ /dev/null
@@ -1,270 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Dainis Jonitis, <Dainis_Jonitis@swh-t.lv>.
- * Portions created by the Initial Developer are Copyright (C) 2001
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsRegionOS2.h"
-#include "nsGfxDefs.h"
-
-nsRegionOS2::nsRegionOS2()
-{
-}
-
-NS_IMPL_ISUPPORTS1(nsRegionOS2, nsIRegion)
-
-PRUint32 nsRegionOS2::NumOfRects (HPS aPS, HRGN aRegion) const
-{
- RGNRECT rgnRect;
- rgnRect.ircStart = 1;
- rgnRect.crc = 0xFFFFFFFF;
- rgnRect.crcReturned = 0;
- rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT;
-
- GFX (::GpiQueryRegionRects (aPS, aRegion, NULL, &rgnRect, NULL), FALSE);
-
- return rgnRect.crcReturned;
-}
-
-HRGN nsRegionOS2::GetHRGN (PRUint32 DestHeight, HPS DestPS)
-{
- PRUint32 NumRects = mRegion.GetNumRects ();
-
- if (NumRects > 0)
- {
- PRECTL pRects = new RECTL [NumRects];
-
- nsRegionRectIterator ri (mRegion);
- const nsRect* pSrc;
- PRECTL pDest = pRects;
-
- while ((pSrc = ri.Next()))
- {
- pDest->xLeft = pSrc->x;
- pDest->xRight = pSrc->XMost ();
- pDest->yTop = DestHeight - pSrc->y;
- pDest->yBottom = pDest->yTop - pSrc->height;
- pDest++;
- }
-
- HRGN rgn = GFX (::GpiCreateRegion (DestPS, NumRects, pRects), RGN_ERROR);
- delete [] pRects;
-
- return rgn;
- } else
- {
- return GFX (::GpiCreateRegion (DestPS, 0, NULL), RGN_ERROR);
- }
-}
-
-// For copying from an existing region who has height & possibly diff. hdc
-nsresult nsRegionOS2::InitWithHRGN (HRGN SrcRegion, PRUint32 SrcHeight, HPS SrcPS)
-{
- PRUint32 NumRects = NumOfRects (SrcPS, SrcRegion);
- mRegion.SetEmpty ();
-
- if (NumRects > 0)
- {
- RGNRECT RgnControl = { 1, NumRects, 0, RECTDIR_LFRT_TOPBOT };
- PRECTL pRects = new RECTL [NumRects];
-
- GFX (::GpiQueryRegionRects (SrcPS, SrcRegion, NULL, &RgnControl, pRects), FALSE);
-
- for (PRUint32 cnt = 0 ; cnt < NumRects ; cnt++)
- mRegion.Or (mRegion, nsRect ( pRects [cnt].xLeft, SrcHeight - pRects [cnt].yTop,
- pRects [cnt].xRight - pRects [cnt].xLeft, pRects [cnt].yTop - pRects [cnt].yBottom));
-
- delete [] pRects;
- }
-
- return NS_OK;
-}
-
-nsresult nsRegionOS2::Init (void)
-{
- mRegion.SetEmpty ();
- return NS_OK;
-}
-
-void nsRegionOS2::SetTo (const nsIRegion &aRegion)
-{
- const nsRegionOS2* pRegion = static_cast<const nsRegionOS2*>(&aRegion);
- mRegion = pRegion->mRegion;
-}
-
-void nsRegionOS2::SetTo (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
-{
- mRegion = nsRect (aX, aY, aWidth, aHeight);
-}
-
-void nsRegionOS2::Intersect (const nsIRegion &aRegion)
-{
- const nsRegionOS2* pRegion = static_cast<const nsRegionOS2*>(&aRegion);
- mRegion.And (mRegion, pRegion->mRegion);
-}
-
-void nsRegionOS2::Intersect (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
-{
- mRegion.And (mRegion, nsRect (aX, aY, aWidth, aHeight));
-}
-
-void nsRegionOS2::Union (const nsIRegion &aRegion)
-{
- const nsRegionOS2* pRegion = static_cast<const nsRegionOS2*>(&aRegion);
- mRegion.Or (mRegion, pRegion->mRegion);
-}
-
-void nsRegionOS2::Union (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
-{
- mRegion.Or (mRegion, nsRect (aX, aY, aWidth, aHeight));
-}
-
-void nsRegionOS2::Subtract (const nsIRegion &aRegion)
-{
- const nsRegionOS2* pRegion = static_cast<const nsRegionOS2*>(&aRegion);
- mRegion.Sub (mRegion, pRegion->mRegion);
-}
-
-void nsRegionOS2::Subtract (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
-{
- mRegion.Sub (mRegion, nsRect (aX, aY, aWidth, aHeight));
-}
-
-PRBool nsRegionOS2::IsEmpty (void)
-{
- return mRegion.IsEmpty ();
-}
-
-PRBool nsRegionOS2::IsEqual (const nsIRegion &aRegion)
-{
- const nsRegionOS2* pRegion = static_cast<const nsRegionOS2*>(&aRegion);
- return mRegion.IsEqual (pRegion->mRegion);
-}
-
-void nsRegionOS2::GetBoundingBox (PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight)
-{
- const nsRect& BoundRect = mRegion.GetBounds();
- *aX = BoundRect.x;
- *aY = BoundRect.y;
- *aWidth = BoundRect.width;
- *aHeight = BoundRect.height;
-}
-
-void nsRegionOS2::Offset (PRInt32 aXOffset, PRInt32 aYOffset)
-{
- mRegion.MoveBy (aXOffset, aYOffset);
-}
-
-PRBool nsRegionOS2::ContainsRect (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
-{
- nsRegion TmpRegion;
- TmpRegion.And (mRegion, nsRect (aX, aY, aWidth, aHeight));
- return (!TmpRegion.IsEmpty ());
-}
-
-nsresult nsRegionOS2::GetRects (nsRegionRectSet **aRects)
-{
- if (!aRects)
- return NS_ERROR_NULL_POINTER;
-
- nsRegionRectSet* pRegionSet = *aRects;
- PRUint32 NumRects = mRegion.GetNumRects ();
-
- if (!pRegionSet) // Not yet allocated
- {
- PRUint8* pBuf = new PRUint8 [sizeof (nsRegionRectSet) + NumRects * sizeof (nsRegionRect)];
- pRegionSet = reinterpret_cast<nsRegionRectSet*>(pBuf);
- pRegionSet->mRectsLen = NumRects + 1;
- } else // Already allocated in previous call
- {
- if (NumRects > pRegionSet->mRectsLen) // passed array is not big enough - reallocate it.
- {
- delete [] reinterpret_cast<PRUint8*>(pRegionSet);
- PRUint8* pBuf = new PRUint8 [sizeof (nsRegionRectSet) + NumRects * sizeof (nsRegionRect)];
- pRegionSet = reinterpret_cast<nsRegionRectSet*>(pBuf);
- pRegionSet->mRectsLen = NumRects + 1;
- }
- }
- pRegionSet->mNumRects = NumRects;
- *aRects = pRegionSet;
-
-
- nsRegionRectIterator ri (mRegion);
- nsRegionRect* pDest = &pRegionSet->mRects [0];
- const nsRect* pSrc;
-
- while ((pSrc = ri.Next ()) != nsnull)
- {
- pDest->x = pSrc->x;
- pDest->y = pSrc->y;
- pDest->width = pSrc->width;
- pDest->height = pSrc->height;
-
- ++pDest;
- }
-
- return NS_OK;
-}
-
-nsresult nsRegionOS2::FreeRects (nsRegionRectSet *aRects)
-{
- if (!aRects)
- return NS_ERROR_NULL_POINTER;
-
- delete [] reinterpret_cast<PRUint8*>(aRects);
- return NS_OK;
-}
-
-nsresult nsRegionOS2::GetNativeRegion (void *&aRegion) const
-{
- aRegion = RGN_ERROR;
- return NS_OK;
-}
-
-nsresult nsRegionOS2::GetRegionComplexity (nsRegionComplexity &aComplexity) const
-{
- switch (mRegion.GetNumRects ())
- {
- case 0: aComplexity = eRegionComplexity_empty; break;
- case 1: aComplexity = eRegionComplexity_rect; break;
- default: aComplexity = eRegionComplexity_complex; break;
- }
-
- return NS_OK;
-}
-
-nsresult nsRegionOS2::GetNumRects (PRUint32 *aRects) const
-{
- *aRects = mRegion.GetNumRects ();
- return NS_OK;
-}
deleted file mode 100644
--- a/gfx/src/os2/nsRegionOS2.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Dainis Jonitis, <Dainis_Jonitis@swh-t.lv>.
- * Portions created by the Initial Developer are Copyright (C) 2001
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-
-#ifndef _nsRegionOS2_h
-#define _nsRegionOS2_h
-
-#include "nsiRegion.h"
-#include "nsRegion.h"
-#define INCL_GPI
-#include <os2.h>
-
-class nsRegionOS2 : public nsIRegion
-{
- PRUint32 NumOfRects (HPS aPS, HRGN aRegion) const;
-
-public:
- nsRegionOS2 ();
-
- NS_DECL_ISUPPORTS
-
- virtual nsresult Init();
-
- virtual void SetTo(const nsIRegion &aRegion);
- virtual void SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
- virtual void Intersect(const nsIRegion &aRegion);
- virtual void Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
- virtual void Union(const nsIRegion &aRegion);
- virtual void Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
- virtual void Subtract(const nsIRegion &aRegion);
- virtual void Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
- virtual PRBool IsEmpty(void);
- virtual PRBool IsEqual(const nsIRegion &aRegion);
- virtual void GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight);
- virtual void Offset(PRInt32 aXOffset, PRInt32 aYOffset);
- virtual PRBool ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
- NS_IMETHOD GetRects(nsRegionRectSet **aRects);
- NS_IMETHOD FreeRects(nsRegionRectSet *aRects);
- // Don't use this on OS/2 - Use GetHRGN () instead
- NS_IMETHOD GetNativeRegion(void *&aRegion) const;
- NS_IMETHOD GetRegionComplexity(nsRegionComplexity &aComplexity) const;
- NS_IMETHOD GetNumRects(PRUint32 *aRects) const;
-
- // OS/2 specific
- // get region in widget's coord space for given device
- HRGN GetHRGN (PRUint32 ulHeight, HPS hps);
-
- // copy from another region defined in aWidget's space for a given device
- nsresult InitWithHRGN (HRGN copy, PRUint32 ulHeight, HPS hps);
-private:
- nsRegion mRegion;
-};
-
-#endif
deleted file mode 100644
--- a/gfx/src/os2/nsRenderingContextOS2.cpp
+++ /dev/null
@@ -1,2456 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Mozilla OS/2 libraries.
- *
- * The Initial Developer of the Original Code is
- * John Fairhurst, <john_fairhurst@iname.com>.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Henry Sobotka <sobotka@axess.com> Jan. 2000 review and update
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK *****
- *
- * This Original Code has been modified by IBM Corporation.
- * Modifications made by IBM described herein are
- * Copyright (c) International Business Machines
- * Corporation, 2000
- *
- * Modifications to Mozilla code or documentation
- * identified per MPL Section 3.3
- *
- * Date Modified by Description of modification
- * 03/23/2000 IBM Corp. Fixed InvertRect.
- * 05/08/2000 IBM Corp. Fix for trying to us an already freed mGammaTable.
- * 05/31/2000 IBM Corp. Fix background color on PS printers.
- *
- */
-
-// ToDo: Unicode text draw-er
-#include "nsGfxDefs.h"
-
-#include "nsRenderingContextOS2.h"
-#include "nsFontMetricsOS2.h"
-#include "nsRegionOS2.h"
-#include "nsDeviceContextOS2.h"
-#include "prprf.h"
-#include "nsGfxCIID.h"
-#include "nsUnicharUtils.h"
-
-
-// helper clip region functions - defined at the bottom of this file.
-LONG OS2_CombineClipRegion( HPS hps, HRGN hrgnCombine, LONG lMode);
-HRGN OS2_CopyClipRegion( HPS hps);
-#define OS2_SetClipRegion(hps,hrgn) OS2_CombineClipRegion(hps, hrgn, CRGN_COPY)
-
-#define FLAG_CLIP_VALID 0x0001
-#define FLAG_CLIP_CHANGED 0x0002
-#define FLAG_LOCAL_CLIP_VALID 0x0004
-
-#define FLAGS_ALL (FLAG_CLIP_VALID | FLAG_CLIP_CHANGED | FLAG_LOCAL_CLIP_VALID)
-
-class GraphicsState
-{
-public:
- GraphicsState();
- GraphicsState(GraphicsState &aState);
- ~GraphicsState();
-
- GraphicsState *mNext;
- nsTransform2D mMatrix;
- nsRect mLocalClip;
- HRGN mClipRegion;
- nscolor mColor;
- nsIFontMetrics *mFontMetrics;
- PRInt32 mFlags;
- nsLineStyle mLineStyle;
-};
-
-GraphicsState :: GraphicsState()
-{
- mNext = nsnull;
- mMatrix.SetToIdentity();
- mLocalClip.x = mLocalClip.y = mLocalClip.width = mLocalClip.height = 0;
- mClipRegion = NULL;
- mColor = NS_RGB(0, 0, 0);
- mFontMetrics = nsnull;
- mFlags = ~FLAGS_ALL;
- mLineStyle = nsLineStyle_kSolid;
-}
-
-GraphicsState :: GraphicsState(GraphicsState &aState) :
- mMatrix(&aState.mMatrix),
- mLocalClip(aState.mLocalClip)
-{
- mNext = &aState;
- mClipRegion = NULL;
- mColor = NS_RGB(0, 0, 0);
- mFontMetrics = nsnull;
- mFlags = ~FLAGS_ALL;
- mLineStyle = aState.mLineStyle;
-}
-
-GraphicsState :: ~GraphicsState()
-{
- if (NULL != mClipRegion)
- {
- printf( "oops, leaked a region from rc-gs\n");
- mClipRegion = NULL;
- }
-}
-
-// Rendering context -------------------------------------------------------
-
-// Init-term stuff ---------------------------------------------------------
-
-nsRenderingContextOS2::nsRenderingContextOS2()
-{
- mContext = nsnull;
- mSurface = nsnull;
- mPS = 0;
- mMainSurface = nsnull;
- mColor = NS_RGB( 0, 0, 0);
- mFontMetrics = nsnull;
- mLineStyle = nsLineStyle_kSolid;
- mPreservedInitialClipRegion = PR_FALSE;
- mPaletteMode = PR_FALSE;
- mCurrFontOS2 = nsnull;
-
- mStateCache = new nsVoidArray();
- mRightToLeftText = PR_FALSE;
-
- //create an initial GraphicsState
-
- PushState();
-
- mP2T = 1.0f;
-}
-
-nsRenderingContextOS2::~nsRenderingContextOS2()
-{
- NS_IF_RELEASE(mContext);
- NS_IF_RELEASE(mFontMetrics);
-
- //destroy the initial GraphicsState
- PopState ();
-
- if (nsnull != mStateCache)
- {
- PRInt32 cnt = mStateCache->Count();
-
- while (--cnt >= 0)
- {
- GraphicsState *state = (GraphicsState *)mStateCache->ElementAt(cnt);
- if (state->mClipRegion) {
- GFX (::GpiDestroyRegion (mPS, state->mClipRegion), FALSE);
- state->mClipRegion = 0;
- }
- mStateCache->RemoveElementAt(cnt);
-
- if (nsnull != state)
- delete state;
- }
-
- delete mStateCache;
- mStateCache = nsnull;
- }
-
- // Release surfaces and the palette
- NS_IF_RELEASE(mMainSurface);
- NS_IF_RELEASE(mSurface);
-}
-
-NS_IMPL_ISUPPORTS2(nsRenderingContextOS2,
- nsIRenderingContext,
- nsIRenderingContextOS2)
-
-NS_IMETHODIMP
-nsRenderingContextOS2::Init( nsIDeviceContext *aContext,
- nsIWidget *aWindow)
-{
- mContext = aContext;
- NS_IF_ADDREF(mContext);
-
- // Create & remember an on-screen surface
- nsWindowSurface *surf = new nsWindowSurface;
- if (!surf)
- return NS_ERROR_OUT_OF_MEMORY;
-
- surf->Init(aWindow);
-
- mSurface = surf;
- mPS = mSurface->GetPS ();
- NS_ADDREF(mSurface);
-
- mDCOwner = aWindow;
- NS_IF_ADDREF(mDCOwner);
-
- // Grab another reference to the onscreen for later uniformity
- mMainSurface = mSurface;
- NS_ADDREF(mMainSurface);
-
- return CommonInit();
-}
-
-NS_IMETHODIMP
-nsRenderingContextOS2::Init( nsIDeviceContext *aContext,
- nsIDrawingSurface* aSurface)
-{
- mContext = aContext;
- NS_IF_ADDREF(mContext);
-
- // Add a couple of references to the onscreen (or print, more likely)
- mSurface = (nsDrawingSurfaceOS2 *) aSurface;
-
- if (nsnull != mSurface)
- {
- mPS = mSurface->GetPS ();
- NS_ADDREF(mSurface);
-
- mMainSurface = mSurface;
- NS_ADDREF(mMainSurface);
- }
-
- return CommonInit();
-}
-
-nsresult nsRenderingContextOS2::SetupPS(void)
-{
- LONG BlackColor, WhiteColor;
-
- // If this is a palette device, then set transparent colors
- if (((nsDeviceContextOS2*)mContext)->IsPaletteDevice())
- {
- BlackColor = GFX (::GpiQueryColorIndex(mPS, 0, MK_RGB (0x00, 0x00, 0x00)), GPI_ALTERROR); // CLR_BLACK;
- WhiteColor = GFX (::GpiQueryColorIndex(mPS, 0, MK_RGB (0xFF, 0xFF, 0xFF)), GPI_ALTERROR); // CLR_WHITE;
-
- mPaletteMode = PR_TRUE;
- }
- else
- {
- GFX (::GpiCreateLogColorTable(mPS, 0, LCOLF_RGB, 0, 0, 0), FALSE);
-
- BlackColor = MK_RGB(0x00, 0x00, 0x00);
- WhiteColor = MK_RGB(0xFF, 0xFF, 0xFF);
-
- mPaletteMode = PR_FALSE;
- }
-
- // Set image foreground and background colors. These are used in transparent images for blitting 1-bit masks.
- // To invert colors on ROP_SRCAND we map 1 to black and 0 to white
- IMAGEBUNDLE ib;
- ib.lColor = BlackColor; // map 1 in mask to 0x000000 (black) in destination
- ib.lBackColor = WhiteColor; // map 0 in mask to 0xFFFFFF (white) in destination
- ib.usMixMode = FM_OVERPAINT;
- ib.usBackMixMode = BM_OVERPAINT;
- GFX (::GpiSetAttrs(mPS, PRIM_IMAGE, IBB_COLOR | IBB_BACK_COLOR | IBB_MIX_MODE | IBB_BACK_MIX_MODE, 0, (PBUNDLE)&ib), FALSE);
-
- return NS_OK;
-}
-
-// Presentation space page units (& so world coords) are PU_PELS.
-// We have a matrix, mTMatrix, which converts from the passed in app units
-// to pels. Note there is *no* guarantee that app units == twips.
-nsresult nsRenderingContextOS2::CommonInit()
-{
- float app2dev;
-
- app2dev = mContext->AppUnitsToDevUnits();
- mTranMatrix->AddScale( app2dev, app2dev);
- mP2T = mContext->DevUnitsToAppUnits();
-
- return SetupPS();
-}
-
-// PS & drawing surface management -----------------------------------------
-
-NS_IMETHODIMP nsRenderingContextOS2::LockDrawingSurface( PRInt32 aX, PRInt32 aY,
- PRUint32 aWidth, PRUint32 aHeight,
- void **aBits,
- PRInt32 *aStride, PRInt32 *aWidthBytes,
- PRUint32 aFlags)
-{
- PushState();
-
- return mSurface->Lock( aX, aY, aWidth, aHeight, aBits,
- aStride, aWidthBytes, aFlags);
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::UnlockDrawingSurface()
-{
- mSurface->Unlock();
-
- PopState();
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsRenderingContextOS2::SelectOffScreenDrawingSurface( nsIDrawingSurface* aSurface)
-{
- if (aSurface != mSurface)
- {
- if(nsnull != aSurface)
- {
- NS_IF_RELEASE(mSurface);
- mSurface = (nsDrawingSurfaceOS2 *) aSurface;
- mPS = mSurface->GetPS ();
-
- SetupPS();
- }
- else // deselect current offscreen...
- {
- NS_IF_RELEASE(mSurface);
- mSurface = mMainSurface;
- mPS = mSurface->GetPS ();
-
- SetupPS();
- }
-
- NS_ADDREF(mSurface);
- }
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsRenderingContextOS2::GetDrawingSurface( nsIDrawingSurface* *aSurface)
-{
- *aSurface = mSurface;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsRenderingContextOS2::GetHints(PRUint32& aResult)
-{
- PRUint32 result = 0;
-
- result |= NS_RENDERING_HINT_FAST_MEASURE;
-
- aResult = result;
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::Reset()
-{
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::GetDeviceContext( nsIDeviceContext *&aContext)
-{
- NS_IF_ADDREF(mContext);
- aContext = mContext;
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2 :: PushState(void)
-{
- PRInt32 cnt = mStateCache->Count();
-
- if (cnt == 0)
- {
- if (nsnull == mStates)
- mStates = new GraphicsState();
- else
- mStates = new GraphicsState(*mStates);
- }
- else
- {
- GraphicsState *state = (GraphicsState *)mStateCache->ElementAt(cnt - 1);
- mStateCache->RemoveElementAt(cnt - 1);
-
- state->mNext = mStates;
-
- //clone state info
-
- state->mMatrix = mStates->mMatrix;
- state->mLocalClip = mStates->mLocalClip;
-// we don't want to NULL this out since we reuse the region
-// from state to state. if we NULL it, we need to also delete it,
-// which means we'll just re-create it when we push the clip state. MMP
-// state->mClipRegion = OS2_CopyClipRegion( mPS);
- state->mFlags = ~FLAGS_ALL;
- state->mLineStyle = mStates->mLineStyle;
-
- mStates = state;
- }
-
- if (nsnull != mStates->mNext)
- {
- mStates->mNext->mColor = mColor;
- mStates->mNext->mFontMetrics = mFontMetrics;
- NS_IF_ADDREF(mStates->mNext->mFontMetrics);
- }
-
- mTranMatrix = &mStates->mMatrix;
-
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2 :: PopState(void)
-{
- if (nsnull == mStates)
- {
- NS_ASSERTION(!(nsnull == mStates), "state underflow");
- }
- else
- {
- GraphicsState *oldstate = mStates;
-
- mStates = mStates->mNext;
-
- mStateCache->AppendElement(oldstate);
-
- if (nsnull != mStates)
- {
- mTranMatrix = &mStates->mMatrix;
-
- GraphicsState *pstate;
-
- if (oldstate->mFlags & FLAG_CLIP_CHANGED)
- {
- pstate = mStates;
-
- //the clip rect has changed from state to state, so
- //install the previous clip rect
-
- while ((nsnull != pstate) && !(pstate->mFlags & FLAG_CLIP_VALID))
- pstate = pstate->mNext;
-
- if (nsnull != pstate)
- {
- // set copy of pstate->mClipRegion as current clip region
- HRGN hrgn = GFX (::GpiCreateRegion (mPS, 0, NULL), RGN_ERROR);
- GFX (::GpiCombineRegion (mPS, hrgn, pstate->mClipRegion, 0, CRGN_COPY), RGN_ERROR);
- OS2_SetClipRegion (mPS, hrgn);
- }
- }
-
- oldstate->mFlags &= ~FLAGS_ALL;
-
- NS_IF_RELEASE(mFontMetrics);
- mFontMetrics = mStates->mFontMetrics;
-
- mColor = mStates->mColor;
-
- SetLineStyle(mStates->mLineStyle);
- }
- else
- mTranMatrix = nsnull;
- }
-
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::IsVisibleRect( const nsRect &aRect,
- PRBool &aIsVisible)
-{
- nsRect trect( aRect);
- mTranMatrix->TransformCoord( &trect.x, &trect.y,
- &trect.width, &trect.height);
- RECTL rcl;
- mSurface->NS2PM_ININ (trect, rcl);
-
- LONG rc = GFX (::GpiRectVisible( mPS, &rcl), RVIS_ERROR);
-
- aIsVisible = (rc == RVIS_PARTIAL || rc == RVIS_VISIBLE) ? PR_TRUE : PR_FALSE;
-
-
- return NS_OK;
-}
-
-// Return PR_TRUE if clip region is now empty
-NS_IMETHODIMP nsRenderingContextOS2::SetClipRect( const nsRect& aRect, nsClipCombine aCombine)
-{
- nsRect trect = aRect;
- RECTL rcl;
-
- mTranMatrix->TransformCoord(&trect.x, &trect.y,
- &trect.width, &trect.height);
-
- mStates->mLocalClip = aRect;
- mStates->mFlags |= FLAG_LOCAL_CLIP_VALID;
-
- //how we combine the new rect with the previous?
-
- if( trect.width == 0 || trect.height == 0)
- {
- // Mozilla assumes that clip region with zero width or height does not produce any output - everything is clipped.
- // GPI does not support clip regions with zero width or height. We cheat by creating 1x1 clip region far outside
- // of real drawing region limits.
-
- if( aCombine == nsClipCombine_kIntersect || aCombine == nsClipCombine_kReplace)
- {
- PushClipState();
-
- rcl.xLeft = -10000;
- rcl.xRight = -9999;
- rcl.yBottom = -10000;
- rcl.yTop = -9999;
-
- HRGN hrgn = GFX (::GpiCreateRegion( mPS, 1, &rcl), RGN_ERROR);
- OS2_SetClipRegion (mPS, hrgn);
- }
- else if( aCombine == nsClipCombine_kUnion || aCombine == nsClipCombine_kSubtract)
- {
- PushClipState();
-
- // Clipping region is already correct. Just need to obtain it's complexity
- POINTL Offset = { 0, 0 };
-
- GFX (::GpiOffsetClipRegion (mPS, &Offset), RGN_ERROR);
- }
- else
- NS_ASSERTION(PR_FALSE, "illegal clip combination");
- }
- else
- {
- if (aCombine == nsClipCombine_kIntersect)
- {
- PushClipState();
-
- mSurface->NS2PM_ININ (trect, rcl);
- GFX (::GpiIntersectClipRectangle(mPS, &rcl), RGN_ERROR);
- }
- else if (aCombine == nsClipCombine_kUnion)
- {
- PushClipState();
-
- mSurface->NS2PM_INEX (trect, rcl);
- HRGN hrgn = GFX (::GpiCreateRegion(mPS, 1, &rcl), RGN_ERROR);
-
- if( hrgn )
- OS2_CombineClipRegion(mPS, hrgn, CRGN_OR);
- }
- else if (aCombine == nsClipCombine_kSubtract)
- {
- PushClipState();
-
- mSurface->NS2PM_ININ (trect, rcl);
- GFX (::GpiExcludeClipRectangle(mPS, &rcl), RGN_ERROR);
- }
- else if (aCombine == nsClipCombine_kReplace)
- {
- PushClipState();
-
- mSurface->NS2PM_INEX (trect, rcl);
- HRGN hrgn = GFX (::GpiCreateRegion(mPS, 1, &rcl), RGN_ERROR);
-
- if( hrgn )
- OS2_SetClipRegion(mPS, hrgn);
- }
- else
- NS_ASSERTION(PR_FALSE, "illegal clip combination");
- }
-
- return NS_OK;
-}
-
-// rc is whether there is a cliprect to return
-NS_IMETHODIMP nsRenderingContextOS2::GetClipRect( nsRect &aRect, PRBool &aClipValid)
-{
- if (mStates->mFlags & FLAG_LOCAL_CLIP_VALID)
- {
- aRect = mStates->mLocalClip;
- aClipValid = PR_TRUE;
- }
- else
- aClipValid = PR_FALSE;
-
- return NS_OK;
-}
-
-// Return PR_TRUE if clip region is now empty
-NS_IMETHODIMP nsRenderingContextOS2::SetClipRegion( const nsIRegion &aRegion, nsClipCombine aCombine)
-{
- nsRegionOS2 *pRegion = (nsRegionOS2 *) &aRegion;
- PRUint32 ulHeight = mSurface->GetHeight ();
-
- HRGN hrgn = pRegion->GetHRGN( ulHeight, mPS);
- LONG cmode = 0L;
-
- switch( aCombine)
- {
- case nsClipCombine_kIntersect:
- cmode = CRGN_AND;
- break;
- case nsClipCombine_kUnion:
- cmode = CRGN_OR;
- break;
- case nsClipCombine_kSubtract:
- cmode = CRGN_DIFF;
- break;
- case nsClipCombine_kReplace:
- cmode = CRGN_COPY;
- break;
- default:
- // Compiler informational...
- NS_ASSERTION( 0, "illegal clip combination");
- break;
- }
-
- if (NULL != hrgn)
- {
- mStates->mFlags &= ~FLAG_LOCAL_CLIP_VALID;
- PushClipState();
- OS2_CombineClipRegion( mPS, hrgn, cmode);
- }
- else
- return PR_FALSE;
-
- return NS_OK;
-}
-
-/**
- * Fills in |aRegion| with a copy of the current clip region.
- */
-NS_IMETHODIMP nsRenderingContextOS2::CopyClipRegion(nsIRegion &aRegion)
-{
-#if 0
- HRGN hr = OS2_CopyClipRegion(mPS);
-
- if (hr == HRGN_ERROR)
- return NS_ERROR_FAILURE;
-
- ((nsRegionOS2 *)&aRegion)->mRegion = hr;
-
- return NS_OK;
-#else
- NS_ASSERTION( 0, "nsRenderingContextOS2::CopyClipRegion() not implemented" );
- return NS_ERROR_NOT_IMPLEMENTED;
-#endif
-}
-
-// Somewhat dubious & rather expensive
-NS_IMETHODIMP nsRenderingContextOS2::GetClipRegion( nsIRegion **aRegion)
-{
- if( !aRegion)
- return NS_ERROR_NULL_POINTER;
-
- *aRegion = 0;
-
- nsRegionOS2 *pRegion = new nsRegionOS2;
- if (!pRegion)
- return NS_ERROR_OUT_OF_MEMORY;
- NS_ADDREF(pRegion);
-
- // Get current clip region
- HRGN hrgnClip = 0;
-
- GFX (::GpiSetClipRegion (mPS, 0, &hrgnClip), RGN_ERROR);
-
- if( hrgnClip && hrgnClip != HRGN_ERROR)
- {
- // There was a clip region, so get it & init.
- HRGN hrgnDummy = 0;
- PRUint32 ulHeight = mSurface->GetHeight ();
-
- pRegion->InitWithHRGN (hrgnClip, ulHeight, mPS);
- GFX (::GpiSetClipRegion (mPS, hrgnClip, &hrgnDummy), RGN_ERROR);
- }
- else
- pRegion->Init();
-
- *aRegion = pRegion;
-
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::SetColor( nscolor aColor)
-{
- mColor = aColor;
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::GetColor( nscolor &aColor) const
-{
- aColor = mColor;
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::SetLineStyle( nsLineStyle aLineStyle)
-{
- mLineStyle = aLineStyle;
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::GetLineStyle( nsLineStyle &aLineStyle)
-{
- aLineStyle = mLineStyle;
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::SetFont( const nsFont &aFont, nsIAtom* aLangGroup)
-{
- mCurrFontOS2 = nsnull; // owned & released by mFontMetrics
- NS_IF_RELEASE(mFontMetrics);
- mContext->GetMetricsFor(aFont, aLangGroup, mFontMetrics);
-
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::SetFont( nsIFontMetrics *aFontMetrics)
-{
- mCurrFontOS2 = nsnull; // owned & released by mFontMetrics
- NS_IF_RELEASE(mFontMetrics);
- mFontMetrics = aFontMetrics;
- NS_IF_ADDREF(mFontMetrics);
-
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::GetFontMetrics( nsIFontMetrics*& aFontMetrics)
-{
- NS_IF_ADDREF(mFontMetrics);
- aFontMetrics = mFontMetrics;
-
- return NS_OK;
-}
-
-// add the passed in translation to the current translation
-NS_IMETHODIMP nsRenderingContextOS2::Translate( nscoord aX, nscoord aY)
-{
- mTranMatrix->AddTranslation( (float) aX, (float) aY);
- return NS_OK;
-}
-
-// add the passed in scale to the current scale
-NS_IMETHODIMP nsRenderingContextOS2::Scale( float aSx, float aSy)
-{
- mTranMatrix->AddScale(aSx, aSy);
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::GetCurrentTransform( nsTransform2D *&aTransform)
-{
- aTransform = mTranMatrix;
- return NS_OK;
-}
-
-
-// The idea here is to create an offscreen surface for blitting with.
-// I can't find any way for people to resize the bitmap created here,
-// so I guess this gets called quite often.
-//
-// I'm reliably told that 'aBounds' is in device units, and that the
-// position oughtn't to be ignored, but for all intents & purposes can be.
-//
-NS_IMETHODIMP nsRenderingContextOS2::CreateDrawingSurface(const nsRect& aBounds,
- PRUint32 aSurfFlags, nsIDrawingSurface* &aSurface)
-{
- nsresult rc = NS_ERROR_FAILURE;
-
- nsOffscreenSurface *surf = new nsOffscreenSurface;
-
- if (!surf)
- return NS_ERROR_OUT_OF_MEMORY;
-
- rc = surf->Init( mMainSurface->GetPS (), aBounds.width, aBounds.height, aSurfFlags);
-
- if(NS_SUCCEEDED(rc))
- {
- NS_ADDREF(surf);
- aSurface = surf;
- }
- else
- delete surf;
-
- return rc;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::CreateDrawingSurface(HPS aPS, nsIDrawingSurface* &aSurface, nsIWidget *aWidget)
-{
- nsWindowSurface *surf = new nsWindowSurface();
-
- if (nsnull != surf)
- {
- NS_ADDREF(surf);
- surf->Init(aPS, aWidget);
- }
-
- aSurface = surf;
-
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::DestroyDrawingSurface( nsIDrawingSurface* aDS)
-{
- nsDrawingSurfaceOS2 *surf = (nsDrawingSurfaceOS2 *) aDS;
- nsresult rc = NS_ERROR_NULL_POINTER;
-
- // If the surface being destroyed is the one we're currently using for
- // offscreen, then lose our reference to it & hook back to the onscreen.
- if( surf && surf == mSurface)
- {
- NS_RELEASE(mSurface); // ref. from SelectOffscreen
- mSurface = mMainSurface;
- mPS = mSurface->GetPS ();
- NS_ADDREF(mSurface);
- }
-
- if( surf)
- {
- NS_RELEASE(surf); // ref. from CreateSurface
- rc = NS_OK;
- }
-
- return rc;
-}
-
-// Drawing methods ---------------------------------------------------------
-
-LONG nsRenderingContextOS2::GetGPIColor (void)
-{
- LONG gcolor = MK_RGB (NS_GET_R (mColor),
- NS_GET_G (mColor),
- NS_GET_B (mColor));
-
- return (mPaletteMode) ? GFX (::GpiQueryColorIndex (mPS, 0, gcolor), GPI_ALTERROR) :
- gcolor ;
-}
-
-void nsRenderingContextOS2::SetupLineColorAndStyle (void)
-{
-
- LINEBUNDLE lineBundle;
- lineBundle.lColor = GetGPIColor ();
-
- GFX (::GpiSetAttrs (mPS, PRIM_LINE, LBB_COLOR, 0, (PBUNDLE)&lineBundle), FALSE);
-
- long ltype = 0;
- switch( mLineStyle)
- {
- case nsLineStyle_kNone: ltype = LINETYPE_INVISIBLE; break;
- case nsLineStyle_kSolid: ltype = LINETYPE_SOLID; break;
- case nsLineStyle_kDashed: ltype = LINETYPE_SHORTDASH; break;
- case nsLineStyle_kDotted: ltype = LINETYPE_DOT; break;
- default:
- NS_ASSERTION(0, "Unexpected line style");
- break;
- }
- GFX (::GpiSetLineType (mPS, ltype), FALSE);
-
-}
-
-void nsRenderingContextOS2::SetupFillColor (void)
-{
-
- AREABUNDLE areaBundle;
- areaBundle.lColor = GetGPIColor ();
-
- GFX (::GpiSetAttrs (mPS, PRIM_AREA, ABB_COLOR, 0, (PBUNDLE)&areaBundle), FALSE);
-
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::DrawLine( nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1)
-{
- mTranMatrix->TransformCoord( &aX0, &aY0);
- mTranMatrix->TransformCoord( &aX1, &aY1);
-
- POINTL ptls[] = { { (long) aX0, (long) aY0 },
- { (long) aX1, (long) aY1 } };
- mSurface->NS2PM (ptls, 2);
-
- if (ptls[0].x > ptls[1].x)
- ptls[0].x--;
- else if (ptls[1].x > ptls[0].x)
- ptls[1].x--;
-
- if (ptls[0].y < ptls[1].y)
- ptls[0].y++;
- else if (ptls[1].y < ptls[0].y)
- ptls[1].y++;
-
- SetupLineColorAndStyle ();
-
- GFX (::GpiMove (mPS, ptls), FALSE);
- GFX (::GpiLine (mPS, ptls + 1), GPI_ERROR);
-
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints)
-{
- PMDrawPoly( aPoints, aNumPoints, PR_FALSE);
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::DrawPolygon( const nsPoint aPoints[], PRInt32 aNumPoints)
-{
- PMDrawPoly( aPoints, aNumPoints, PR_FALSE);
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::FillPolygon( const nsPoint aPoints[], PRInt32 aNumPoints)
-{
- PMDrawPoly( aPoints, aNumPoints, PR_TRUE );
- return NS_OK;
-}
-
- // bDoTransform defaults to PR_TRUE
-void nsRenderingContextOS2::PMDrawPoly( const nsPoint aPoints[], PRInt32 aNumPoints, PRBool bFilled, PRBool bDoTransform)
-{
- if( aNumPoints > 1)
- {
- // Xform coords
- POINTL aptls[ 20];
- PPOINTL pts = aptls;
-
- if( aNumPoints > 20)
- pts = new POINTL[aNumPoints];
-
- PPOINTL pp = pts;
- const nsPoint *np = &aPoints[0];
-
- for( PRInt32 i = 0; i < aNumPoints; i++, pp++, np++)
- {
- pp->x = np->x;
- pp->y = np->y;
- if( bDoTransform )
- mTranMatrix->TransformCoord( (int*)&pp->x, (int*)&pp->y);
- }
-
- // go to os2
- mSurface->NS2PM (pts, aNumPoints);
-
- // We draw closed pgons using polyline to avoid filling it. This works
- // because the API to this class specifies that the last point must
- // be the same as the first one...
-
- GFX (::GpiMove (mPS, pts), FALSE);
-
- if( bFilled == PR_TRUE)
- {
- POLYGON pgon = { aNumPoints - 1, pts + 1 };
- //IBM-AKR changed from boundary and inclusive to be noboundary and
- // exclusive to fix bug with text fields, buttons, etc. borders
- // being 1 pel too thick. Bug 56853
- SetupFillColor ();
- GFX (::GpiPolygons (mPS, 1, &pgon, POLYGON_NOBOUNDARY, POLYGON_EXCL), GPI_ERROR);
- }
- else
- {
- SetupLineColorAndStyle ();
- GFX (::GpiPolyLine (mPS, aNumPoints - 1, pts + 1), GPI_ERROR);
- }
-
- if( aNumPoints > 20)
- delete [] pts;
- }
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::DrawRect( const nsRect& aRect)
-{
- nsRect tr = aRect;
- PMDrawRect( tr, FALSE);
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::DrawRect( nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
-{
- nsRect tr( aX, aY, aWidth, aHeight);
- PMDrawRect( tr, FALSE);
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::FillRect( const nsRect& aRect)
-{
- nsRect tr = aRect;
- PMDrawRect( tr, TRUE);
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::FillRect( nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
-{
- nsRect tr( aX, aY, aWidth, aHeight);
- PMDrawRect( tr, TRUE);
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsRenderingContextOS2 :: InvertRect(const nsRect& aRect)
-{
- return InvertRect(aRect.x, aRect.y, aRect.width, aRect.height);
-}
-
-NS_IMETHODIMP
-nsRenderingContextOS2 :: InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
-{
- nsRect tr(aX, aY, aWidth, aHeight);
- LONG CurMix = GFX (::GpiQueryMix (mPS), FM_ERROR);
- GFX (::GpiSetMix (mPS, FM_INVERT), FALSE);
- PMDrawRect(tr, FALSE);
- GFX (::GpiSetMix (mPS, CurMix), FALSE);
- return NS_OK;
-}
-
-void nsRenderingContextOS2::PMDrawRect( nsRect &rect, BOOL fill)
-{
- mTranMatrix->TransformCoord( &rect.x, &rect.y, &rect.width, &rect.height);
-
- // only draw line if it has a non-zero height and width
- if ( !rect.width || !rect.height )
- return;
-
- RECTL rcl;
- mSurface->NS2PM_ININ (rect, rcl);
-
- GFX (::GpiMove (mPS, (PPOINTL) &rcl), FALSE);
-
- if (rcl.xLeft == rcl.xRight || rcl.yTop == rcl.yBottom)
- {
- SetupLineColorAndStyle ();
- GFX (::GpiLine (mPS, ((PPOINTL)&rcl) + 1), GPI_ERROR);
- }
- else
- {
- long lOps;
-
- if (fill)
- {
- lOps = DRO_FILL;
- SetupFillColor ();
- } else
- {
- lOps = DRO_OUTLINE;
- SetupLineColorAndStyle ();
- }
-
- GFX (::GpiBox (mPS, lOps, ((PPOINTL)&rcl) + 1, 0, 0), GPI_ERROR);
- }
-}
-
-// Arc-drawing methods, all proxy on to PMDrawArc
-NS_IMETHODIMP nsRenderingContextOS2::DrawEllipse( const nsRect& aRect)
-{
- nsRect tRect( aRect);
- PMDrawArc( tRect, PR_FALSE, PR_TRUE);
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::DrawEllipse( nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
-{
- nsRect tRect( aX, aY, aWidth, aHeight);
- PMDrawArc( tRect, PR_FALSE, PR_TRUE);
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::FillEllipse( const nsRect& aRect)
-{
- nsRect tRect( aRect);
- PMDrawArc( tRect, PR_TRUE, PR_TRUE);
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::FillEllipse( nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
-{
- nsRect tRect( aX, aY, aWidth, aHeight);
- PMDrawArc( tRect, PR_TRUE, PR_TRUE);
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::DrawArc( const nsRect& aRect,
- float aStartAngle, float aEndAngle)
-{
- nsRect tRect( aRect);
- PMDrawArc( tRect, PR_FALSE, PR_FALSE, aStartAngle, aEndAngle);
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::DrawArc( nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
- float aStartAngle, float aEndAngle)
-{
- nsRect tRect( aX, aY, aWidth, aHeight);
- PMDrawArc( tRect, PR_FALSE, PR_FALSE, aStartAngle, aEndAngle);
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::FillArc( const nsRect& aRect,
- float aStartAngle, float aEndAngle)
-{
- nsRect tRect( aRect);
- PMDrawArc( tRect, PR_TRUE, PR_FALSE, aStartAngle, aEndAngle);
- return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::FillArc( nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
- float aStartAngle, float aEndAngle)
-{
- nsRect tRect( aX, aY, aWidth, aHeight);
- PMDrawArc( tRect, PR_TRUE, PR_FALSE, aStartAngle, aEndAngle);
- return NS_OK;
-}
-
-void nsRenderingContextOS2::PMDrawArc( nsRect &rect, PRBool bFilled, PRBool bFull,
- float start, float end)
-{
- // convert coords
- mTranMatrix->TransformCoord( &rect.x, &rect.y, &rect.width, &rect.height);
-
- RECTL rcl;
- mSurface->NS2PM_ININ (rect, rcl);
-
- // set arc params.
- long lWidth = rect.width / 2;
- long lHeight = rect.height / 2;
- ARCPARAMS arcparams = { lWidth, lHeight, 0, 0 };
- GFX (::GpiSetArcParams (mPS, &arcparams), FALSE);
-
- // move to center
- rcl.xLeft += lWidth;
- rcl.yBottom += lHeight;
- GFX (::GpiMove (mPS, (PPOINTL)&rcl), FALSE);
-
- if (bFilled)
- SetupFillColor ();
- else
- SetupLineColorAndStyle ();
-
-
- if (bFull)
- {
- long lOps = (bFilled) ? DRO_FILL : DRO_OUTLINE;
-
- // draw ellipse
- GFX (::GpiFullArc (mPS, lOps, MAKEFIXED(1,0)), GPI_ERROR);
- }
- else
- {
- FIXED StartAngle = (FIXED)(start * 65536.0) % MAKEFIXED (360, 0);
- FIXED EndAngle = (FIXED)(end * 65536.0) % MAKEFIXED (360, 0);
- FIXED SweepAngle = EndAngle - StartAngle;
-
- if (SweepAngle < 0) SweepAngle += MAKEFIXED (360, 0);
-
- // draw an arc or a pie
- if (bFilled)
- {
- GFX (::GpiBeginArea (mPS, BA_NOBOUNDARY), FALSE);
- GFX (::GpiPartialArc (mPS, (PPOINTL)&rcl, MAKEFIXED(1,0), StartAngle, SweepAngle), GPI_ERROR);
- GFX (::GpiEndArea (mPS), GPI_ERROR);
- }
- else
- {
- // draw an invisible partialarc to get to the start of the arc.
- long lLineType = GFX (::GpiQueryLineType (mPS), LINETYPE_ERROR);
- GFX (::GpiSetLineType (mPS, LINETYPE_INVISIBLE), FALSE);
- GFX (::GpiPartialArc (mPS, (PPOINTL)&rcl, MAKEFIXED(1,0), StartAngle, MAKEFIXED (0,0)), GPI_ERROR);
- // now draw a real arc
- GFX (::GpiSetLineType (mPS, lLineType), FALSE);
- GFX (::GpiPartialArc (mPS, (PPOINTL)&rcl, MAKEFIXED(1,0), StartAngle, SweepAngle), GPI_ERROR);
- }
- }
-}
-
-NS_IMETHODIMP nsRenderingContextOS2 :: GetWidth(char ch, nscoord& aWidth)
-{
- char buf[1];
- buf[0] = ch;
- return GetWidth(buf, 1, aWidth);
-}
-
-NS_IMETHODIMP nsRenderingContextOS2 :: GetWidth(PRUnichar ch, nscoord &aWidth, PRInt32 *aFontID)
-{
- PRUnichar buf[1];
- buf[0] = ch;
- return GetWidth(buf, 1, aWidth, aFontID);
-}
-
-NS_IMETHODIMP nsRenderingContextOS2 :: GetWidth(const char* aString, nscoord& aWidth)
-{
- return GetWidth(aString, strlen(aString), aWidth);
-}
-
-NS_IMETHODIMP nsRenderingContextOS2 :: GetWidth(const char* aString,
- PRUint32 aLength,
- nscoord& aWidth)
-{
-
- if (nsnull != mFontMetrics)
- {
- // Check for the very common case of trying to get the width of a single
- // space.
- if ((1 == aLength) && (aString[0] == ' '))
- {
- return mFontMetrics->GetSpaceWidth(aWidth);
- }
-
- SetupFontAndColor();
- nscoord pxWidth = mCurrFontOS2->GetWidth(mPS, aString, aLength);
- aWidth = NSToCoordRound(float(pxWidth) * mP2T);
-
- return NS_OK;
- }
- else
- return NS_ERROR_FAILURE;
-}
-
-NS_IMETHODIMP nsRenderingContextOS2::GetWidth( const nsString &aString,
- nscoord &aWidth,
- PRInt32 *aFontID)
-{
- return GetWidth( aString.get(), aString.Length(), aWidth, aFontID);
-}
-
-struct GetWidthData {
- HPS mPS; // IN
- nsDrawingSurfaceOS2* mSurface; // IN
- nsFontOS2* mFont; // IN/OUT (running)
- LONG mWidth; // IN/OUT (running, accumulated width so far)
-};
-
-static PRBool PR_CALLBACK
-do_GetWidth(const nsFontSwitch* aFontSwitch,
- const PRUnichar* aSubstring,
- PRUint32 aSubstringLength,
- void* aData)
-{
- nsFontOS2* font = aFontSwitch->mFont;
-
- GetWidthData* data = (GetWidthData*)aData;
- if (data->mFont != font) {
- // the desired font is not the current font in the PS
- data->mFont = font;
- data->mSurface->SelectFont(data->mFont);
- }
- data->mWidth += font->GetWidth(data->mPS, aSubstring, aSubstringLength);
- return PR_TRUE; // don't stop till the end