diff options
Diffstat (limited to 'gfx')
-rw-r--r-- | gfx/cairo/cairo/src/moz.build | 6 | ||||
-rw-r--r-- | gfx/cairo/libpixman/src/Makefile.in | 2 | ||||
-rw-r--r-- | gfx/src/Makefile.in | 4 | ||||
-rw-r--r-- | gfx/src/nsDeviceContext.cpp | 31 | ||||
-rw-r--r-- | gfx/thebes/Makefile.in | 4 | ||||
-rw-r--r-- | gfx/thebes/gfxOS2Fonts.cpp | 850 | ||||
-rw-r--r-- | gfx/thebes/gfxOS2Fonts.h | 105 | ||||
-rw-r--r-- | gfx/thebes/gfxOS2Platform.cpp | 188 | ||||
-rw-r--r-- | gfx/thebes/gfxOS2Platform.h | 65 | ||||
-rw-r--r-- | gfx/thebes/gfxOS2Surface.cpp | 203 | ||||
-rw-r--r-- | gfx/thebes/gfxOS2Surface.h | 48 | ||||
-rw-r--r-- | gfx/thebes/gfxPlatform.cpp | 4 | ||||
-rw-r--r-- | gfx/thebes/gfxPlatform.h | 4 | ||||
-rw-r--r-- | gfx/thebes/moz.build | 15 |
14 files changed, 0 insertions, 1529 deletions
diff --git a/gfx/cairo/cairo/src/moz.build b/gfx/cairo/cairo/src/moz.build index b5af1f746..706fe2ed9 100644 --- a/gfx/cairo/cairo/src/moz.build +++ b/gfx/cairo/cairo/src/moz.build @@ -32,12 +32,6 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows': CPP_SOURCES += [ 'cairo-d2d-surface.cpp', ] -elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'os2': - EXPORTS.cairo += [ - 'cairo-os2.h', - 'cairo-os2-private.h', - 'cairo-pdf.h', - ] elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa': EXPORTS.cairo += [ 'cairo-quartz-image.h', diff --git a/gfx/cairo/libpixman/src/Makefile.in b/gfx/cairo/libpixman/src/Makefile.in index 750fbb937..ba07e8cda 100644 --- a/gfx/cairo/libpixman/src/Makefile.in +++ b/gfx/cairo/libpixman/src/Makefile.in @@ -64,10 +64,8 @@ endif ifdef USE_SSE2 SSE2_CFLAGS=-msse -msse2 -Winline endif -ifneq ($(MOZ_WIDGET_TOOLKIT),os2) MMX_CFLAGS+=--param inline-unit-growth=10000 --param large-function-growth=10000 endif -endif ifeq (arm,$(findstring arm,$(OS_TEST))) # Apple's arm assembler doesn't support the same syntax as # the standard GNU assembler, so use the C fallback paths for now. diff --git a/gfx/src/Makefile.in b/gfx/src/Makefile.in index 9295aade1..b22eae387 100644 --- a/gfx/src/Makefile.in +++ b/gfx/src/Makefile.in @@ -25,10 +25,6 @@ ifdef MOZ_WIDGET_GTK CXXFLAGS += $(MOZ_PANGO_CFLAGS) endif -ifeq ($(MOZ_WIDGET_TOOLKIT),os2) -CXXFLAGS += $(CAIRO_FT_CFLAGS) -endif - ifeq ($(MOZ_WIDGET_TOOLKIT),qt) CXXFLAGS += $(MOZ_QT_CFLAGS) endif diff --git a/gfx/src/nsDeviceContext.cpp b/gfx/src/nsDeviceContext.cpp index dc917ab76..266713f99 100644 --- a/gfx/src/nsDeviceContext.cpp +++ b/gfx/src/nsDeviceContext.cpp @@ -28,8 +28,6 @@ #include "gfxPSSurface.h" #elif XP_WIN #include "gfxWindowsSurface.h" -#elif defined(XP_OS2) -#include "gfxOS2Surface.h" #elif XP_MACOSX #include "gfxQuartzSurface.h" #endif @@ -303,15 +301,6 @@ nsDeviceContext::SetDPI() break; } #endif -#ifdef XP_OS2 - case gfxASurface::SurfaceTypeOS2: { - LONG lDPI; - HDC dc = GpiQueryDevice(reinterpret_cast<gfxOS2Surface*>(mPrintingSurface.get())->GetPS()); - if (DevQueryCaps(dc, CAPS_VERTICAL_FONT_RES, 1, &lDPI)) - dpi = lDPI; - break; - } -#endif default: NS_NOTREACHED("Unexpected printing surface type"); break; @@ -677,26 +666,6 @@ nsDeviceContext::CalcPrintingSize() } #endif -#ifdef XP_OS2 - case gfxASurface::SurfaceTypeOS2: - { - inPoints = false; - // we already set the size in the surface constructor we set for - // printing, so just get those values here - size = reinterpret_cast<gfxOS2Surface*>(mPrintingSurface.get())->GetSize(); - // as they are in pixels we need to scale them to app units - size.width = NSFloatPixelsToAppUnits(size.width, AppUnitsPerDevPixel()); - size.height = NSFloatPixelsToAppUnits(size.height, AppUnitsPerDevPixel()); - // still need to get the depth from the device context - HDC dc = GpiQueryDevice(reinterpret_cast<gfxOS2Surface*>(mPrintingSurface.get())->GetPS()); - LONG value; - if (DevQueryCaps(dc, CAPS_COLOR_BITCOUNT, 1, &value)) - mDepth = value; - else - mDepth = 8; // default to 8bpp, should be enough for printers - break; - } -#endif default: NS_ERROR("trying to print to unknown surface type"); } diff --git a/gfx/thebes/Makefile.in b/gfx/thebes/Makefile.in index 4d5c1e481..1602edf91 100644 --- a/gfx/thebes/Makefile.in +++ b/gfx/thebes/Makefile.in @@ -92,10 +92,6 @@ ifdef MOZ_WIDGET_GTK CXXFLAGS += $(MOZ_PANGO_CFLAGS) endif -ifeq ($(MOZ_WIDGET_TOOLKIT),os2) -CXXFLAGS += $(CAIRO_FT_CFLAGS) -endif - ifeq ($(MOZ_WIDGET_TOOLKIT),qt) CXXFLAGS += $(CAIRO_FT_CFLAGS) $(MOZ_PANGO_CFLAGS) endif diff --git a/gfx/thebes/gfxOS2Fonts.cpp b/gfx/thebes/gfxOS2Fonts.cpp deleted file mode 100644 index 39b0f1e00..000000000 --- a/gfx/thebes/gfxOS2Fonts.cpp +++ /dev/null @@ -1,850 +0,0 @@ -/* vim: set sw=4 sts=4 et cin: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "gfxContext.h" - -#include "gfxOS2Platform.h" -#include "gfxOS2Surface.h" -#include "gfxOS2Fonts.h" -#include "nsTArray.h" -#include "nsGkAtoms.h" - -#include "nsIPlatformCharset.h" - -#include "mozilla/Preferences.h" -#include <algorithm> - -using namespace mozilla; - -/********************************************************************** - * class gfxOS2Font - **********************************************************************/ - -gfxOS2Font::gfxOS2Font(gfxOS2FontEntry *aFontEntry, const gfxFontStyle *aFontStyle) - : gfxFont(aFontEntry, aFontStyle), - mFontFace(nullptr), - mMetrics(nullptr), mAdjustedSize(0), - mHinting(FC_HINT_MEDIUM), mAntialias(FcTrue) -{ -#ifdef DEBUG_thebes_2 - printf("gfxOS2Font[%p]::gfxOS2Font(%p \"%s\", aFontStyle)\n", - (void *)this, (void *)aFontEntry, - NS_LossyConvertUTF16toASCII(aFontEntry->Name()).get()); -#endif - // try to get the preferences for hinting, antialias, and embolden options - int32_t value; - nsresult rv = Preferences::GetInt("gfx.os2.font.hinting", &value); - if (NS_SUCCEEDED(rv) && value >= FC_HINT_NONE && value <= FC_HINT_FULL) { - mHinting = value; - } - - mAntialias = Preferences::GetBool("gfx.os2.font.antialiasing", mAntialias); - -#ifdef DEBUG_thebes_2 - printf(" font display options: hinting=%d, antialiasing=%s\n", - mHinting, mAntialias ? "on" : "off"); -#endif -} - -gfxOS2Font::~gfxOS2Font() -{ -#ifdef DEBUG_thebes_2 - printf("gfxOS2Font[%#x]::~gfxOS2Font()\n", (unsigned)this); -#endif - if (mFontFace) { - cairo_font_face_destroy(mFontFace); - } - if (mScaledFont) { - cairo_scaled_font_destroy(mScaledFont); - } - delete mMetrics; - mFontFace = nullptr; - mScaledFont = nullptr; - mMetrics = nullptr; -} - -// fill font metrics structure with default values in case of error -static void FillMetricsDefaults(gfxFont::Metrics *aMetrics) -{ - aMetrics->emAscent = 0.8 * aMetrics->emHeight; - aMetrics->emDescent = 0.2 * aMetrics->emHeight; - aMetrics->maxAscent = aMetrics->emAscent; - aMetrics->maxDescent = aMetrics->maxDescent; - aMetrics->maxHeight = aMetrics->emHeight; - aMetrics->internalLeading = 0.0; - aMetrics->externalLeading = 0.2 * aMetrics->emHeight; - aMetrics->spaceWidth = 0.5 * aMetrics->emHeight; - aMetrics->maxAdvance = aMetrics->spaceWidth; - aMetrics->aveCharWidth = aMetrics->spaceWidth; - aMetrics->zeroOrAveCharWidth = aMetrics->spaceWidth; - aMetrics->xHeight = 0.5 * aMetrics->emHeight; - aMetrics->underlineSize = aMetrics->emHeight / 14.0; - aMetrics->underlineOffset = -aMetrics->underlineSize; - aMetrics->strikeoutOffset = 0.25 * aMetrics->emHeight; - aMetrics->strikeoutSize = aMetrics->underlineSize; - aMetrics->superscriptOffset = aMetrics->xHeight; - aMetrics->subscriptOffset = aMetrics->xHeight; -} - -// Snap a line to pixels while keeping the center and size of the -// line as close to the original position as possible. -static void SnapLineToPixels(gfxFloat& aOffset, gfxFloat& aSize) -{ - gfxFloat snappedSize = std::max(floor(aSize + 0.5), 1.0); - // Correct offset for change in size - gfxFloat offset = aOffset - 0.5 * (aSize - snappedSize); - // Snap offset - aOffset = floor(offset + 0.5); - aSize = snappedSize; -} - -// gfxOS2Font::GetMetrics() -// return the metrics of the current font using the gfxFont metrics structure. -// If the metrics are not available yet, compute them using the FreeType -// function on the font. (This is partly based on the respective function from -// gfxPangoFonts) -const gfxFont::Metrics& gfxOS2Font::GetMetrics() -{ -#ifdef DEBUG_thebes_1 - printf("gfxOS2Font[%#x]::GetMetrics()\n", (unsigned)this); -#endif - if (mMetrics) { - return *mMetrics; - } - - // whatever happens below, we can always create the metrics - mMetrics = new gfxFont::Metrics; - mSpaceGlyph = 0; - - // round size to integer pixels, this is to get full pixels for layout - // together with internal/external leading (see below) - mMetrics->emHeight = floor(GetStyle()->size + 0.5); - - cairo_scaled_font_t* scaledFont = CairoScaledFont(); - if (!scaledFont) { - FillMetricsDefaults(mMetrics); - return *mMetrics; - } - - FT_Face face = cairo_ft_scaled_font_lock_face(scaledFont); - if (!face) { - // Abort here already, otherwise we crash in the following - // this can happen if the font-size requested is zero. - FillMetricsDefaults(mMetrics); - return *mMetrics; - } - if (!face->charmap) { - // Also abort, if the charmap isn't loaded; then the char - // lookups won't work. This happens for fonts without Unicode - // charmap. - cairo_ft_scaled_font_unlock_face(scaledFont); - FillMetricsDefaults(mMetrics); - return *mMetrics; - } - - // compute font scaling factors - gfxFloat emUnit = 1.0 * face->units_per_EM; - gfxFloat xScale = face->size->metrics.x_ppem / emUnit; - gfxFloat yScale = face->size->metrics.y_ppem / emUnit; - - FT_UInt gid; // glyph ID - - // properties of space - gid = FT_Get_Char_Index(face, ' '); - if (gid) { - // Load glyph into glyph slot. Use load_default here to get results in - // 26.6 fractional pixel format which is what is used for all other - // characters in gfxOS2FontGroup::CreateGlyphRunsFT. - FT_Load_Glyph(face, gid, FT_LOAD_DEFAULT); - // glyph width doesn't work for spaces, use advance instead - mMetrics->spaceWidth = face->glyph->advance.x >> 6; - // save the space glyph - mSpaceGlyph = gid; - } else { - NS_ASSERTION(gid, "this font doesn't have a space glyph!"); - mMetrics->spaceWidth = face->max_advance_width * xScale; - } - - // properties of 'x', also use its width as average width - gid = FT_Get_Char_Index(face, 'x'); // select the glyph - if (gid) { - // Load glyph into glyph slot. Here, use no_scale to get font units. - FT_Load_Glyph(face, gid, FT_LOAD_NO_SCALE); - mMetrics->xHeight = face->glyph->metrics.height * yScale; - mMetrics->aveCharWidth = face->glyph->metrics.horiAdvance * xScale; - } else { - // this font doesn't have an 'x'... - // fake these metrics using a fraction of the font size - mMetrics->xHeight = mMetrics->emHeight * 0.5; - mMetrics->aveCharWidth = mMetrics->emHeight * 0.5; - } - - // properties of '0', for 'ch' units - gid = FT_Get_Char_Index(face, '0'); - if (gid) { - FT_Load_Glyph(face, gid, FT_LOAD_NO_SCALE); - mMetrics->zeroOrAveCharWidth = face->glyph->metrics.horiAdvance * xScale; - } else { - // this font doesn't have a '0' - mMetrics->zeroOrAveCharWidth = mMetrics->aveCharWidth; - } - - // compute an adjusted size if we need to - if (mAdjustedSize == 0 && GetStyle()->sizeAdjust != 0) { - gfxFloat aspect = mMetrics->xHeight / GetStyle()->size; - mAdjustedSize = GetStyle()->GetAdjustedSize(aspect); - mMetrics->emHeight = mAdjustedSize; - } - - // now load the OS/2 TrueType table to access some more properties - TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(face, ft_sfnt_os2); - if (os2 && os2->version != 0xFFFF) { // should be there if not old Mac font - // if we are here we can improve the avgCharWidth - mMetrics->aveCharWidth = std::max(mMetrics->aveCharWidth, - os2->xAvgCharWidth * xScale); - - mMetrics->superscriptOffset = std::max(os2->ySuperscriptYOffset * yScale, 1.0); - // some fonts have the incorrect sign (from gfxPangoFonts) - mMetrics->subscriptOffset = std::max(fabs(os2->ySubscriptYOffset * yScale), - 1.0); - mMetrics->strikeoutOffset = os2->yStrikeoutPosition * yScale; - mMetrics->strikeoutSize = os2->yStrikeoutSize * yScale; - } else { - // use fractions of emHeight instead of xHeight for these to be more robust - mMetrics->superscriptOffset = mMetrics->emHeight * 0.5; - mMetrics->subscriptOffset = mMetrics->emHeight * 0.2; - mMetrics->strikeoutOffset = mMetrics->emHeight * 0.3; - mMetrics->strikeoutSize = face->underline_thickness * yScale; - } - SnapLineToPixels(mMetrics->strikeoutOffset, mMetrics->strikeoutSize); - - // seems that underlineOffset really has to be negative - mMetrics->underlineOffset = face->underline_position * yScale; - mMetrics->underlineSize = face->underline_thickness * yScale; - - // descents are negative in FT but Thebes wants them positive - mMetrics->emAscent = face->ascender * yScale; - mMetrics->emDescent = -face->descender * yScale; - mMetrics->maxHeight = face->height * yScale; - // the max units determine frame heights, better be generous - mMetrics->maxAscent = std::max(face->bbox.yMax * yScale, - mMetrics->emAscent); - mMetrics->maxDescent = std::max(-face->bbox.yMin * yScale, - mMetrics->emDescent); - mMetrics->maxAdvance = std::max(face->max_advance_width * xScale, - mMetrics->aveCharWidth); - - // leadings are not available directly (only for WinFNTs); - // better compute them on our own, to get integer values and make - // layout happy (see // LockedFTFace::GetMetrics in gfxPangoFonts.cpp) - mMetrics->internalLeading = floor(mMetrics->maxHeight - - mMetrics->emHeight + 0.5); - gfxFloat lineHeight = floor(mMetrics->maxHeight + 0.5); - mMetrics->externalLeading = lineHeight - - mMetrics->internalLeading - mMetrics->emHeight; - - SanitizeMetrics(mMetrics, false); - -#ifdef DEBUG_thebes_1 - printf("gfxOS2Font[%#x]::GetMetrics():\n" - " %s (%s)\n" - " emHeight=%f == %f=gfxFont::style.size == %f=adjSz\n" - " maxHeight=%f xHeight=%f\n" - " aveCharWidth=%f(x) zeroOrAveWidth=%f(0) spaceWidth=%f\n" - " supOff=%f SubOff=%f strOff=%f strSz=%f\n" - " undOff=%f undSz=%f intLead=%f extLead=%f\n" - " emAsc=%f emDesc=%f maxH=%f\n" - " maxAsc=%f maxDes=%f maxAdv=%f\n", - (unsigned)this, - NS_LossyConvertUTF16toASCII(GetName()).get(), - os2 && os2->version != 0xFFFF ? "has OS/2 table" : "no OS/2 table!", - mMetrics->emHeight, GetStyle()->size, mAdjustedSize, - mMetrics->maxHeight, mMetrics->xHeight, - mMetrics->aveCharWidth, mMetrics->zeroOrAveCharWidth, mMetrics->spaceWidth, - mMetrics->superscriptOffset, mMetrics->subscriptOffset, - mMetrics->strikeoutOffset, mMetrics->strikeoutSize, - mMetrics->underlineOffset, mMetrics->underlineSize, - mMetrics->internalLeading, mMetrics->externalLeading, - mMetrics->emAscent, mMetrics->emDescent, mMetrics->maxHeight, - mMetrics->maxAscent, mMetrics->maxDescent, mMetrics->maxAdvance - ); -#endif - cairo_ft_scaled_font_unlock_face(scaledFont); - return *mMetrics; -} - -// weight list copied from fontconfig.h -// unfortunately, the OS/2 version so far only supports regular and bold -static const int8_t nFcWeight = 2; // 10; // length of weight list -static const int fcWeight[] = { - //FC_WEIGHT_THIN, - //FC_WEIGHT_EXTRALIGHT, // == FC_WEIGHT_ULTRALIGHT - //FC_WEIGHT_LIGHT, - //FC_WEIGHT_BOOK, - FC_WEIGHT_REGULAR, // == FC_WEIGHT_NORMAL - //FC_WEIGHT_MEDIUM, - //FC_WEIGHT_DEMIBOLD, // == FC_WEIGHT_SEMIBOLD - FC_WEIGHT_BOLD, - //FC_WEIGHT_EXTRABOLD, // == FC_WEIGHT_ULTRABOLD - //FC_WEIGHT_BLACK // == FC_WEIGHT_HEAVY -}; - -// gfxOS2Font::CairoFontFace() -// return a font face usable by cairo for font rendering -// if none was created yet, use FontConfig patterns based on the current style -// to create a new font face -cairo_font_face_t *gfxOS2Font::CairoFontFace() -{ -#ifdef DEBUG_thebes_2 - printf("gfxOS2Font[%#x]::CairoFontFace()\n", (unsigned)this); -#endif - if (!mFontFace) { -#ifdef DEBUG_thebes - printf("gfxOS2Font[%#x]::CairoFontFace(): create it for %s, %f\n", - (unsigned)this, NS_LossyConvertUTF16toASCII(GetName()).get(), GetStyle()->size); -#endif - FcPattern *fcPattern = FcPatternCreate(); - - // add (family) name to pattern - // convert name because FC stores it in UTF8 while we have it in UTF16 - FcPatternAddString(fcPattern, FC_FAMILY, - (FcChar8 *)NS_ConvertUTF16toUTF8(GetName()).get()); - - // The requirements outlined in gfxFont.h are difficult to meet without - // having a table of available font weights, so we map the gfxFont - // weight to possible FontConfig weights. - int8_t weight = GetStyle()->ComputeWeight(); - // gfxFont weight FC weight - // 400 80 - // 700 200 - int16_t fcW = 40 * weight - 80; // match gfxFont weight to base FC weight - // find the correct weight in the list - int8_t i = 0; - while (i < nFcWeight && fcWeight[i] < fcW) { - i++; - } - if (i < 0) { - i = 0; - } else if (i >= nFcWeight) { - i = nFcWeight - 1; - } - fcW = fcWeight[i]; - - // add weight to pattern - FcPatternAddInteger(fcPattern, FC_WEIGHT, fcW); - - uint8_t fcProperty; - // add style to pattern - switch (GetStyle()->style) { - case NS_FONT_STYLE_ITALIC: - fcProperty = FC_SLANT_ITALIC; - break; - case NS_FONT_STYLE_OBLIQUE: - fcProperty = FC_SLANT_OBLIQUE; - break; - case NS_FONT_STYLE_NORMAL: - default: - fcProperty = FC_SLANT_ROMAN; - } - FcPatternAddInteger(fcPattern, FC_SLANT, fcProperty); - - // add the size we want - FcPatternAddDouble(fcPattern, FC_PIXEL_SIZE, - mAdjustedSize ? mAdjustedSize : GetStyle()->size); - - // finally find a matching font - FcResult fcRes; - FcPattern *fcMatch = FcFontMatch(NULL, fcPattern, &fcRes); - - // Most code that depends on FcFontMatch() assumes it won't fail, - // then crashes when it does. For now, at least, substitute the - // default serif font when it fails to avoid those crashes. - if (!fcMatch) { -//#ifdef DEBUG - printf("Could not match font for:\n" - " family=%s, weight=%d, slant=%d, size=%f\n", - NS_LossyConvertUTF16toASCII(GetName()).get(), - GetStyle()->weight, GetStyle()->style, GetStyle()->size); -//#endif - // FcPatternAddString() will free the existing FC_FAMILY string - FcPatternAddString(fcPattern, FC_FAMILY, (FcChar8*)"SERIF"); - fcMatch = FcFontMatch(NULL, fcPattern, &fcRes); -//#ifdef DEBUG - printf("Attempt to substitute default SERIF font %s\n", - fcMatch ? "succeeded" : "failed"); -//#endif - } - FcPatternDestroy(fcPattern); - - if (fcMatch) { - int w = FC_WEIGHT_REGULAR; - FcPatternGetInteger(fcMatch, FC_WEIGHT, 0, &w); - if (fcW >= FC_WEIGHT_DEMIBOLD && w < FC_WEIGHT_DEMIBOLD) { - // if we want a bold font, but the selected font doesn't have a - // bold counterpart, artificially embolden it - FcPatternAddBool(fcMatch, FC_EMBOLDEN, FcTrue); - } - FcPatternAddBool(fcMatch, FC_ANTIALIAS, mAntialias); - FcPatternAddInteger(fcMatch, FC_HINT_STYLE, mHinting); - - // and ask cairo to return a font face for this - mFontFace = cairo_ft_font_face_create_for_pattern(fcMatch); - - FcPatternDestroy(fcMatch); - } - } - - NS_ASSERTION(mFontFace, "Failed to make font face"); - return mFontFace; -} - -cairo_scaled_font_t *gfxOS2Font::CairoScaledFont() -{ -#ifdef DEBUG_thebes_2 - printf("gfxOS2Font[%#x]::CairoScaledFont()\n", (unsigned)this); -#endif - if (mScaledFont) { - return mScaledFont; - } -#ifdef DEBUG_thebes_2 - printf("gfxOS2Font[%#x]::CairoScaledFont(): create it for %s, %f\n", - (unsigned)this, NS_LossyConvertUTF16toASCII(GetName()).get(), GetStyle()->size); -#endif - - double size = mAdjustedSize ? mAdjustedSize : GetStyle()->size; - cairo_matrix_t identityMatrix; - cairo_matrix_init_identity(&identityMatrix); - cairo_matrix_t fontMatrix; - // synthetic oblique by skewing via the font matrix - if (!mFontEntry->mItalic && - (mStyle.style & (NS_FONT_STYLE_ITALIC | NS_FONT_STYLE_OBLIQUE))) - { - const double kSkewFactor = 0.2126; // 12 deg skew as used in e.g. ftview - cairo_matrix_init(&fontMatrix, size, 0, -kSkewFactor*size, size, 0, 0); - } else { - cairo_matrix_init_scale(&fontMatrix, size, size); - } - - cairo_font_face_t * face = CairoFontFace(); - if (!face) - return nullptr; - - cairo_font_options_t *fontOptions = cairo_font_options_create(); - mScaledFont = cairo_scaled_font_create(face, &fontMatrix, - &identityMatrix, fontOptions); - cairo_font_options_destroy(fontOptions); - - NS_ASSERTION(cairo_scaled_font_status(mScaledFont) == CAIRO_STATUS_SUCCESS, - "Failed to make scaled font"); - return mScaledFont; -} - -bool gfxOS2Font::SetupCairoFont(gfxContext *aContext) -{ -#ifdef DEBUG_thebes_2 - printf("gfxOS2Font[%#x]::SetupCairoFont(%#x)\n", - (unsigned)this, (unsigned) aContext); -#endif - // gfxPangoFont checks the CTM but Windows doesn't so leave away here, too - - // this implicitely ensures that mScaledFont is created if NULL - cairo_scaled_font_t *scaledFont = CairoScaledFont(); - if (!scaledFont || cairo_scaled_font_status(scaledFont) != CAIRO_STATUS_SUCCESS) { - // Don't cairo_set_scaled_font as that would propagate the error to - // the cairo_t, precluding any further drawing. - return false; - } - cairo_set_scaled_font(aContext->GetCairo(), scaledFont); - return true; -} - -/** - * Look up the font in the gfxFont cache. If we don't find it, create one. - * In either case, add a ref and return it --- - * except for OOM in which case we do nothing and return null. - */ -already_AddRefed<gfxOS2Font> gfxOS2Font::GetOrMakeFont(const nsAString& aName, - const gfxFontStyle *aStyle) -{ - nsRefPtr<gfxOS2FontEntry> fe = new gfxOS2FontEntry(aName); - nsRefPtr<gfxFont> font = - gfxFontCache::GetCache()->Lookup(static_cast<gfxFontEntry *>(fe), aStyle); - if (!font) { - font = new gfxOS2Font(fe, aStyle); - if (!font) - return nullptr; - gfxFontCache::GetCache()->AddNew(font); - } - gfxFont *f = nullptr; - font.swap(f); - return static_cast<gfxOS2Font *>(f); -} - -/********************************************************************** - * class gfxOS2FontGroup - **********************************************************************/ - -gfxOS2FontGroup::gfxOS2FontGroup(const nsAString& aFamilies, - const gfxFontStyle* aStyle, - gfxUserFontSet *aUserFontSet) - : gfxFontGroup(aFamilies, aStyle, aUserFontSet) -{ -#ifdef DEBUG_thebes_2 - printf("gfxOS2FontGroup[%#x]::gfxOS2FontGroup(\"%s\", %#x)\n", - (unsigned)this, NS_LossyConvertUTF16toASCII(aFamilies).get(), - (unsigned)aStyle); -#endif - - // check for WarpSans and as we cannot display that (yet), replace - // it with Workplace Sans - int pos = 0; - if ((pos = mFamilies.Find("WarpSans", false, 0, -1)) > -1) { - mFamilies.Replace(pos, 8, NS_LITERAL_STRING("Workplace Sans")); - } - - nsTArray<nsString> familyArray; - ForEachFont(FontCallback, &familyArray); - - // To be able to easily search for glyphs in other fonts, append a few good - // replacement candidates to the list. The best ones are the Unicode fonts that - // are set up, and if the user was so clever to set up the User Defined fonts, - // then these are probable candidates, too. - nsString fontString; - gfxPlatform::GetPlatform()->GetPrefFonts(nsGkAtoms::Unicode, fontString, false); - ForEachFont(fontString, nsGkAtoms::Unicode, FontCallback, &familyArray); - gfxPlatform::GetPlatform()->GetPrefFonts(nsGkAtoms::x_user_def, fontString, false); - ForEachFont(fontString, nsGkAtoms::x_user_def, FontCallback, &familyArray); - - // Should append some default font if there are no available fonts. - // Let's use Helv which should be available on any OS/2 system; if - // it's not there, Fontconfig replaces it with something else... - if (familyArray.Length() == 0) { - familyArray.AppendElement(NS_LITERAL_STRING("Helv")); - } - - for (uint32_t i = 0; i < familyArray.Length(); i++) { - nsRefPtr<gfxOS2Font> font = gfxOS2Font::GetOrMakeFont(familyArray[i], &mStyle); - if (font) { - mFonts.AppendElement(font); - } - } -} - -gfxOS2FontGroup::~gfxOS2FontGroup() -{ -#ifdef DEBUG_thebes_2 - printf("gfxOS2FontGroup[%#x]::~gfxOS2FontGroup()\n", (unsigned)this); -#endif -} - -gfxFontGroup *gfxOS2FontGroup::Copy(const gfxFontStyle *aStyle) -{ - return new gfxOS2FontGroup(mFamilies, aStyle, mUserFontSet); -} - -/** - * We use this to append an LTR or RTL Override character to the start of the - * string. This forces Pango to honour our direction even if there are neutral - * characters in the string. - */ -static int32_t AppendDirectionalIndicatorUTF8(bool aIsRTL, nsACString& aString) -{ - static const PRUnichar overrides[2][2] = { { 0x202d, 0 }, { 0x202e, 0 }}; // LRO, RLO - AppendUTF16toUTF8(overrides[aIsRTL], aString); - return 3; // both overrides map to 3 bytes in UTF8 -} - -gfxTextRun *gfxOS2FontGroup::MakeTextRun(const PRUnichar* aString, uint32_t aLength, - const Parameters* aParams, uint32_t aFlags) -{ - NS_ASSERTION(aLength > 0, "should use MakeEmptyTextRun for zero-length text"); - gfxTextRun *textRun = gfxTextRun::Create(aParams, aLength, this, aFlags); - if (!textRun) - return nullptr; - - mEnableKerning = !(aFlags & gfxTextRunFactory::TEXT_OPTIMIZE_SPEED); - - nsAutoCString utf8; - int32_t headerLen = AppendDirectionalIndicatorUTF8(textRun->IsRightToLeft(), utf8); - AppendUTF16toUTF8(Substring(aString, aString + aLength), utf8); - -#ifdef DEBUG_thebes_2 - NS_ConvertUTF8toUTF16 u16(utf8); - printf("gfxOS2FontGroup[%#x]::MakeTextRun(PRUnichar %s, %d, %#x, %d)\n", - (unsigned)this, NS_LossyConvertUTF16toASCII(u16).get(), aLength, (unsigned)aParams, aFlags); -#endif - - InitTextRun(textRun, (uint8_t *)utf8.get(), utf8.Length(), headerLen); - - textRun->FetchGlyphExtents(aParams->mContext); - - return textRun; -} - -gfxTextRun *gfxOS2FontGroup::MakeTextRun(const uint8_t* aString, uint32_t aLength, - const Parameters* aParams, uint32_t aFlags) -{ -#ifdef DEBUG_thebes_2 - const char *cStr = reinterpret_cast<const char *>(aString); - NS_ConvertASCIItoUTF16 us(cStr, aLength); - printf("gfxOS2FontGroup[%#x]::MakeTextRun(uint8_t %s, %d, %#x, %d)\n", - (unsigned)this, NS_LossyConvertUTF16toASCII(us).get(), aLength, (unsigned)aParams, aFlags); -#endif - NS_ASSERTION(aLength > 0, "should use MakeEmptyTextRun for zero-length text"); - NS_ASSERTION(aFlags & TEXT_IS_8BIT, "8bit should have been set"); - gfxTextRun *textRun = gfxTextRun::Create(aParams, aLength, this, aFlags); - if (!textRun) - return nullptr; - - mEnableKerning = !(aFlags & gfxTextRunFactory::TEXT_OPTIMIZE_SPEED); - - const char *chars = reinterpret_cast<const char *>(aString); - bool isRTL = textRun->IsRightToLeft(); - if ((aFlags & TEXT_IS_ASCII) && !isRTL) { - // We don't need to send an override character here, the characters must be all - // LTR - InitTextRun(textRun, (uint8_t *)chars, aLength, 0); - } else { - // Although chars in not necessarily ASCII (as it may point to the low - // bytes of any UCS-2 characters < 256), NS_ConvertASCIItoUTF16 seems - // to DTRT. - NS_ConvertASCIItoUTF16 unicodeString(chars, aLength); - nsAutoCString utf8; - int32_t headerLen = AppendDirectionalIndicatorUTF8(isRTL, utf8); - AppendUTF16toUTF8(unicodeString, utf8); - InitTextRun(textRun, (uint8_t *)utf8.get(), utf8.Length(), headerLen); - } - - textRun->FetchGlyphExtents(aParams->mContext); - - return textRun; -} - -void gfxOS2FontGroup::InitTextRun(gfxTextRun *aTextRun, const uint8_t *aUTF8Text, - uint32_t aUTF8Length, - uint32_t aUTF8HeaderLength) -{ - CreateGlyphRunsFT(aTextRun, aUTF8Text + aUTF8HeaderLength, - aUTF8Length - aUTF8HeaderLength); -} - -// Helper function to return the leading UTF-8 character in a char pointer -// as 32bit number. Also sets the length of the current character (i.e. the -// offset to the next one) in the second argument -uint32_t getUTF8CharAndNext(const uint8_t *aString, uint8_t *aLength) -{ - *aLength = 1; - if (aString[0] < 0x80) { // normal 7bit ASCII char - return aString[0]; - } - if ((aString[0] >> 5) == 6) { // two leading ones -> two bytes - *aLength = 2; - return ((aString[0] & 0x1F) << 6) + (aString[1] & 0x3F); - } - if ((aString[0] >> 4) == 14) { // three leading ones -> three bytes - *aLength = 3; - return ((aString[0] & 0x0F) << 12) + ((aString[1] & 0x3F) << 6) + - (aString[2] & 0x3F); - } - if ((aString[0] >> 4) == 15) { // four leading ones -> four bytes - *aLength = 4; - return ((aString[0] & 0x07) << 18) + ((aString[1] & 0x3F) << 12) + - ((aString[2] & 0x3F) << 6) + (aString[3] & 0x3F); - } - return aString[0]; -} - -void gfxOS2FontGroup::CreateGlyphRunsFT(gfxTextRun *aTextRun, const uint8_t *aUTF8, - uint32_t aUTF8Length) -{ -#ifdef DEBUG_thebes_2 - printf("gfxOS2FontGroup::CreateGlyphRunsFT(%#x, _aUTF8_, %d)\n", - (unsigned)aTextRun, /*aUTF8,*/ aUTF8Length); - for (uint32_t i = 0; i < FontListLength(); i++) { - gfxOS2Font *font = GetFontAt(i); - printf(" i=%d, name=%s, size=%f\n", i, NS_LossyConvertUTF16toASCII(font->GetName()).get(), - font->GetStyle()->size); - } -#endif - uint32_t lastFont = FontListLength()-1; - gfxOS2Font *font0 = GetFontAt(0); - const uint8_t *p = aUTF8; - uint32_t utf16Offset = 0; - gfxTextRun::CompressedGlyph g; - const uint32_t appUnitsPerDevUnit = aTextRun->GetAppUnitsPerDevUnit(); - gfxOS2Platform *platform = gfxOS2Platform::GetPlatform(); - - aTextRun->AddGlyphRun(font0, gfxTextRange::kFontGroup, 0, false); - // a textRun likely has the same font for most of the characters, so we can - // lock it before the loop for efficiency - FT_Face face0 = cairo_ft_scaled_font_lock_face(font0->CairoScaledFont()); - while (p < aUTF8 + aUTF8Length) { - bool glyphFound = false; - // convert UTF-8 character and step to the next one in line - uint8_t chLen; - uint32_t ch = getUTF8CharAndNext(p, &chLen); - p += chLen; // move to next char -#ifdef DEBUG_thebes_2 - printf("\'%c\' (%d, %#x, %s) [%#x %#x]:", (char)ch, ch, ch, ch >=0x10000 ? "non-BMP!" : "BMP", ch >=0x10000 ? H_SURROGATE(ch) : 0, ch >=0x10000 ? L_SURROGATE(ch) : 0); -#endif - - if (ch == 0 || platform->noFontWithChar(ch)) { - // null bytes or missing characters cannot be displayed - aTextRun->SetMissingGlyph(utf16Offset, ch); - } else { - // Try to get a glyph from all fonts available to us. - // Once we found it in one of the fonts we quit the loop early. - // If we don't find the glyph even in the last font, we will fall - // back to searching all fonts on the system and finally set the - // missing glyph symbol after trying the last font. - for (uint32_t i = 0; i <= lastFont; i++) { - gfxOS2Font *font = font0; - FT_Face face = face0; - if (i > 0) { - font = GetFontAt(i); - face = cairo_ft_scaled_font_lock_face(font->CairoScaledFont()); -#ifdef DEBUG_thebes_2 - if (i == lastFont) { - printf("Last font %d (%s) for ch=%#x (pos=%d)", - i, NS_LossyConvertUTF16toASCII(font->GetName()).get(), ch, utf16Offset); - } -#endif - } - if (!face || !face->charmap) { // don't try to use fonts with non-Unicode charmaps - if (face && face != face0) - cairo_ft_scaled_font_unlock_face(font->CairoScaledFont()); - continue; // next font - } - - NS_ASSERTION(!IsInvalidChar(ch), "Invalid char detected"); - FT_UInt gid = FT_Get_Char_Index(face, ch); // find the glyph id - - if (gid == 0 && i == lastFont) { - // missing glyph, try to find a replacement in another font - nsRefPtr<gfxOS2Font> fontX = platform->FindFontForChar(ch, font0); - if (fontX) { - font = fontX; // replace current font - cairo_ft_scaled_font_unlock_face(font->CairoScaledFont()); - face = cairo_ft_scaled_font_lock_face(fontX->CairoScaledFont()); - gid = FT_Get_Char_Index(face, ch); - // likely to find more chars in this font, append it - // to the font list to find it quicker next time - mFonts.AppendElement(fontX); - lastFont = FontListLength()-1; - } - } - - // select the current font into the text run - aTextRun->AddGlyphRun(font, gfxTextRange::kFontGroup, utf16Offset, false); - - int32_t advance = 0; - if (gid == font->GetSpaceGlyph()) { - advance = (int)(font->GetMetrics().spaceWidth * appUnitsPerDevUnit); - } else if (gid == 0) { - advance = -1; // trigger the missing glyphs case below - } else { - // find next character and its glyph -- in case they exist - // and exist in the current font face -- to compute kerning - uint32_t chNext = 0; - FT_UInt gidNext = 0; - FT_Pos lsbDeltaNext = 0; -#ifdef DEBUG_thebes_2 - printf("(kerning=%s/%s)", mEnableKerning ? "enable" : "disable", FT_HAS_KERNING(face) ? "yes" : "no"); -#endif - if (mEnableKerning && FT_HAS_KERNING(face) && p < aUTF8 + aUTF8Length) { - chNext = getUTF8CharAndNext(p, &chLen); - if (chNext) { - gidNext = FT_Get_Char_Index(face, chNext); - if (gidNext && gidNext != font->GetSpaceGlyph()) { - FT_Load_Glyph(face, gidNext, FT_LOAD_DEFAULT); - lsbDeltaNext = face->glyph->lsb_delta; - } - } - } - - // now load the current glyph - FT_Load_Glyph(face, gid, FT_LOAD_DEFAULT); // load glyph into the slot - advance = face->glyph->advance.x; - - // now add kerning to the current glyph's advance - if (chNext && gidNext) { - FT_Vector kerning; - FT_Get_Kerning(face, gid, gidNext, FT_KERNING_DEFAULT, &kerning); - advance += kerning.x; - if (face->glyph->rsb_delta - lsbDeltaNext >= 32) { - advance -= 64; - } else if (face->glyph->rsb_delta - lsbDeltaNext < -32) { - advance += 64; - } - } - - // now apply unit conversion and scaling - advance = (advance >> 6) * appUnitsPerDevUnit; - } -#ifdef DEBUG_thebes_2 - printf(" gid=%d, advance=%d (%s)\n", gid, advance, - NS_LossyConvertUTF16toASCII(font->GetName()).get()); -#endif - - if (advance >= 0 && - gfxTextRun::CompressedGlyph::IsSimpleAdvance(advance) && - gfxTextRun::CompressedGlyph::IsSimpleGlyphID(gid)) - { - aTextRun->SetSimpleGlyph(utf16Offset, - g.SetSimpleGlyph(advance, gid)); - glyphFound = true; - } else if (gid == 0) { - // gid = 0 only happens when the glyph is missing from the font - if (i == lastFont) { - // set the missing glyph only when it's missing from the very - // last font - aTextRun->SetMissingGlyph(utf16Offset, ch); - } - glyphFound = false; - } else { - gfxTextRun::DetailedGlyph details; - details.mGlyphID = gid; - NS_ASSERTION(details.mGlyphID == gid, "Seriously weird glyph ID detected!"); - details.mAdvance = advance; - details.mXOffset = 0; - details.mYOffset = 0; - g.SetComplex(aTextRun->IsClusterStart(utf16Offset), true, 1); - aTextRun->SetGlyphs(utf16Offset, g, &details); - glyphFound = true; - } - - if (i > 0) { - cairo_ft_scaled_font_unlock_face(font->CairoScaledFont()); - } - - if (glyphFound) { - break; - } - } - } // for all fonts - - NS_ASSERTION(!IS_SURROGATE(ch), "Surrogates shouldn't appear in UTF8"); - if (ch >= 0x10000) { - // This character is a surrogate pair in UTF16 - ++utf16Offset; - } - - ++utf16Offset; - } - cairo_ft_scaled_font_unlock_face(font0->CairoScaledFont()); -} - -// append aFontName to aClosure string array, if not already present -bool gfxOS2FontGroup::FontCallback(const nsAString& aFontName, - const nsACString& aGenericName, - bool aUseFontSet, - void *aClosure) -{ - nsTArray<nsString> *sa = static_cast<nsTArray<nsString>*>(aClosure); - if (!aFontName.IsEmpty() && !sa->Contains(aFontName)) { - sa->AppendElement(aFontName); - } - return true; -} diff --git a/gfx/thebes/gfxOS2Fonts.h b/gfx/thebes/gfxOS2Fonts.h deleted file mode 100644 index b353c4770..000000000 --- a/gfx/thebes/gfxOS2Fonts.h +++ /dev/null @@ -1,105 +0,0 @@ -/* vim: set sw=4 sts=4 et cin: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef GFX_OS2_FONTS_H -#define GFX_OS2_FONTS_H - -#include "gfxTypes.h" -#include "gfxFont.h" -#include "gfxMatrix.h" -#include "nsDataHashtable.h" - -#define INCL_GPI -#include <os2.h> -#include <cairo-os2.h> -#include "cairo-ft.h" // includes fontconfig.h, too -#include <freetype/tttables.h> - -#include "nsICharsetConverterManager.h" - -class gfxOS2FontEntry : public gfxFontEntry { -public: - gfxOS2FontEntry(const nsAString& aName) : gfxFontEntry(aName) {} - ~gfxOS2FontEntry() {} -}; - -class gfxOS2Font : public gfxFont { -public: - gfxOS2Font(gfxOS2FontEntry *aFontEntry, const gfxFontStyle *aFontStyle); - virtual ~gfxOS2Font(); - - virtual const gfxFont::Metrics& GetMetrics(); - cairo_font_face_t *CairoFontFace(); - cairo_scaled_font_t *CairoScaledFont(); - - // Get the glyphID of a space - virtual uint32_t GetSpaceGlyph() { - if (!mMetrics) - GetMetrics(); - return mSpaceGlyph; - } - - static already_AddRefed<gfxOS2Font> GetOrMakeFont(const nsAString& aName, - const gfxFontStyle *aStyle); - -protected: - virtual bool SetupCairoFont(gfxContext *aContext); - - virtual FontType GetType() const { return FONT_TYPE_OS2; } - -private: - cairo_font_face_t *mFontFace; - Metrics *mMetrics; - gfxFloat mAdjustedSize; - uint32_t mSpaceGlyph; - int mHinting; - bool mAntialias; -}; - - -class gfxOS2FontGroup : public gfxFontGroup { -public: - gfxOS2FontGroup(const nsAString& aFamilies, const gfxFontStyle* aStyle, gfxUserFontSet *aUserFontSet); - virtual ~gfxOS2FontGroup(); - - virtual gfxFontGroup *Copy(const gfxFontStyle *aStyle); - - // create and initialize the textRun using FreeType font - virtual gfxTextRun *MakeTextRun(const PRUnichar* aString, uint32_t aLength, - const Parameters* aParams, uint32_t aFlags); - virtual gfxTextRun *MakeTextRun(const uint8_t* aString, uint32_t aLength, - const Parameters* aParams, uint32_t aFlags); - - gfxOS2Font *GetFontAt(int32_t i) { - // If it turns out to be hard for all clients that cache font - // groups to call UpdateFontList at appropriate times, we could - // instead consider just calling UpdateFontList from someplace - // more central (such as here). - NS_ASSERTION(!mUserFontSet || mCurrGeneration == GetGeneration(), - "Whoever was caching this font group should have " - "called UpdateFontList on it"); - -#ifdef DEBUG_thebes_2 - printf("gfxOS2FontGroup[%#x]::GetFontAt(%d), %#x, %#x\n", - (unsigned)this, i, (unsigned)&mFonts, (unsigned)&mFonts[i]); -#endif - return static_cast<gfxOS2Font*>(static_cast<gfxFont*>(mFonts[i])); - } - -protected: - void InitTextRun(gfxTextRun *aTextRun, const uint8_t *aUTF8Text, - uint32_t aUTF8Length, uint32_t aUTF8HeaderLength); - void CreateGlyphRunsFT(gfxTextRun *aTextRun, const uint8_t *aUTF8, - uint32_t aUTF8Length); - static bool FontCallback(const nsAString& aFontName, - const nsACString& aGenericName, - bool aUseFontSet, - void *aClosure); - -private: - bool mEnableKerning; -}; - -#endif /* GFX_OS2_FONTS_H */ diff --git a/gfx/thebes/gfxOS2Platform.cpp b/gfx/thebes/gfxOS2Platform.cpp deleted file mode 100644 index f8eee640a..000000000 --- a/gfx/thebes/gfxOS2Platform.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/* vim: set sw=4 sts=4 et cin: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "gfxOS2Platform.h" -#include "gfxOS2Surface.h" -#include "gfxImageSurface.h" -#include "gfxOS2Fonts.h" -#include "nsTArray.h" - -#include "gfxFontconfigUtils.h" -//#include <fontconfig/fontconfig.h> - -/********************************************************************** - * class gfxOS2Platform - **********************************************************************/ -gfxFontconfigUtils *gfxOS2Platform::sFontconfigUtils = nullptr; - -gfxOS2Platform::gfxOS2Platform() -{ -#ifdef DEBUG_thebes - printf("gfxOS2Platform::gfxOS2Platform()\n"); -#endif - // this seems to be reasonably early in the process and only once, - // so it's a good place to initialize OS/2 cairo stuff - cairo_os2_init(); -#ifdef DEBUG_thebes - printf(" cairo_os2_init() was called\n"); -#endif - if (!sFontconfigUtils) { - sFontconfigUtils = gfxFontconfigUtils::GetFontconfigUtils(); - } -} - -gfxOS2Platform::~gfxOS2Platform() -{ -#ifdef DEBUG_thebes - printf("gfxOS2Platform::~gfxOS2Platform()\n"); -#endif - gfxFontconfigUtils::Shutdown(); - sFontconfigUtils = nullptr; - - // clean up OS/2 cairo stuff - cairo_os2_fini(); -#ifdef DEBUG_thebes - printf(" cairo_os2_fini() was called\n"); -#endif -} - -already_AddRefed<gfxASurface> -gfxOS2Platform::CreateOffscreenSurface(const gfxIntSize& aSize, - gfxASurface::gfxContentType contentType) -{ -#ifdef DEBUG_thebes_2 - printf("gfxOS2Platform::CreateOffscreenSurface(%d/%d, %d)\n", - aSize.width, aSize.height, aImageFormat); -#endif - gfxASurface *newSurface = nullptr; - - // we only ever seem to get aImageFormat=0 or ImageFormatARGB32 but - // I don't really know if we need to differ between ARGB32 and RGB24 here - if (contentType == gfxASurface::CONTENT_COLOR_ALPHA || - contentType == gfxASurface::CONTENT_COLOR) - { - newSurface = new gfxOS2Surface(aSize, OptimalFormatForContent(contentType)); - } else if (contentType == gfxASurface::CONTENT_ALPHA) { - newSurface = new gfxImageSurface(aSize, OptimalFormatForContent(contentType)); - } else { - return nullptr; - } - - NS_IF_ADDREF(newSurface); - return newSurface; -} - -nsresult -gfxOS2Platform::GetFontList(nsIAtom *aLangGroup, - const nsACString& aGenericFamily, - nsTArray<nsString>& aListOfFonts) -{ -#ifdef DEBUG_thebes - const char *langgroup = "(null)"; - if (aLangGroup) { - aLangGroup->GetUTF8String(&langgroup); - } - char *family = ToNewCString(aGenericFamily); - printf("gfxOS2Platform::GetFontList(%s, %s, ..)\n", - langgroup, family); - free(family); -#endif - return sFontconfigUtils->GetFontList(aLangGroup, aGenericFamily, - aListOfFonts); -} - -nsresult gfxOS2Platform::UpdateFontList() -{ -#ifdef DEBUG_thebes - printf("gfxOS2Platform::UpdateFontList()\n"); -#endif - mCodepointsWithNoFonts.reset(); - - nsresult rv = sFontconfigUtils->UpdateFontList(); - - // initialize ranges of characters for which system-wide font search should be skipped - mCodepointsWithNoFonts.SetRange(0,0x1f); // C0 controls - mCodepointsWithNoFonts.SetRange(0x7f,0x9f); // C1 controls - return rv; -} - -nsresult -gfxOS2Platform::ResolveFontName(const nsAString& aFontName, - FontResolverCallback aCallback, - void *aClosure, bool& aAborted) -{ -#ifdef DEBUG_thebes - char *fontname = ToNewCString(aFontName); - printf("gfxOS2Platform::ResolveFontName(%s, ...)\n", fontname); - free(fontname); -#endif - return sFontconfigUtils->ResolveFontName(aFontName, aCallback, aClosure, - aAborted); -} - -nsresult -gfxOS2Platform::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName) -{ - return sFontconfigUtils->GetStandardFamilyName(aFontName, aFamilyName); -} - -gfxFontGroup * -gfxOS2Platform::CreateFontGroup(const nsAString &aFamilies, - const gfxFontStyle *aStyle, - gfxUserFontSet *aUserFontSet) -{ - return new gfxOS2FontGroup(aFamilies, aStyle, aUserFontSet); -} - -already_AddRefed<gfxOS2Font> -gfxOS2Platform::FindFontForChar(uint32_t aCh, gfxOS2Font *aFont) -{ -#ifdef DEBUG_thebes - printf("gfxOS2Platform::FindFontForChar(%d, ...)\n", aCh); -#endif - - // is codepoint with no matching font? return null immediately - if (mCodepointsWithNoFonts.test(aCh)) { - return nullptr; - } - - // the following is not very clever but it's a quick fix to search all fonts - // (one should instead cache the charmaps as done on Mac and Win) - - // just continue to append all fonts known to the system - nsTArray<nsString> fontList; - nsAutoCString generic; - nsresult rv = GetFontList(aFont->GetStyle()->language, generic, fontList); - if (NS_SUCCEEDED(rv)) { - // start at 3 to skip over the generic entries - for (uint32_t i = 3; i < fontList.Length(); i++) { -#ifdef DEBUG_thebes - printf("searching in entry i=%d (%s)\n", - i, NS_LossyConvertUTF16toASCII(fontList[i]).get()); -#endif - nsRefPtr<gfxOS2Font> font = - gfxOS2Font::GetOrMakeFont(fontList[i], aFont->GetStyle()); - if (!font) - continue; - FT_Face face = cairo_ft_scaled_font_lock_face(font->CairoScaledFont()); - if (!face || !face->charmap) { - if (face) - cairo_ft_scaled_font_unlock_face(font->CairoScaledFont()); - continue; - } - - FT_UInt gid = FT_Get_Char_Index(face, aCh); // find the glyph id - if (gid != 0) { - // this is the font - cairo_ft_scaled_font_unlock_face(font->CairoScaledFont()); - return font.forget(); - } - } - } - - // no match found, so add to the set of non-matching codepoints - mCodepointsWithNoFonts.set(aCh); - return nullptr; -} diff --git a/gfx/thebes/gfxOS2Platform.h b/gfx/thebes/gfxOS2Platform.h deleted file mode 100644 index 2c2a2c034..000000000 --- a/gfx/thebes/gfxOS2Platform.h +++ /dev/null @@ -1,65 +0,0 @@ -/* vim: set sw=4 sts=4 et cin: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef GFX_OS2_PLATFORM_H -#define GFX_OS2_PLATFORM_H - -#define INCL_GPIBITMAPS -#include <os2.h> - -#include "gfxPlatform.h" -#include "gfxOS2Fonts.h" -#include "gfxFontUtils.h" -#include "nsTArray.h" - -class gfxFontconfigUtils; - -class gfxOS2Platform : public gfxPlatform { - -public: - gfxOS2Platform(); - virtual ~gfxOS2Platform(); - - static gfxOS2Platform *GetPlatform() { - return (gfxOS2Platform*) gfxPlatform::GetPlatform(); - } - - already_AddRefed<gfxASurface> - CreateOffscreenSurface(const gfxIntSize& size, - gfxASurface::gfxContentType contentType); - - nsresult GetFontList(nsIAtom *aLangGroup, - const nsACString& aGenericFamily, - nsTArray<nsString>& aListOfFonts); - nsresult UpdateFontList(); - nsresult ResolveFontName(const nsAString& aFontName, - FontResolverCallback aCallback, - void *aClosure, bool& aAborted); - nsresult GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName); - - gfxFontGroup *CreateFontGroup(const nsAString &aFamilies, - const gfxFontStyle *aStyle, - gfxUserFontSet *aUserFontSet); - - // Given a string and a font we already have, find the font that - // supports the most code points and most closely resembles aFont. - // This simple version involves looking at the fonts on the machine to see - // which code points they support. - already_AddRefed<gfxOS2Font> FindFontForChar(uint32_t aCh, gfxOS2Font *aFont); - - // return true if it's already known that we don't have a font for this char - bool noFontWithChar(uint32_t aCh) { - return mCodepointsWithNoFonts.test(aCh); - } - -protected: - static gfxFontconfigUtils *sFontconfigUtils; - -private: - // when font lookup fails for a character, cache it to skip future searches - gfxSparseBitSet mCodepointsWithNoFonts; -}; - -#endif /* GFX_OS2_PLATFORM_H */ diff --git a/gfx/thebes/gfxOS2Surface.cpp b/gfx/thebes/gfxOS2Surface.cpp deleted file mode 100644 index 18098617f..000000000 --- a/gfx/thebes/gfxOS2Surface.cpp +++ /dev/null @@ -1,203 +0,0 @@ -/* vim: set sw=4 sts=4 et cin: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "gfxOS2Surface.h" - -#include <stdio.h> - -/********************************************************************** - * class gfxOS2Surface - **********************************************************************/ - -gfxOS2Surface::gfxOS2Surface(const gfxIntSize& aSize, - gfxASurface::gfxImageFormat aImageFormat) - : mWnd(0), mSize(aSize) -{ -#ifdef DEBUG_thebes_2 - printf("gfxOS2Surface[%#x]::gfxOS2Surface(Size=%dx%d, %d)\n", (unsigned int)this, - aSize.width, aSize.height, aImageFormat); -#endif - // in this case we don't have a window, so we create a memory presentation - // space to construct the cairo surface on - - // create a PS, partly taken from nsOffscreenSurface::Init(), i.e. nsDrawingSurfaceOS2.cpp - DEVOPENSTRUC dop = { 0, 0, 0, 0, 0 }; - SIZEL sizel = { 0, 0 }; // use same page size as device - mDC = DevOpenDC(0, OD_MEMORY, (PSZ)"*", 5, (PDEVOPENDATA)&dop, NULLHANDLE); - NS_ASSERTION(mDC != DEV_ERROR, "Could not create memory DC"); - - mPS = GpiCreatePS(0, mDC, &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC); - NS_ASSERTION(mPS != GPI_ERROR, "Could not create PS on memory DC!"); - - // now create a bitmap of the right size - BITMAPINFOHEADER2 hdr = { 0 }; - hdr.cbFix = sizeof(BITMAPINFOHEADER2); - hdr.cx = mSize.width; - hdr.cy = mSize.height; - hdr.cPlanes = 1; - - // find bit depth - LONG lBitCount = 0; - DevQueryCaps(mDC, CAPS_COLOR_BITCOUNT, 1, &lBitCount); - hdr.cBitCount = (USHORT)lBitCount; - - mBitmap = GpiCreateBitmap(mPS, &hdr, 0, 0, 0); - NS_ASSERTION(mBitmap != GPI_ERROR, "Could not create bitmap in memory!"); - // set final stats & select bitmap into PS - GpiSetBitmap(mPS, mBitmap); - - // now we can finally create the cairo surface on the in-memory PS - cairo_surface_t *surf = cairo_os2_surface_create(mPS, mSize.width, mSize.height); -#ifdef DEBUG_thebes_2 - printf(" type(%#x)=%d (ID=%#x, h/w=%d/%d)\n", (unsigned int)surf, - cairo_surface_get_type(surf), (unsigned int)mPS, mSize.width, mSize.height); -#endif - // Normally, OS/2 cairo surfaces have to be forced to redraw completely - // by calling cairo_surface_mark_dirty(surf), but Mozilla paints them in - // full, so that is not necessary here. - - // manual refresh is done from nsWindow::OnPaint - cairo_os2_surface_set_manual_window_refresh(surf, 1); - - Init(surf); -} - -gfxOS2Surface::gfxOS2Surface(HWND aWnd) - : mWnd(aWnd), mDC(nullptr), mPS(nullptr), mBitmap(nullptr) -{ -#ifdef DEBUG_thebes_2 - printf("gfxOS2Surface[%#x]::gfxOS2Surface(HWND=%#x)\n", (unsigned int)this, - (unsigned int)aWnd); -#endif - - RECTL rectl; - WinQueryWindowRect(aWnd, &rectl); - mSize.width = rectl.xRight - rectl.xLeft; - mSize.height = rectl.yTop - rectl.yBottom; - if (mSize.width == 0) mSize.width = 1; // fake a minimal surface area to let - if (mSize.height == 0) mSize.height = 1; // cairo_os2_surface_create() return something - - // This variation on cairo_os2_surface_create() avoids creating a - // persistent HPS that may never be used. It also enables manual - // refresh so nsWindow::OnPaint() controls when the screen is updated. - cairo_surface_t *surf = - cairo_os2_surface_create_for_window(mWnd, mSize.width, mSize.height); -#ifdef DEBUG_thebes_2 - printf(" type(%#x)=%d (ID=%#x, h/w=%d/%d)\n", (unsigned int)surf, - cairo_surface_get_type(surf), (unsigned int)mPS, mSize.width, mSize.height); -#endif - - Init(surf); -} - -gfxOS2Surface::gfxOS2Surface(HDC aDC, const gfxIntSize& aSize) - : mWnd(0), mDC(aDC), mBitmap(nullptr), mSize(aSize) -{ -#ifdef DEBUG_thebes_2 - printf("gfxOS2Surface[%#x]::gfxOS2Surface(HDC=%#x, Size=%dx%d)\n", (unsigned int)this, - (unsigned int)aDC, aSize.width, aSize.height); -#endif - SIZEL sizel = { 0, 0 }; // use same page size as device - mPS = GpiCreatePS(0, mDC, &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC); - NS_ASSERTION(mPS != GPI_ERROR, "Could not create PS on print DC!"); - - // now create a bitmap of the right size - BITMAPINFOHEADER2 hdr = { 0 }; - hdr.cbFix = sizeof(BITMAPINFOHEADER2); - hdr.cx = mSize.width; - hdr.cy = mSize.height; - hdr.cPlanes = 1; - - // find bit depth - LONG lBitCount = 0; - DevQueryCaps(mDC, CAPS_COLOR_BITCOUNT, 1, &lBitCount); - hdr.cBitCount = (USHORT)lBitCount; - - mBitmap = GpiCreateBitmap(mPS, &hdr, 0, 0, 0); - NS_ASSERTION(mBitmap != GPI_ERROR, "Could not create bitmap for printer!"); - // set final stats & select bitmap into PS - GpiSetBitmap(mPS, mBitmap); - - // now we can finally create the cairo surface on the in-memory PS - cairo_surface_t *surf = cairo_os2_surface_create(mPS, mSize.width, mSize.height); -#ifdef DEBUG_thebes_2 - printf(" type(%#x)=%d (ID=%#x, h/w=%d/%d)\n", (unsigned int)surf, - cairo_surface_get_type(surf), (unsigned int)mPS, mSize.width, mSize.height); -#endif - // Normally, OS/2 cairo surfaces have to be forced to redraw completely - // by calling cairo_surface_mark_dirty(surf), but Mozilla paints them in - // full, so that is not necessary here. - - Init(surf); -} - -gfxOS2Surface::~gfxOS2Surface() -{ -#ifdef DEBUG_thebes_2 - printf("gfxOS2Surface[%#x]::~gfxOS2Surface()\n", (unsigned int)this); -#endif - - // Surfaces connected to a window were created using WinGetPS so we should - // release it again with WinReleasePS. Memory or printer surfaces on the - // other hand were created on device contexts with the GPI functions, so - // use those to clean up stuff. - if (mWnd) { - if (mPS) { - WinReleasePS(mPS); - } - } else { - if (mBitmap) { - GpiSetBitmap(mPS, NULL); - GpiDeleteBitmap(mBitmap); - } - if (mPS) { - GpiDestroyPS(mPS); - } - if (mDC) { - DevCloseDC(mDC); - } - } -} - -void gfxOS2Surface::Refresh(RECTL *aRect, HPS aPS) -{ -#ifdef DEBUG_thebes_2 - printf("gfxOS2Surface[%#x]::Refresh(x=%ld,%ld/y=%ld,%ld, HPS=%#x), mPS=%#x\n", - (unsigned int)this, - aRect->xLeft, aRect->xRight, aRect->yBottom, aRect->yTop, - (unsigned int)aPS, (unsigned int)mPS); -#endif - cairo_os2_surface_refresh_window(CairoSurface(), (aPS ? aPS : mPS), aRect); -} - -int gfxOS2Surface::Resize(const gfxIntSize& aSize) -{ -#ifdef DEBUG_thebes_2 - printf("gfxOS2Surface[%#x]::Resize(%dx%d)\n", (unsigned int)this, - aSize.width, aSize.height); -#endif - mSize = aSize; // record the new size - // hardcode mutex timeout to 50ms for now - return cairo_os2_surface_set_size(CairoSurface(), mSize.width, mSize.height, 50); -} - -HPS gfxOS2Surface::GetPS() -{ - // Creating an HPS on-the-fly should never be needed because GetPS() - // is only called for printing surfaces & mPS should only be null for - // window surfaces. It would be a bug if Cairo had an HPS but Thebes - // didn't, but we'll check anyway to avoid leakage. As a last resort, - // if this is a window surface we'll create one & hang on to it. - if (!mPS) { - cairo_os2_surface_get_hps(CairoSurface(), &mPS); - if (!mPS && mWnd) { - mPS = WinGetPS(mWnd); - cairo_os2_surface_set_hps(CairoSurface(), mPS); - } - } - - return mPS; -} - diff --git a/gfx/thebes/gfxOS2Surface.h b/gfx/thebes/gfxOS2Surface.h deleted file mode 100644 index 85f8ca466..000000000 --- a/gfx/thebes/gfxOS2Surface.h +++ /dev/null @@ -1,48 +0,0 @@ -/* vim: set sw=4 sts=4 et cin: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef GFX_OS2_SURFACE_H -#define GFX_OS2_SURFACE_H - -#include "gfxASurface.h" - -#define INCL_GPIBITMAPS -#include <os2.h> -#include <cairo-os2.h> - -class gfxOS2Surface : public gfxASurface { - -public: - // constructor used to create a memory surface of given size - gfxOS2Surface(const gfxIntSize& aSize, - gfxASurface::gfxImageFormat aImageFormat); - // constructor for surface connected to an onscreen window - gfxOS2Surface(HWND aWnd); - // constructor for surface connected to a printing device context - gfxOS2Surface(HDC aDC, const gfxIntSize& aSize); - virtual ~gfxOS2Surface(); - - // Special functions that only make sense for the OS/2 port of cairo: - - // Update the cairo surface. - // While gfxOS2Surface keeps track of the presentation handle itself, - // use the one from WinBeginPaint() here. - void Refresh(RECTL *aRect, HPS aPS); - - // Reset the cairo surface to the given size. - int Resize(const gfxIntSize& aSize); - - HPS GetPS(); - virtual const gfxIntSize GetSize() const { return mSize; } - -private: - HWND mWnd; // non-null if created through the HWND constructor - HDC mDC; // memory device context - HPS mPS; // presentation space connected to window or memory device - HBITMAP mBitmap; // bitmap for initialization of memory surface - gfxIntSize mSize; // current size of the surface -}; - -#endif /* GFX_OS2_SURFACE_H */ diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index 43e9d2560..73601d43c 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -27,8 +27,6 @@ #include "gfxPlatformGtk.h" #elif defined(MOZ_WIDGET_QT) #include "gfxQtPlatform.h" -#elif defined(XP_OS2) -#include "gfxOS2Platform.h" #elif defined(ANDROID) #include "gfxAndroidPlatform.h" #endif @@ -320,8 +318,6 @@ gfxPlatform::Init() gPlatform = new gfxPlatformGtk; #elif defined(MOZ_WIDGET_QT) gPlatform = new gfxQtPlatform; -#elif defined(XP_OS2) - gPlatform = new gfxOS2Platform; #elif defined(ANDROID) gPlatform = new gfxAndroidPlatform; #else diff --git a/gfx/thebes/gfxPlatform.h b/gfx/thebes/gfxPlatform.h index 6ddd0330e..03e5e3c4a 100644 --- a/gfx/thebes/gfxPlatform.h +++ b/gfx/thebes/gfxPlatform.h @@ -21,10 +21,6 @@ #include "mozilla/RefPtr.h" #include "GfxInfoCollector.h" -#ifdef XP_OS2 -#undef OS2EMX_PLAIN_CHAR -#endif - class gfxImageSurface; class gfxFont; class gfxFontGroup; diff --git a/gfx/thebes/moz.build b/gfx/thebes/moz.build index 991378da0..a38ecd837 100644 --- a/gfx/thebes/moz.build +++ b/gfx/thebes/moz.build @@ -136,21 +136,6 @@ elif CONFIG['MOZ_WIDGET_GTK']: CPP_SOURCES += [ 'gfxPangoFonts.cpp', ] -elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'os2': - EXPORTS += [ - 'gfxOS2Fonts.h', - 'gfxOS2Platform.h', - 'gfxOS2Surface.h', - 'gfxPDFSurface.h', - ] - CPP_SOURCES += [ - 'gfxOS2Fonts.cpp', - 'gfxOS2Platform.cpp', - 'gfxOS2Surface.cpp', - 'nsUnicodeRange.cpp', - 'gfxFontconfigUtils.cpp', - 'gfxPDFSurface.cpp' - ] elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'qt': EXPORTS += [ 'gfxFT2FontBase.h', |