javauis/eswt_qt/org.eclipse.swt/Eclipse_SWT_PI/qt/library/swtfontcache.cpp
changeset 76 4ad59aaee882
parent 21 2a9601315dfc
equal deleted inserted replaced
69:773449708c84 76:4ad59aaee882
     1 /*******************************************************************************
     1 /*******************************************************************************
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2009, 2010 Nokia Corporation and/or its subsidiary(-ies).
     3  * All rights reserved. This program and the accompanying materials
     3  * All rights reserved. This program and the accompanying materials
     4  * are made available under the terms of the Eclipse Public License v1.0
     4  * are made available under the terms of the Eclipse Public License v1.0
     5  * which accompanies this distribution, and is available at
     5  * which accompanies this distribution, and is available at
     6  * http://www.eclipse.org/legal/epl-v10.html
     6  * http://www.eclipse.org/legal/epl-v10.html
     7  *
     7  *
    17 
    17 
    18 namespace Java { namespace eSWT {
    18 namespace Java { namespace eSWT {
    19 
    19 
    20 SwtFontCache::SwtFontCache() : mFonts(NULL), mSize(0), mCount(0)
    20 SwtFontCache::SwtFontCache() : mFonts(NULL), mSize(0), mCount(0)
    21 {
    21 {
    22     SWT_LOG_JNI_CALL();
    22     SWT_LOG_FUNC_CALL();
    23 }
    23 }
    24 
    24 
    25 SwtFontCache::~SwtFontCache()
    25 SwtFontCache::~SwtFontCache()
    26 {
    26 {
    27     SWT_LOG_JNI_CALL();
    27     SWT_LOG_FUNC_CALL();
    28         
    28         
    29     for(int i = 0; i < mCount; ++i)
    29     for(int i = 0; i < mCount; ++i)
    30     {
    30     {
    31         delete mFonts[i];
    31         delete mFonts[i];
    32         mFonts[i] = NULL;
    32         mFonts[i] = NULL;
    35     mFonts = NULL;
    35     mFonts = NULL;
    36 }
    36 }
    37 
    37 
    38 QFont* SwtFontCache::cache(QFont* aFont)
    38 QFont* SwtFontCache::cache(QFont* aFont)
    39 {
    39 {
    40     SWT_LOG_JNI_CALL();
    40     SWT_LOG_FUNC_CALL();
    41     
    41     
    42     QFont* cached = findEqual( aFont );
    42     QFont* cached = findEqual( aFont );
    43     if( cached )
    43     if( cached )
    44     {
    44     {
    45         delete aFont;
    45         delete aFont;
    53     return cached;
    53     return cached;
    54 }
    54 }
    55 
    55 
    56 bool SwtFontCache::isCached(const QFont* const aFont)
    56 bool SwtFontCache::isCached(const QFont* const aFont)
    57 {
    57 {
    58     SWT_LOG_JNI_CALL();
    58     SWT_LOG_FUNC_CALL();
    59     
    59     
    60     for(int i = 0; i < mCount; ++i)
    60     for(int i = 0; i < mCount; ++i)
    61     {
    61     {
    62         if(mFonts[i] == aFont)
    62         if(mFonts[i] == aFont)
    63         {
    63         {
    67     return false;
    67     return false;
    68 }
    68 }
    69 
    69 
    70 QFont* SwtFontCache::findEqual(QFont* aFont)
    70 QFont* SwtFontCache::findEqual(QFont* aFont)
    71 {
    71 {
    72     SWT_LOG_JNI_CALL();
    72     SWT_LOG_FUNC_CALL();
    73 
    73 
    74     if(aFont == NULL)
    74     if(aFont == NULL)
    75     {
    75     {
    76         return NULL;
    76         return NULL;
    77     }
    77     }
    85     return NULL;
    85     return NULL;
    86 }
    86 }
    87 
    87 
    88 void SwtFontCache::add(QFont* aFont)
    88 void SwtFontCache::add(QFont* aFont)
    89 {
    89 {
    90     SWT_LOG_JNI_CALL();
    90     SWT_LOG_FUNC_CALL();
    91 
    91 
    92     if(mSize == mCount)
    92     if(mSize == mCount)
    93     {
    93     {
    94         const int newSize = mSize + SWTFONTCACHE_GRANULARITY;
    94         const int newSize = mSize + SWTFONTCACHE_GRANULARITY;
    95         QFont** bigger = new QFont* [newSize];
    95         QFont** bigger = new QFont* [newSize];