diff options
author | Caolán McNamara <caolanm@redhat.com> | 2015-11-13 15:54:00 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2015-11-23 14:25:58 +0000 |
commit | b0f5416d7ee7c988d316df7ffa0318fa6514e4de (patch) | |
tree | c196c9966ee53499559806050bb2f01195d91c23 /vcl/generic/glyphs | |
parent | Updated core (diff) | |
download | core-b0f5416d7ee7c988d316df7ffa0318fa6514e4de.tar.gz core-b0f5416d7ee7c988d316df7ffa0318fa6514e4de.zip |
Do all svp text rendering with cairo
enabling us to delete a whole pile of foo
For android we patch cairo, which is internal in that case, to swap the rgb
components so that cairo then matches the OpenGL GL_RGBA format so we can use
it there where we don't have GL_BGRA support.
Change-Id: I25e34889c7b7263438b143dd2a2ad882fb0f190a
Diffstat (limited to 'vcl/generic/glyphs')
-rw-r--r-- | vcl/generic/glyphs/gcach_ftyp.cxx | 272 | ||||
-rw-r--r-- | vcl/generic/glyphs/gcach_rbmp.cxx | 251 |
2 files changed, 0 insertions, 523 deletions
diff --git a/vcl/generic/glyphs/gcach_ftyp.cxx b/vcl/generic/glyphs/gcach_ftyp.cxx index 2e874e51eccc..51bb542642e4 100644 --- a/vcl/generic/glyphs/gcach_ftyp.cxx +++ b/vcl/generic/glyphs/gcach_ftyp.cxx @@ -987,278 +987,6 @@ bool ServerFont::GetAntialiasAdvice() const return bAdviseAA; } -bool ServerFont::GetGlyphBitmap1( sal_GlyphId aGlyphId, RawBitmap& rRawBitmap ) const -{ - FT_Activate_Size( maSizeFT ); - - int nGlyphFlags; - SplitGlyphFlags( *this, aGlyphId, nGlyphFlags ); - - FT_Int nLoadFlags = mnLoadFlags; - // #i70930# force mono-hinting for monochrome text - nLoadFlags &= ~0xF0000; - nLoadFlags |= FT_LOAD_TARGET_MONO; - - if( mbArtItalic ) - nLoadFlags |= FT_LOAD_NO_BITMAP; - - // for 0/90/180/270 degree fonts enable hinting even if not advisable - // non-hinted and non-antialiased bitmaps just look too ugly - if( (mnCos==0 || mnSin==0) && (mnPrioAutoHint > 0) ) - nLoadFlags &= ~FT_LOAD_NO_HINTING; - - if( mnPrioEmbedded <= mnPrioAutoHint ) - nLoadFlags |= FT_LOAD_NO_BITMAP; - - FT_Error rc = FT_Load_Glyph( maFaceFT, aGlyphId, nLoadFlags ); - - if( rc != FT_Err_Ok ) - return false; - - if (mbArtBold) - FT_GlyphSlot_Embolden(maFaceFT->glyph); - - FT_Glyph pGlyphFT; - rc = FT_Get_Glyph( maFaceFT->glyph, &pGlyphFT ); - if( rc != FT_Err_Ok ) - return false; - - int nAngle = ApplyGlyphTransform( nGlyphFlags, pGlyphFT, true ); - - if( mbArtItalic ) - { - FT_Matrix aMatrix; - aMatrix.xx = aMatrix.yy = 0x10000L; - aMatrix.xy = 0x6000L, aMatrix.yx = 0; - FT_Glyph_Transform( pGlyphFT, &aMatrix, nullptr ); - } - - // Check for zero area bounding boxes as this crashes some versions of FT. - // This also provides a handy short cut as much of the code following - // becomes an expensive nop when a glyph covers no pixels. - FT_BBox cbox; - FT_Glyph_Get_CBox(pGlyphFT, ft_glyph_bbox_unscaled, &cbox); - - if( (cbox.xMax - cbox.xMin) == 0 || (cbox.yMax - cbox.yMin == 0) ) - { - memset(&rRawBitmap, 0, sizeof rRawBitmap); - FT_Done_Glyph( pGlyphFT ); - return true; - } - - if( pGlyphFT->format != FT_GLYPH_FORMAT_BITMAP ) - { - if( pGlyphFT->format == FT_GLYPH_FORMAT_OUTLINE ) - reinterpret_cast<FT_OutlineGlyphRec*>(pGlyphFT)->outline.flags |= FT_OUTLINE_HIGH_PRECISION; - FT_Render_Mode nRenderMode = FT_RENDER_MODE_MONO; - - rc = FT_Glyph_To_Bitmap( &pGlyphFT, nRenderMode, nullptr, true ); - if( rc != FT_Err_Ok ) - { - FT_Done_Glyph( pGlyphFT ); - return false; - } - } - - const FT_BitmapGlyph pBmpGlyphFT = reinterpret_cast<const FT_BitmapGlyph>(pGlyphFT); - // NOTE: autohinting in FT<=2.0.2 miscalculates the offsets below by +-1 - rRawBitmap.mnXOffset = +pBmpGlyphFT->left; - rRawBitmap.mnYOffset = -pBmpGlyphFT->top; - - const FT_Bitmap& rBitmapFT = pBmpGlyphFT->bitmap; - rRawBitmap.mnHeight = rBitmapFT.rows; - rRawBitmap.mnBitCount = 1; - rRawBitmap.mnWidth = rBitmapFT.width; - rRawBitmap.mnScanlineSize = rBitmapFT.pitch; - - const sal_uLong nNeededSize = rRawBitmap.mnScanlineSize * rRawBitmap.mnHeight; - - if( rRawBitmap.mnAllocated < nNeededSize ) - { - rRawBitmap.mnAllocated = 2*nNeededSize; - rRawBitmap.mpBits.reset(new unsigned char[ rRawBitmap.mnAllocated ]); - } - - if (!mbArtBold) - { - memcpy( rRawBitmap.mpBits.get(), rBitmapFT.buffer, nNeededSize ); - } - else - { - memset( rRawBitmap.mpBits.get(), 0, nNeededSize ); - const unsigned char* pSrcLine = rBitmapFT.buffer; - unsigned char* pDstLine = rRawBitmap.mpBits.get(); - for( int h = rRawBitmap.mnHeight; --h >= 0; ) - { - memcpy( pDstLine, pSrcLine, rBitmapFT.pitch ); - pDstLine += rRawBitmap.mnScanlineSize; - pSrcLine += rBitmapFT.pitch; - } - - unsigned char* p = rRawBitmap.mpBits.get(); - for( sal_uLong y=0; y < rRawBitmap.mnHeight; y++ ) - { - unsigned char nLastByte = 0; - for( sal_uLong x=0; x < rRawBitmap.mnScanlineSize; x++ ) - { - unsigned char nTmp = p[x] << 7; - p[x] |= (p[x] >> 1) | nLastByte; - nLastByte = nTmp; - } - p += rRawBitmap.mnScanlineSize; - } - } - - FT_Done_Glyph( pGlyphFT ); - - // special case for 0/90/180/270 degree orientation - switch( nAngle ) - { - case -900: - case +900: - case +1800: - case +2700: - rRawBitmap.Rotate( nAngle ); - break; - } - - return true; -} - -bool ServerFont::GetGlyphBitmap8( sal_GlyphId aGlyphId, RawBitmap& rRawBitmap ) const -{ - FT_Activate_Size( maSizeFT ); - - int nGlyphFlags; - SplitGlyphFlags( *this, aGlyphId, nGlyphFlags ); - - FT_Int nLoadFlags = mnLoadFlags; - - if( mbArtItalic ) - nLoadFlags |= FT_LOAD_NO_BITMAP; - - if( (nGlyphFlags & GF_UNHINTED) || (mnPrioAutoHint < mnPrioAntiAlias) ) - nLoadFlags |= FT_LOAD_NO_HINTING; - - if( mnPrioEmbedded <= mnPrioAntiAlias ) - nLoadFlags |= FT_LOAD_NO_BITMAP; - - FT_Error rc = FT_Load_Glyph( maFaceFT, aGlyphId, nLoadFlags ); - - if( rc != FT_Err_Ok ) - return false; - - if (mbArtBold) - FT_GlyphSlot_Embolden(maFaceFT->glyph); - - FT_Glyph pGlyphFT; - rc = FT_Get_Glyph( maFaceFT->glyph, &pGlyphFT ); - if( rc != FT_Err_Ok ) - return false; - - int nAngle = ApplyGlyphTransform( nGlyphFlags, pGlyphFT, true ); - - if( mbArtItalic ) - { - FT_Matrix aMatrix; - aMatrix.xx = aMatrix.yy = 0x10000L; - aMatrix.xy = 0x6000L, aMatrix.yx = 0; - FT_Glyph_Transform( pGlyphFT, &aMatrix, nullptr ); - } - - if( pGlyphFT->format == FT_GLYPH_FORMAT_OUTLINE ) - reinterpret_cast<FT_OutlineGlyph>(pGlyphFT)->outline.flags |= FT_OUTLINE_HIGH_PRECISION; - - bool bEmbedded = (pGlyphFT->format == FT_GLYPH_FORMAT_BITMAP); - if( !bEmbedded ) - { - rc = FT_Glyph_To_Bitmap( &pGlyphFT, FT_RENDER_MODE_NORMAL, nullptr, true ); - if( rc != FT_Err_Ok ) - { - FT_Done_Glyph( pGlyphFT ); - return false; - } - } - - const FT_BitmapGlyph pBmpGlyphFT = reinterpret_cast<const FT_BitmapGlyph>(pGlyphFT); - rRawBitmap.mnXOffset = +pBmpGlyphFT->left; - rRawBitmap.mnYOffset = -pBmpGlyphFT->top; - - const FT_Bitmap& rBitmapFT = pBmpGlyphFT->bitmap; - rRawBitmap.mnHeight = rBitmapFT.rows; - rRawBitmap.mnWidth = rBitmapFT.width; - rRawBitmap.mnBitCount = 8; - rRawBitmap.mnScanlineSize = bEmbedded ? rBitmapFT.width : rBitmapFT.pitch; - rRawBitmap.mnScanlineSize = (rRawBitmap.mnScanlineSize + 3) & -4; - - const sal_uLong nNeededSize = rRawBitmap.mnScanlineSize * rRawBitmap.mnHeight; - if( rRawBitmap.mnAllocated < nNeededSize ) - { - rRawBitmap.mnAllocated = 2*nNeededSize; - rRawBitmap.mpBits.reset(new unsigned char[ rRawBitmap.mnAllocated ]); - } - - const unsigned char* pSrc = rBitmapFT.buffer; - unsigned char* pDest = rRawBitmap.mpBits.get(); - if( !bEmbedded ) - { - unsigned int x; - for( int y = rRawBitmap.mnHeight; --y >= 0 ; ) - { - // note width is "int" in freetype 2.4.8 and "unsigned int" in 2.5.5 - for (x = 0; x < static_cast<unsigned int>(rBitmapFT.width); ++x) - *(pDest++) = *(pSrc++); - for(; x < rRawBitmap.mnScanlineSize; ++x ) - *(pDest++) = 0; - } - } - else - { - unsigned int x; - for( int y = rRawBitmap.mnHeight; --y >= 0 ; ) - { - unsigned char nSrc = 0; - // note width is "int" in freetype 2.4.8 and "unsigned int" in 2.5.5 - for (x = 0; x < static_cast<unsigned int>(rBitmapFT.width); ++x, nSrc+=nSrc) - { - if( (x & 7) == 0 ) - nSrc = *(pSrc++); - *(pDest++) = (0x7F - nSrc) >> 8; - } - for(; x < rRawBitmap.mnScanlineSize; ++x ) - *(pDest++) = 0; - } - } - - if( !bEmbedded && mbUseGamma ) - { - unsigned char* p = rRawBitmap.mpBits.get(); - for( sal_uLong y=0; y < rRawBitmap.mnHeight; y++ ) - { - for( sal_uLong x=0; x < rRawBitmap.mnWidth; x++ ) - { - p[x] = aGammaTable[ p[x] ]; - } - p += rRawBitmap.mnScanlineSize; - } - } - - FT_Done_Glyph( pGlyphFT ); - - // special case for 0/90/180/270 degree orientation - switch( nAngle ) - { - case -900: - case +900: - case +1800: - case +2700: - rRawBitmap.Rotate( nAngle ); - break; - } - - return true; -} - // determine unicode ranges in font const FontCharMapPtr ServerFont::GetFontCharMap() const diff --git a/vcl/generic/glyphs/gcach_rbmp.cxx b/vcl/generic/glyphs/gcach_rbmp.cxx deleted file mode 100644 index 37f079c7548b..000000000000 --- a/vcl/generic/glyphs/gcach_rbmp.cxx +++ /dev/null @@ -1,251 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * 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/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#include "generic/glyphcache.hxx" -#include <string.h> - -RawBitmap::RawBitmap() - : mnAllocated(0) - , mnWidth(0) - , mnHeight(0) - , mnScanlineSize(0) - , mnBitCount(0) - , mnXOffset(0) - , mnYOffset(0) -{ -} - -RawBitmap::~RawBitmap() -{} - -// used by 90 and 270 degree rotations on 8 bit deep bitmaps -static void ImplRotate8_90( unsigned char* p1, const unsigned char* p2, - int xmax, int ymax, int dx, int dy, int nPad ) -{ - for( int y = ymax; --y >= 0; p2 += dy ) - { - for( int x = xmax; --x >= 0; p2 += dx ) - *(p1++) = *p2; - for( int i = nPad; --i >= 0; ) - *(p1++) = 0; - } -} - -// used by inplace 180 degree rotation on 8 bit deep bitmaps -static void ImplRotate8_180( unsigned char* p1, int xmax, int ymax, int nPad ) -{ - unsigned char* p2 = p1 + ymax * (xmax + nPad); - for( int y = ymax/2; --y >= 0; ) - { - p2 -= nPad; - for( int x = xmax; --x >= 0; ) - { - unsigned char cTmp = *(--p2); - *p2 = *p1; - *(p1++) = cTmp; - } - p1 += nPad; - } - - // reverse middle line - p2 -= nPad; - while( p1 < p2 ) - { - unsigned char cTmp = *(--p2); - *p2 = *p1; - *(p1++) = cTmp; - } -} - -// used by 90 or 270 degree rotations on 1 bit deep bitmaps -static void ImplRotate1_90( unsigned char* p1, const unsigned char* p2, - int xmax, int ymax, int dx, int nShift, int nDeltaShift, int nPad ) -{ - for( int y = ymax; --y >= 0; ) - { - unsigned nTemp = 1; - const unsigned char* p20 = p2; - for( int x = xmax; --x >= 0; p2 += dx ) - { - // build bitwise and store when byte finished - nTemp += nTemp + ((*p2 >> nShift) & 1); - if( nTemp >= 0x100U ) - { - *(p1++) = (unsigned char)nTemp; - nTemp = 1; - } - } - p2 = p20; - - // store left aligned remainder if needed - if( nTemp > 1 ) - { - for(; nTemp < 0x100U; nTemp += nTemp ) ; - *(p1++) = (unsigned char)nTemp; - } - // pad scanline with zeroes - for( int i = nPad; --i >= 0;) - *(p1++) = 0; - - // increase/decrease shift, but keep bound inside 0 to 7 - nShift += nDeltaShift; - if( nShift != (nShift & 7) ) - p2 -= nDeltaShift; - nShift &= 7; - } -} - -// used by 180 degrees rotations on 1 bit deep bitmaps -static void ImplRotate1_180( unsigned char* p1, const unsigned char* p2, - int xmax, int ymax, int nPad ) -{ - --p2; - for( int y = ymax; --y >= 0; ) - { - p2 -= nPad; - - unsigned nTemp = 1; - unsigned nInp = (0x100 + *p2) >> (-xmax & 7); - for( int x = xmax; --x >= 0; ) - { - // build bitwise and store when byte finished - nTemp += nTemp + (nInp & 1); - if( nTemp >= 0x100 ) - { - *(p1++) = (unsigned char)nTemp; - nTemp = 1; - } - // update input byte if needed (and available) - if( (nInp >>= 1) <= 1 && ((y != 0) || (x != 0)) ) - nInp = 0x100 + *(--p2); - } - - // store left aligned remainder if needed - if( nTemp > 1 ) - { - for(; nTemp < 0x100; nTemp += nTemp ) ; - *(p1++) = (unsigned char)nTemp; - } - // scanline pad is already clean - p1 += nPad; - } -} - -bool RawBitmap::Rotate( int nAngle ) -{ - sal_uLong nNewScanlineSize = 0; - sal_uLong nNewHeight = 0; - sal_uLong nNewWidth = 0; - - // do inplace rotation or prepare double buffered rotation - switch( nAngle ) - { - case 0: // nothing to do - case 3600: - return true; - default: // non rectangular angles not allowed - return false; - case 1800: // rotate by 180 degrees - mnXOffset = -(mnXOffset + mnWidth); - mnYOffset = -(mnYOffset + mnHeight); - if( mnBitCount == 8 ) - { - ImplRotate8_180( mpBits.get(), mnWidth, mnHeight, mnScanlineSize-mnWidth ); - return true; - } - nNewWidth = mnWidth; - nNewHeight = mnHeight; - nNewScanlineSize = mnScanlineSize; - break; - case +900: // left by 90 degrees - case -900: - case 2700: // right by 90 degrees - nNewWidth = mnHeight; - nNewHeight = mnWidth; - if( mnBitCount==1 ) - nNewScanlineSize = (nNewWidth + 7) / 8; - else - nNewScanlineSize = (nNewWidth + 3) & -4; - break; - } - - unsigned int nBufSize = nNewHeight * nNewScanlineSize; - unsigned char* pBuf = new unsigned char[ nBufSize ]; - if( !pBuf ) - return false; - - memset( pBuf, 0, nBufSize ); - int i; - - // dispatch non-inplace rotations - switch( nAngle ) - { - case 1800: // rotate by 180 degrees - // we know we only need to deal with 1 bit depth - ImplRotate1_180( pBuf, mpBits.get() + mnHeight * mnScanlineSize, - mnWidth, mnHeight, mnScanlineSize - (mnWidth + 7) / 8 ); - break; - case +900: // rotate left by 90 degrees - i = mnXOffset; - mnXOffset = mnYOffset; - mnYOffset = -nNewHeight - i; - if( mnBitCount == 8 ) - ImplRotate8_90( pBuf, mpBits.get() + mnWidth - 1, - nNewWidth, nNewHeight, +mnScanlineSize, -1-mnHeight*mnScanlineSize, - nNewScanlineSize - nNewWidth ); - else - ImplRotate1_90( pBuf, mpBits.get() + (mnWidth - 1) / 8, - nNewWidth, nNewHeight, +mnScanlineSize, - (-mnWidth & 7), +1, nNewScanlineSize - (nNewWidth + 7) / 8 ); - break; - case 2700: // rotate right by 90 degrees - case -900: - i = mnXOffset; - mnXOffset = -(nNewWidth + mnYOffset); - mnYOffset = i; - if( mnBitCount == 8 ) - ImplRotate8_90( pBuf, mpBits.get() + mnScanlineSize * (mnHeight-1), - nNewWidth, nNewHeight, -mnScanlineSize, +1+mnHeight*mnScanlineSize, - nNewScanlineSize - nNewWidth ); - else - ImplRotate1_90( pBuf, mpBits.get() + mnScanlineSize * (mnHeight-1), - nNewWidth, nNewHeight, -mnScanlineSize, - +7, -1, nNewScanlineSize - (nNewWidth + 7) / 8 ); - break; - } - - mnWidth = nNewWidth; - mnHeight = nNewHeight; - mnScanlineSize = nNewScanlineSize; - - if( nBufSize < mnAllocated ) - { - memcpy( mpBits.get(), pBuf, nBufSize ); - delete[] pBuf; - } - else - { - mpBits.reset(pBuf); - mnAllocated = nBufSize; - } - - return true; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |