src/gui/text/qfontengine_s60.cpp
branchRCL_3
changeset 4 3b1da2848fc7
parent 3 41300fa6a67c
child 5 d3bac044e0f0
equal deleted inserted replaced
3:41300fa6a67c 4:3b1da2848fc7
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     8 **
     8 **
    43 #include "qtextengine_p.h"
    43 #include "qtextengine_p.h"
    44 #include "qglobal.h"
    44 #include "qglobal.h"
    45 #include <private/qapplication_p.h>
    45 #include <private/qapplication_p.h>
    46 #include "qimage.h"
    46 #include "qimage.h"
    47 #include "qt_s60_p.h"
    47 #include "qt_s60_p.h"
    48 #include "qpixmap_s60_p.h"
       
    49 
    48 
    50 #include <e32base.h>
    49 #include <e32base.h>
    51 #include <e32std.h>
    50 #include <e32std.h>
    52 #include <eikenv.h>
    51 #include <eikenv.h>
    53 #include <gdi.h>
    52 #include <gdi.h>
   133 QFontEngineS60::QFontEngineS60(const QFontDef &request, const QFontEngineS60Extensions *extensions)
   132 QFontEngineS60::QFontEngineS60(const QFontDef &request, const QFontEngineS60Extensions *extensions)
   134     : m_extensions(extensions)
   133     : m_extensions(extensions)
   135 {
   134 {
   136     QFontEngine::fontDef = request;
   135     QFontEngine::fontDef = request;
   137     m_fontSizeInPixels = (request.pixelSize >= 0)?
   136     m_fontSizeInPixels = (request.pixelSize >= 0)?
   138         request.pixelSize:pointsToPixels(request.pointSize);
   137             request.pixelSize:pointsToPixels(request.pointSize);
   139         
       
   140     QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock);
       
   141     
       
   142     m_textRenderBitmap = q_check_ptr(new CFbsBitmap());	// CBase derived object needs check on new
       
   143     const TSize bitmapSize(1, 1); // It is just a dummy bitmap that I need to keep the font alive (or maybe not)
       
   144     qt_symbian_throwIfError(m_textRenderBitmap->Create(bitmapSize, EGray256));
       
   145     QT_TRAP_THROWING(m_textRenderBitmapDevice = CFbsBitmapDevice::NewL(m_textRenderBitmap));
       
   146     qt_symbian_throwIfError(m_textRenderBitmapDevice->CreateContext(m_textRenderBitmapGc));
       
   147     cache_cost = sizeof(QFontEngineS60) + bitmapSize.iHeight * bitmapSize.iWidth * 4;
       
   148 
   138 
   149     TFontSpec fontSpec(qt_QString2TPtrC(request.family), m_fontSizeInPixels);
   139     TFontSpec fontSpec(qt_QString2TPtrC(request.family), m_fontSizeInPixels);
   150     fontSpec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
   140     fontSpec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
   151     fontSpec.iFontStyle.SetPosture(request.style == QFont::StyleNormal?EPostureUpright:EPostureItalic);
   141     fontSpec.iFontStyle.SetPosture(request.style == QFont::StyleNormal?EPostureUpright:EPostureItalic);
   152     fontSpec.iFontStyle.SetStrokeWeight(request.weight > QFont::Normal?EStrokeWeightBold:EStrokeWeightNormal);
   142     fontSpec.iFontStyle.SetStrokeWeight(request.weight > QFont::Normal?EStrokeWeightBold:EStrokeWeightNormal);
   153     const TInt errorCode = m_textRenderBitmapDevice->GetNearestFontInPixels(m_font, fontSpec);
   143     const TInt errorCode = S60->screenDevice()->GetNearestFontToDesignHeightInPixels(m_font, fontSpec);
   154     Q_ASSERT(errorCode == 0);
   144     Q_ASSERT(errorCode == 0);
   155     m_textRenderBitmapGc->UseFont(m_font);
   145 
   156     
   146     cache_cost = sizeof(QFontEngineS60);
   157     lock.relock();
       
   158 }
   147 }
   159 
   148 
   160 QFontEngineS60::~QFontEngineS60()
   149 QFontEngineS60::~QFontEngineS60()
   161 {
   150 {
   162     QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock);
   151     S60->screenDevice()->ReleaseFont(m_font);
   163     
       
   164     m_textRenderBitmapGc->DiscardFont();
       
   165     delete m_textRenderBitmapGc;
       
   166     m_textRenderBitmapGc = NULL;
       
   167     m_textRenderBitmapDevice->ReleaseFont(m_font);
       
   168     delete m_textRenderBitmapDevice;
       
   169     m_textRenderBitmapDevice = NULL;
       
   170     delete m_textRenderBitmap;
       
   171     m_textRenderBitmap = NULL;
       
   172     
       
   173     lock.relock();
       
   174 }
   152 }
   175 
   153 
   176 bool QFontEngineS60::stringToCMap(const QChar *characters, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const
   154 bool QFontEngineS60::stringToCMap(const QChar *characters, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const
   177 {
   155 {
   178     if (*nglyphs < len) {
   156     if (*nglyphs < len) {