LCOV - code coverage report
Current view: top level - vcl/unx/generic/gdi - salgdi3.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 327 0.0 %
Date: 2014-11-03 Functions: 0 31 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sal/types.h>
      21             : 
      22             : #include <string.h>
      23             : #include <stdio.h>
      24             : #include <math.h>
      25             : #include <unistd.h>
      26             : #include <fcntl.h>
      27             : #include <fontconfig/fontconfig.h>
      28             : #include <sys/mman.h>
      29             : #include <sys/stat.h>
      30             : #include <sys/types.h>
      31             : 
      32             : #include <basegfx/polygon/b2dpolypolygon.hxx>
      33             : #include <boost/unordered_set.hpp>
      34             : #include <i18nlangtag/mslangid.hxx>
      35             : #include <osl/file.hxx>
      36             : #include <osl/module.hxx>
      37             : #include <rtl/tencinfo.h>
      38             : #include <sal/alloca.h>
      39             : #include <tools/debug.hxx>
      40             : #include <tools/stream.hxx>
      41             : #include <vcl/settings.hxx>
      42             : #include <vcl/sysdata.hxx>
      43             : #include <vcl/jobdata.hxx>
      44             : #include <vcl/printerinfomanager.hxx>
      45             : #include <vcl/svapp.hxx>
      46             : #include <vcl/metric.hxx>
      47             : 
      48             : #include "fontmanager.hxx"
      49             : #include "impfont.hxx"
      50             : #include "gcach_xpeer.hxx"
      51             : #include "generic/genpspgraphics.h"
      52             : #include "generic/printergfx.hxx"
      53             : #include "outdev.h"
      54             : #include "PhysicalFontCollection.hxx"
      55             : #include "PhysicalFontFace.hxx"
      56             : #include "salframe.hxx"
      57             : #include "unx/saldata.hxx"
      58             : #include "unx/saldisp.hxx"
      59             : #include "unx/salgdi.h"
      60             : #include "unx/salunx.h"
      61             : #include "unx/salvd.h"
      62             : #include "xrender_peer.hxx"
      63             : 
      64             : #include <config_graphite.h>
      65             : #if ENABLE_GRAPHITE
      66             : #include <graphite_layout.hxx>
      67             : #include <graphite_serverfont.hxx>
      68             : #endif
      69             : 
      70             : #include <cairo.h>
      71             : #include <cairo-ft.h>
      72             : #include <cairo-xlib.h>
      73             : #include <cairo-xlib-xrender.h>
      74             : 
      75             : struct BOX
      76             : {
      77             :     short x1, x2, y1, y2;
      78             : };
      79             : struct _XRegion
      80             : {
      81             :     long size;
      82             :     long numRects;
      83             :     BOX *rects;
      84             :     BOX extents;
      85             : };
      86             : 
      87             : // X11SalGraphics
      88             : 
      89             : GC
      90           0 : X11SalGraphics::GetFontGC()
      91             : {
      92           0 :     Display *pDisplay = GetXDisplay();
      93             : 
      94           0 :     if( !pFontGC_ )
      95             :     {
      96             :         XGCValues values;
      97           0 :         values.subwindow_mode       = ClipByChildren;
      98           0 :         values.fill_rule            = EvenOddRule;      // Pict import/ Gradient
      99           0 :         values.graphics_exposures   = False;
     100           0 :         values.foreground           = nTextPixel_;
     101             :         pFontGC_ = XCreateGC( pDisplay, hDrawable_,
     102             :                               GCSubwindowMode | GCFillRule
     103             :                               | GCGraphicsExposures | GCForeground,
     104           0 :                               &values );
     105             :     }
     106           0 :     if( !bFontGC_ )
     107             :     {
     108           0 :         XSetForeground( pDisplay, pFontGC_, nTextPixel_ );
     109           0 :         SetClipRegion( pFontGC_ );
     110           0 :         bFontGC_ = true;
     111             :     }
     112             : 
     113           0 :     return pFontGC_;
     114             : }
     115             : 
     116           0 : bool X11SalGraphics::setFont( const FontSelectPattern *pEntry, int nFallbackLevel )
     117             : {
     118             :     // release all no longer needed font resources
     119           0 :     for( int i = nFallbackLevel; i < MAX_FALLBACK; ++i )
     120             :     {
     121           0 :         if( mpServerFont[i] != NULL )
     122             :         {
     123             :             // old server side font is no longer referenced
     124           0 :             GlyphCache::GetInstance().UncacheFont( *mpServerFont[i] );
     125           0 :             mpServerFont[i] = NULL;
     126             :         }
     127             :     }
     128             : 
     129             :     // return early if there is no new font
     130           0 :     if( !pEntry )
     131           0 :         return false;
     132             : 
     133             :     // return early if this is not a valid font for this graphics
     134           0 :     if( !pEntry->mpFontData )
     135           0 :         return false;
     136             : 
     137             :     // handle the request for a non-native X11-font => use the GlyphCache
     138           0 :     ServerFont* pServerFont = GlyphCache::GetInstance().CacheFont( *pEntry );
     139           0 :     if( pServerFont != NULL )
     140             :     {
     141             :         // ignore fonts with e.g. corrupted font files
     142           0 :         if( !pServerFont->TestFont() )
     143             :         {
     144           0 :             GlyphCache::GetInstance().UncacheFont( *pServerFont );
     145           0 :             return false;
     146             :         }
     147             : 
     148             :         // register to use the font
     149           0 :         mpServerFont[ nFallbackLevel ] = pServerFont;
     150             : 
     151             :         // apply font specific-hint settings if needed
     152             :         // TODO: also disable it for reference devices
     153           0 :         if( !bPrinter_ )
     154             :         {
     155           0 :             ImplServerFontEntry* pSFE = static_cast<ImplServerFontEntry*>( pEntry->mpFontEntry );
     156           0 :             pSFE->HandleFontOptions();
     157             :         }
     158             : 
     159           0 :         return true;
     160             :     }
     161             : 
     162           0 :     return false;
     163             : }
     164             : 
     165             : ImplFontOptions* GetFCFontOptions( const ImplFontAttributes& rFontAttributes, int nSize);
     166             : 
     167           0 : void ImplServerFontEntry::HandleFontOptions( void )
     168             : {
     169           0 :     if( !mpServerFont )
     170           0 :         return;
     171           0 :     if( !mbGotFontOptions )
     172             :     {
     173             :         // get and cache the font options
     174           0 :         mbGotFontOptions = true;
     175             :         mpFontOptions.reset(GetFCFontOptions( *maFontSelData.mpFontData,
     176           0 :             maFontSelData.mnHeight ));
     177             :     }
     178             :     // apply the font options
     179           0 :     mpServerFont->SetFontOptions( mpFontOptions );
     180             : }
     181             : 
     182           0 : CairoFontsCache::LRUFonts CairoFontsCache::maLRUFonts;
     183             : int CairoFontsCache::mnRefCount = 0;
     184             : 
     185           0 : CairoFontsCache::CairoFontsCache()
     186             : {
     187           0 :     ++mnRefCount;
     188           0 : }
     189             : 
     190           0 : CairoFontsCache::~CairoFontsCache()
     191             : {
     192           0 :     --mnRefCount;
     193           0 :     if (!mnRefCount && !maLRUFonts.empty())
     194             :     {
     195           0 :         LRUFonts::iterator aEnd = maLRUFonts.end();
     196           0 :         for (LRUFonts::iterator aI = maLRUFonts.begin(); aI != aEnd; ++aI)
     197           0 :             cairo_font_face_destroy((cairo_font_face_t*)aI->first);
     198             :     }
     199           0 : }
     200             : 
     201           0 : void CairoFontsCache::CacheFont(void *pFont, const CairoFontsCache::CacheId &rId)
     202             : {
     203           0 :     maLRUFonts.push_front( std::pair<void*, CairoFontsCache::CacheId>(pFont, rId) );
     204           0 :     if (maLRUFonts.size() > 8)
     205             :     {
     206           0 :         cairo_font_face_destroy((cairo_font_face_t*)maLRUFonts.back().first);
     207           0 :         maLRUFonts.pop_back();
     208             :     }
     209           0 : }
     210             : 
     211           0 : void* CairoFontsCache::FindCachedFont(const CairoFontsCache::CacheId &rId)
     212             : {
     213           0 :     LRUFonts::iterator aEnd = maLRUFonts.end();
     214           0 :     for (LRUFonts::iterator aI = maLRUFonts.begin(); aI != aEnd; ++aI)
     215           0 :         if (aI->second == rId)
     216           0 :             return aI->first;
     217           0 :     return NULL;
     218             : }
     219             : 
     220             : namespace
     221             : {
     222           0 :     bool hasRotation(int nRotation)
     223             :     {
     224           0 :       return nRotation != 0;
     225             :     }
     226             : 
     227           0 :     double toRadian(int nDegree10th)
     228             :     {
     229           0 :         return (3600 - (nDegree10th)) * M_PI / 1800.0;
     230             :     }
     231             : }
     232             : 
     233           0 : void X11SalGraphics::DrawServerFontLayout( const ServerFontLayout& rLayout )
     234             : {
     235           0 :     std::vector<cairo_glyph_t> cairo_glyphs;
     236           0 :     std::vector<int> glyph_extrarotation;
     237           0 :     cairo_glyphs.reserve( 256 );
     238             : 
     239           0 :     Point aPos;
     240             :     sal_GlyphId aGlyphId;
     241           0 :     for( int nStart = 0; rLayout.GetNextGlyphs( 1, &aGlyphId, aPos, nStart ); )
     242             :     {
     243             :         cairo_glyph_t aGlyph;
     244           0 :         aGlyph.index = aGlyphId & GF_IDXMASK;
     245           0 :         aGlyph.x = aPos.X();
     246           0 :         aGlyph.y = aPos.Y();
     247           0 :         cairo_glyphs.push_back(aGlyph);
     248             : 
     249           0 :         switch (aGlyphId & GF_ROTMASK)
     250             :         {
     251             :             case GF_ROTL:    // left
     252           0 :                 glyph_extrarotation.push_back(1);
     253           0 :                 break;
     254             :             case GF_ROTR:    // right
     255           0 :                 glyph_extrarotation.push_back(-1);
     256           0 :                 break;
     257             :             default:
     258           0 :                 glyph_extrarotation.push_back(0);
     259           0 :                 break;
     260             :         }
     261             :     }
     262             : 
     263           0 :     if (cairo_glyphs.empty())
     264           0 :         return;
     265             : 
     266             :     // find a XRenderPictFormat compatible with the Drawable
     267           0 :     XRenderPictFormat* pVisualFormat = GetXRenderFormat();
     268             : 
     269           0 :     Display* pDisplay = GetXDisplay();
     270             : 
     271             :     cairo_surface_t *surface;
     272             : 
     273           0 :     if (pVisualFormat)
     274             :     {
     275             :         surface = cairo_xlib_surface_create_with_xrender_format (
     276             :                         pDisplay, hDrawable_,
     277           0 :                         ScreenOfDisplay(pDisplay, m_nXScreen.getXScreen()),
     278           0 :                         pVisualFormat, SAL_MAX_INT16, SAL_MAX_INT16);
     279             :     }
     280             :     else
     281             :     {
     282             :         surface = cairo_xlib_surface_create(pDisplay, hDrawable_,
     283           0 :             GetVisual().visual, SAL_MAX_INT16, SAL_MAX_INT16);
     284             :     }
     285             : 
     286             :     DBG_ASSERT( surface!=NULL, "no cairo surface for text" );
     287           0 :     if( !surface )
     288           0 :         return;
     289             : 
     290             :     /*
     291             :      * It might be ideal to cache surface and cairo context between calls and
     292             :      * only destroy it when the drawable changes, but to do that we need to at
     293             :      * least change the SalFrame etc impls to dtor the SalGraphics *before* the
     294             :      * destruction of the windows they reference
     295             :     */
     296           0 :     cairo_t *cr = cairo_create(surface);
     297           0 :     cairo_surface_destroy(surface);
     298             : 
     299           0 :     if (const void *pOptions = Application::GetSettings().GetStyleSettings().GetCairoFontOptions())
     300           0 :         cairo_set_font_options(cr, static_cast<const cairo_font_options_t*>(pOptions));
     301             : 
     302           0 :     if( mpClipRegion && !XEmptyRegion( mpClipRegion ) )
     303             :     {
     304           0 :         for (long i = 0; i < mpClipRegion->numRects; ++i)
     305             :         {
     306             :             cairo_rectangle(cr,
     307           0 :                 mpClipRegion->rects[i].x1,
     308           0 :                 mpClipRegion->rects[i].y1,
     309           0 :                 mpClipRegion->rects[i].x2 - mpClipRegion->rects[i].x1,
     310           0 :                 mpClipRegion->rects[i].y2 - mpClipRegion->rects[i].y1);
     311             :         }
     312           0 :         cairo_clip(cr);
     313             :     }
     314             : 
     315             :     cairo_set_source_rgb(cr,
     316           0 :         SALCOLOR_RED(nTextColor_)/255.0,
     317           0 :         SALCOLOR_GREEN(nTextColor_)/255.0,
     318           0 :         SALCOLOR_BLUE(nTextColor_)/255.0);
     319             : 
     320           0 :     ServerFont& rFont = rLayout.GetServerFont();
     321             : 
     322           0 :     FT_Face aFace = rFont.GetFtFace();
     323             :     CairoFontsCache::CacheId aId;
     324           0 :     aId.maFace = aFace;
     325           0 :     aId.mpOptions = rFont.GetFontOptions().get();
     326           0 :     aId.mbEmbolden = rFont.NeedsArtificialBold();
     327             : 
     328             :     cairo_matrix_t m;
     329           0 :     const FontSelectPattern& rFSD = rFont.GetFontSelData();
     330           0 :     int nHeight = rFSD.mnHeight;
     331           0 :     int nWidth = rFSD.mnWidth ? rFSD.mnWidth : nHeight;
     332             : 
     333           0 :     std::vector<int>::const_iterator aEnd = glyph_extrarotation.end();
     334           0 :     std::vector<int>::const_iterator aStart = glyph_extrarotation.begin();
     335           0 :     std::vector<int>::const_iterator aI = aStart;
     336           0 :     while (aI != aEnd)
     337             :     {
     338           0 :         int nGlyphRotation = *aI;
     339             : 
     340           0 :         std::vector<int>::const_iterator aNext = std::find_if(aI+1, aEnd, hasRotation);
     341             : 
     342           0 :         size_t nStartIndex = std::distance(aStart, aI);
     343           0 :         size_t nLen = std::distance(aI, aNext);
     344             : 
     345           0 :         aId.mbVerticalMetrics = nGlyphRotation != 0.0;
     346           0 :         cairo_font_face_t* font_face = (cairo_font_face_t*)CairoFontsCache::FindCachedFont(aId);
     347           0 :         if (!font_face)
     348             :         {
     349           0 :             const ImplFontOptions *pOptions = rFont.GetFontOptions().get();
     350           0 :             void *pPattern = pOptions ? pOptions->GetPattern(aFace, aId.mbEmbolden, aId.mbVerticalMetrics) : NULL;
     351           0 :             if (pPattern)
     352           0 :                 font_face = cairo_ft_font_face_create_for_pattern(reinterpret_cast<FcPattern*>(pPattern));
     353           0 :             if (!font_face)
     354           0 :                 font_face = cairo_ft_font_face_create_for_ft_face(reinterpret_cast<FT_Face>(aFace), rFont.GetLoadFlags());
     355           0 :             CairoFontsCache::CacheFont(font_face, aId);
     356             :         }
     357           0 :         cairo_set_font_face(cr, font_face);
     358             : 
     359           0 :         cairo_set_font_size(cr, nHeight);
     360             : 
     361           0 :         cairo_matrix_init_identity(&m);
     362             : 
     363           0 :         if (rLayout.GetOrientation())
     364           0 :             cairo_matrix_rotate(&m, toRadian(rLayout.GetOrientation()));
     365             : 
     366           0 :         cairo_matrix_scale(&m, nWidth, nHeight);
     367             : 
     368           0 :         if (nGlyphRotation)
     369             :         {
     370           0 :             cairo_matrix_rotate(&m, toRadian(nGlyphRotation*900));
     371             : 
     372             :             cairo_matrix_t em_square;
     373           0 :             cairo_matrix_init_identity(&em_square);
     374           0 :             cairo_get_matrix(cr, &em_square);
     375             : 
     376             :             cairo_matrix_scale(&em_square, aFace->units_per_EM,
     377           0 :                 aFace->units_per_EM);
     378           0 :             cairo_set_matrix(cr, &em_square);
     379             : 
     380             :             cairo_font_extents_t font_extents;
     381           0 :             cairo_font_extents(cr, &font_extents);
     382             : 
     383           0 :             cairo_matrix_init_identity(&em_square);
     384           0 :             cairo_set_matrix(cr, &em_square);
     385             : 
     386             :             //gives the same positions as pre-cairo conversion, but I don't
     387             :             //like them
     388           0 :             double xdiff = 0.0;
     389           0 :             double ydiff = 0.0;
     390           0 :             if (nGlyphRotation == 1)
     391             :             {
     392           0 :                 ydiff = font_extents.ascent/nHeight;
     393           0 :                 xdiff = -font_extents.descent/nHeight;
     394             :             }
     395           0 :             else if (nGlyphRotation == -1)
     396             :             {
     397             :                 cairo_text_extents_t text_extents;
     398           0 :                 cairo_glyph_extents(cr, &cairo_glyphs[nStartIndex], nLen,
     399           0 :                     &text_extents);
     400             : 
     401           0 :                 xdiff = -text_extents.x_advance/nHeight;
     402             :                 //to restore an apparent bug in the original X11 impl, replace
     403             :                 //nHeight with nWidth below
     404           0 :                 xdiff += font_extents.descent/nHeight;
     405             :             }
     406           0 :             cairo_matrix_translate(&m, xdiff, ydiff);
     407             :         }
     408             : 
     409           0 :         if (rFont.NeedsArtificialItalic())
     410             :         {
     411             :             cairo_matrix_t shear;
     412           0 :             cairo_matrix_init_identity(&shear);
     413           0 :             shear.xy = -shear.xx * 0x6000L / 0x10000L;
     414           0 :             cairo_matrix_multiply(&m, &shear, &m);
     415             :         }
     416             : 
     417           0 :         cairo_set_font_matrix(cr, &m);
     418           0 :         cairo_show_glyphs(cr, &cairo_glyphs[nStartIndex], nLen);
     419             : 
     420             : #if OSL_DEBUG_LEVEL > 2
     421             :         //draw origin
     422             :         cairo_save (cr);
     423             :         cairo_rectangle (cr, cairo_glyphs[nStartIndex].x, cairo_glyphs[nStartIndex].y, 5, 5);
     424             :         cairo_set_source_rgba (cr, 1, 0, 0, 0.80);
     425             :         cairo_fill (cr);
     426             :         cairo_restore (cr);
     427             : #endif
     428             : 
     429           0 :         aI = aNext;
     430             :     }
     431             : 
     432           0 :     cairo_destroy(cr);
     433             : }
     434             : 
     435           0 : const FontCharMapPtr X11SalGraphics::GetFontCharMap() const
     436             : {
     437           0 :     if( !mpServerFont[0] )
     438           0 :         return NULL;
     439             : 
     440           0 :     const FontCharMapPtr pFCMap = mpServerFont[0]->GetFontCharMap();
     441           0 :     return pFCMap;
     442             : }
     443             : 
     444           0 : bool X11SalGraphics::GetFontCapabilities(vcl::FontCapabilities &rGetImplFontCapabilities) const
     445             : {
     446           0 :     if (!mpServerFont[0])
     447           0 :         return false;
     448           0 :     return mpServerFont[0]->GetFontCapabilities(rGetImplFontCapabilities);
     449             : }
     450             : 
     451             : // SalGraphics
     452             : 
     453           0 : sal_uInt16 X11SalGraphics::SetFont( FontSelectPattern *pEntry, int nFallbackLevel )
     454             : {
     455           0 :     sal_uInt16 nRetVal = 0;
     456           0 :     if( !setFont( pEntry, nFallbackLevel ) )
     457           0 :         nRetVal |= SAL_SETFONT_BADFONT;
     458           0 :     if( bPrinter_ || (mpServerFont[ nFallbackLevel ] != NULL) )
     459           0 :         nRetVal |= SAL_SETFONT_USEDRAWTEXTARRAY;
     460           0 :     return nRetVal;
     461             : }
     462             : 
     463             : void
     464           0 : X11SalGraphics::SetTextColor( SalColor nSalColor )
     465             : {
     466           0 :     if( nTextColor_ != nSalColor )
     467             :     {
     468           0 :         nTextColor_     = nSalColor;
     469           0 :         nTextPixel_     = GetPixel( nSalColor );
     470           0 :         bFontGC_        = false;
     471             :     }
     472           0 : }
     473             : 
     474           0 : bool X11SalGraphics::AddTempDevFont( PhysicalFontCollection* pFontCollection,
     475             :                                      const OUString& rFileURL,
     476             :                                      const OUString& rFontName )
     477             : {
     478             :     // inform PSP font manager
     479           0 :     OUString aUSystemPath;
     480           0 :     OSL_VERIFY( !osl::FileBase::getSystemPathFromFileURL( rFileURL, aUSystemPath ) );
     481           0 :     rtl_TextEncoding aEncoding = osl_getThreadTextEncoding();
     482           0 :     OString aOFileName( OUStringToOString( aUSystemPath, aEncoding ) );
     483           0 :     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
     484           0 :     std::vector<psp::fontID> aFontIds = rMgr.addFontFile( aOFileName );
     485           0 :     if( aFontIds.empty() )
     486           0 :         return false;
     487             : 
     488           0 :     GlyphCache& rGC = X11GlyphCache::GetInstance();
     489             : 
     490           0 :     for (std::vector<psp::fontID>::iterator aI = aFontIds.begin(), aEnd = aFontIds.end(); aI != aEnd; ++aI)
     491             :     {
     492             :         // prepare font data
     493           0 :         psp::FastPrintFontInfo aInfo;
     494           0 :         rMgr.getFontFastInfo( *aI, aInfo );
     495           0 :         aInfo.m_aFamilyName = rFontName;
     496             : 
     497             :         // inform glyph cache of new font
     498           0 :         ImplDevFontAttributes aDFA = GenPspGraphics::Info2DevFontAttributes( aInfo );
     499           0 :         aDFA.mnQuality += 5800;
     500             : 
     501           0 :         int nFaceNum = rMgr.getFontFaceNumber( aInfo.m_nID );
     502             : 
     503           0 :         const OString& rFileName = rMgr.getFontFileSysPath( aInfo.m_nID );
     504           0 :         rGC.AddFontFile( rFileName, nFaceNum, aInfo.m_nID, aDFA );
     505           0 :     }
     506             : 
     507             :     // announce new font to device's font list
     508           0 :     rGC.AnnounceFonts( pFontCollection );
     509           0 :     return true;
     510             : }
     511             : 
     512           0 : void X11SalGraphics::ClearDevFontCache()
     513             : {
     514           0 :     X11GlyphCache& rGC = X11GlyphCache::GetInstance();
     515           0 :     rGC.ClearFontCache();
     516           0 : }
     517             : 
     518           0 : void X11SalGraphics::GetDevFontList( PhysicalFontCollection* pFontCollection )
     519             : {
     520             :     // prepare the GlyphCache using psprint's font infos
     521           0 :     X11GlyphCache& rGC = X11GlyphCache::GetInstance();
     522             : 
     523           0 :     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
     524           0 :     ::std::list< psp::fontID > aList;
     525           0 :     ::std::list< psp::fontID >::iterator it;
     526           0 :     psp::FastPrintFontInfo aInfo;
     527           0 :     rMgr.getFontList( aList );
     528           0 :     for( it = aList.begin(); it != aList.end(); ++it )
     529             :     {
     530           0 :         if( !rMgr.getFontFastInfo( *it, aInfo ) )
     531           0 :             continue;
     532             : 
     533             :         // normalize face number to the GlyphCache
     534           0 :         int nFaceNum = rMgr.getFontFaceNumber( aInfo.m_nID );
     535             : 
     536             :         // inform GlyphCache about this font provided by the PsPrint subsystem
     537           0 :         ImplDevFontAttributes aDFA = GenPspGraphics::Info2DevFontAttributes( aInfo );
     538           0 :         aDFA.mnQuality += 4096;
     539           0 :         const OString& rFileName = rMgr.getFontFileSysPath( aInfo.m_nID );
     540           0 :         rGC.AddFontFile( rFileName, nFaceNum, aInfo.m_nID, aDFA );
     541           0 :    }
     542             : 
     543             :     // announce glyphcache fonts
     544           0 :     rGC.AnnounceFonts( pFontCollection );
     545             : 
     546             :     // register platform specific font substitutions if available
     547           0 :     SalGenericInstance::RegisterFontSubstitutors( pFontCollection );
     548             : 
     549           0 :     ImplGetSVData()->maGDIData.mbNativeFontConfig = true;
     550           0 : }
     551             : 
     552           0 : void cairosubcallback(void* pPattern)
     553             : {
     554           0 :     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
     555           0 :     const void* pFontOptions = rStyleSettings.GetCairoFontOptions();
     556           0 :     if( !pFontOptions )
     557           0 :         return;
     558             :     cairo_ft_font_options_substitute(static_cast<const cairo_font_options_t*>(pFontOptions),
     559           0 :         static_cast<FcPattern*>(pPattern));
     560             : }
     561             : 
     562           0 : ImplFontOptions* GetFCFontOptions( const ImplFontAttributes& rFontAttributes, int nSize)
     563             : {
     564           0 :     psp::FastPrintFontInfo aInfo;
     565             : 
     566           0 :     aInfo.m_aFamilyName = rFontAttributes.GetFamilyName();
     567           0 :     aInfo.m_eItalic = rFontAttributes.GetSlant();
     568           0 :     aInfo.m_eWeight = rFontAttributes.GetWeight();
     569           0 :     aInfo.m_eWidth = rFontAttributes.GetWidthType();
     570             : 
     571           0 :     const psp::PrintFontManager& rPFM = psp::PrintFontManager::get();
     572           0 :     return rPFM.getFontOptions(aInfo, nSize, cairosubcallback);
     573             : }
     574             : 
     575             : void
     576           0 : X11SalGraphics::GetFontMetric( ImplFontMetricData *pMetric, int nFallbackLevel )
     577             : {
     578           0 :     if( nFallbackLevel >= MAX_FALLBACK )
     579           0 :         return;
     580             : 
     581           0 :     if( mpServerFont[nFallbackLevel] != NULL )
     582             :     {
     583             :         long rDummyFactor;
     584           0 :         mpServerFont[nFallbackLevel]->FetchFontMetric( *pMetric, rDummyFactor );
     585             :     }
     586             : }
     587             : 
     588           0 : bool X11SalGraphics::GetGlyphBoundRect( sal_GlyphId aGlyphId, Rectangle& rRect )
     589             : {
     590           0 :     const int nLevel = aGlyphId >> GF_FONTSHIFT;
     591           0 :     if( nLevel >= MAX_FALLBACK )
     592           0 :         return false;
     593             : 
     594           0 :     ServerFont* pSF = mpServerFont[ nLevel ];
     595           0 :     if( !pSF )
     596           0 :         return false;
     597             : 
     598           0 :     aGlyphId &= GF_IDXMASK;
     599           0 :     const GlyphMetric& rGM = pSF->GetGlyphMetric(aGlyphId);
     600           0 :     Rectangle aRect( rGM.GetOffset(), rGM.GetSize() );
     601             : 
     602           0 :     if ( pSF->mnCos != 0x10000 && pSF->mnSin != 0 )
     603             :     {
     604           0 :         double nCos = pSF->mnCos / 65536.0;
     605           0 :         double nSin = pSF->mnSin / 65536.0;
     606           0 :         rRect.Left() =  nCos*aRect.Left() + nSin*aRect.Top();
     607           0 :         rRect.Top()  = -nSin*aRect.Left() - nCos*aRect.Top();
     608             : 
     609           0 :         rRect.Right()  =  nCos*aRect.Right() + nSin*aRect.Bottom();
     610           0 :         rRect.Bottom() = -nSin*aRect.Right() - nCos*aRect.Bottom();
     611             :     }
     612             :     else
     613           0 :         rRect = aRect;
     614             : 
     615           0 :     return true;
     616             : }
     617             : 
     618           0 : bool X11SalGraphics::GetGlyphOutline( sal_GlyphId aGlyphId,
     619             :     ::basegfx::B2DPolyPolygon& rPolyPoly )
     620             : {
     621           0 :     const int nLevel = aGlyphId >> GF_FONTSHIFT;
     622           0 :     if( nLevel >= MAX_FALLBACK )
     623           0 :         return false;
     624             : 
     625           0 :     ServerFont* pSF = mpServerFont[ nLevel ];
     626           0 :     if( !pSF )
     627           0 :         return false;
     628             : 
     629           0 :     aGlyphId &= GF_IDXMASK;
     630           0 :     if( pSF->GetGlyphOutline( aGlyphId, rPolyPoly ) )
     631           0 :         return true;
     632             : 
     633           0 :     return false;
     634             : }
     635             : 
     636           0 : SalLayout* X11SalGraphics::GetTextLayout( ImplLayoutArgs& rArgs, int nFallbackLevel )
     637             : {
     638           0 :     SalLayout* pLayout = NULL;
     639             : 
     640           0 :     if( mpServerFont[ nFallbackLevel ]
     641           0 :     && !(rArgs.mnFlags & SAL_LAYOUT_DISABLE_GLYPH_PROCESSING) )
     642             :     {
     643             : #if ENABLE_GRAPHITE
     644             :         // Is this a Graphite font?
     645           0 :         if (!bDisableGraphite_ &&
     646           0 :             GraphiteServerFontLayout::IsGraphiteEnabledFont(*mpServerFont[nFallbackLevel]))
     647             :         {
     648           0 :             pLayout = new GraphiteServerFontLayout(*mpServerFont[nFallbackLevel]);
     649             :         }
     650             :         else
     651             : #endif
     652           0 :             pLayout = new ServerFontLayout( *mpServerFont[ nFallbackLevel ] );
     653             :     }
     654             : 
     655           0 :     return pLayout;
     656             : }
     657             : 
     658           0 : SystemFontData X11SalGraphics::GetSysFontData( int nFallbacklevel ) const
     659             : {
     660           0 :     SystemFontData aSysFontData;
     661           0 :     aSysFontData.nSize = sizeof( SystemFontData );
     662           0 :     aSysFontData.nFontId = 0;
     663             : 
     664           0 :     if (nFallbacklevel >= MAX_FALLBACK) nFallbacklevel = MAX_FALLBACK - 1;
     665           0 :     if (nFallbacklevel < 0 ) nFallbacklevel = 0;
     666             : 
     667           0 :     if (mpServerFont[nFallbacklevel] != NULL)
     668             :     {
     669           0 :         ServerFont* rFont = mpServerFont[nFallbacklevel];
     670           0 :         aSysFontData.nFontId = rFont->GetFtFace();
     671           0 :         aSysFontData.nFontFlags = rFont->GetLoadFlags();
     672           0 :         aSysFontData.bFakeBold = rFont->NeedsArtificialBold();
     673           0 :         aSysFontData.bFakeItalic = rFont->NeedsArtificialItalic();
     674           0 :         aSysFontData.bAntialias = rFont->GetAntialiasAdvice();
     675           0 :         aSysFontData.bVerticalCharacterType = rFont->GetFontSelData().mbVertical;
     676             :     }
     677             : 
     678           0 :     return aSysFontData;
     679             : }
     680             : 
     681           0 : bool X11SalGraphics::CreateFontSubset(
     682             :                                    const OUString& rToFile,
     683             :                                    const PhysicalFontFace* pFont,
     684             :                                    sal_GlyphId* pGlyphIds,
     685             :                                    sal_uInt8* pEncoding,
     686             :                                    sal_Int32* pWidths,
     687             :                                    int nGlyphCount,
     688             :                                    FontSubsetInfo& rInfo
     689             :                                    )
     690             : {
     691             :     // in this context the pFont->GetFontId() is a valid PSP
     692             :     // font since they are the only ones left after the PDF
     693             :     // export has filtered its list of subsettable fonts (for
     694             :     // which this method was created). The correct way would
     695             :     // be to have the GlyphCache search for the PhysicalFontFace pFont
     696           0 :     psp::fontID aFont = pFont->GetFontId();
     697             : 
     698           0 :     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
     699             :     bool bSuccess = rMgr.createFontSubset( rInfo,
     700             :                                  aFont,
     701             :                                  rToFile,
     702             :                                  pGlyphIds,
     703             :                                  pEncoding,
     704             :                                  pWidths,
     705           0 :                                  nGlyphCount );
     706           0 :     return bSuccess;
     707             : }
     708             : 
     709           0 : const void* X11SalGraphics::GetEmbedFontData( const PhysicalFontFace* pFont, const sal_Ucs* pUnicodes, sal_Int32* pWidths, FontSubsetInfo& rInfo, long* pDataLen )
     710             : {
     711             :     // in this context the pFont->GetFontId() is a valid PSP
     712             :     // font since they are the only ones left after the PDF
     713             :     // export has filtered its list of subsettable fonts (for
     714             :     // which this method was created). The correct way would
     715             :     // be to have the GlyphCache search for the PhysicalFontFace pFont
     716           0 :     psp::fontID aFont = pFont->GetFontId();
     717           0 :     return GenPspGraphics::DoGetEmbedFontData( aFont, pUnicodes, pWidths, rInfo, pDataLen );
     718             : }
     719             : 
     720           0 : void X11SalGraphics::FreeEmbedFontData( const void* pData, long nLen )
     721             : {
     722           0 :     GenPspGraphics::DoFreeEmbedFontData( pData, nLen );
     723           0 : }
     724             : 
     725           0 : const Ucs2SIntMap* X11SalGraphics::GetFontEncodingVector( const PhysicalFontFace* pFont, const Ucs2OStrMap** pNonEncoded )
     726             : {
     727             :     // in this context the pFont->GetFontId() is a valid PSP
     728             :     // font since they are the only ones left after the PDF
     729             :     // export has filtered its list of subsettable fonts (for
     730             :     // which this method was created). The correct way would
     731             :     // be to have the GlyphCache search for the PhysicalFontFace pFont
     732           0 :     psp::fontID aFont = pFont->GetFontId();
     733           0 :     return GenPspGraphics::DoGetFontEncodingVector( aFont, pNonEncoded );
     734             : }
     735             : 
     736           0 : void X11SalGraphics::GetGlyphWidths( const PhysicalFontFace* pFont,
     737             :                                    bool bVertical,
     738             :                                    Int32Vector& rWidths,
     739             :                                    Ucs2UIntMap& rUnicodeEnc )
     740             : {
     741             :     // in this context the pFont->GetFontId() is a valid PSP
     742             :     // font since they are the only ones left after the PDF
     743             :     // export has filtered its list of subsettable fonts (for
     744             :     // which this method was created). The correct way would
     745             :     // be to have the GlyphCache search for the PhysicalFontFace pFont
     746           0 :     psp::fontID aFont = pFont->GetFontId();
     747           0 :     GenPspGraphics::DoGetGlyphWidths( aFont, bVertical, rWidths, rUnicodeEnc );
     748           0 : }
     749             : 
     750             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10