home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / cvffc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  9.3 KB  |  293 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /* , 1997 */
  19.  
  20. //--------------------------------------------------------------------------------------------------------
  21. //    Author: Frank Tang ftang@netscape.com x2913
  22. //
  23. //    Virtual Font Cacahe used for Unicode rendering 
  24. //--------------------------------------------------------------------------------------------------------
  25. #include "stdafx.h"
  26. #include "cvffc.h"
  27. //------------------------------------------------------------------------------------------------
  28. //
  29. //    CVirtualFontFontCache
  30. //
  31. //------------------------------------------------------------------------------------------------
  32. CMapWordToOb* CVirtualFontFontCache::m_cache = NULL;
  33. //#ifdef netscape_font_module
  34. CMapWordToOb* CVirtualFontFontCache::m_Cyacache = NULL;
  35. //#endif    //netscape_font_module
  36. void    CVirtualFontFontCache::Init()
  37. {
  38.     CVirtualFontFontCache::m_cache = NULL;
  39.     // CVirtualFontFontCache::m_Cyacache = NULL;
  40. }
  41. void    CVirtualFontFontCache::Exit()
  42. {
  43.     CVirtualFontFontCache::Reset();
  44. }
  45. //------------------------------------------------------------------------------------------------
  46. //
  47. //    CVirtualFontFontCache::Get
  48. //
  49. //------------------------------------------------------------------------------------------------
  50. #define STYLEKEY(f,b,i,u)    ( ((f) ? 8 : 0) | ((b) ? 4 : 0) | ((i) ? 2 : 0) | ((u) ? 1 : 0) )
  51. BOOL CVirtualFontFontCache::Get(int16 encoding, int size, BOOL fixed, BOOL bold, BOOL italic, BOOL underline, CFont*& pFont )
  52. {
  53.     if(CVirtualFontFontCache::m_cache)
  54.     {
  55.         CMapWordToOb*    pSizecache;
  56.         if(CVirtualFontFontCache::m_cache->Lookup(encoding, (CObject*&)pSizecache))
  57.         {
  58.             CMapWordToOb*    pStylecache;
  59.             if(pSizecache->Lookup(size, (CObject*&)pStylecache))
  60.             {
  61.                 BOOL ret = pStylecache->Lookup( STYLEKEY(fixed,bold,italic,underline), (CObject*&)pFont);
  62.                 return ret;
  63.             }
  64.         }
  65.     }
  66.     return FALSE;
  67. }
  68.  
  69. //#ifdef netscape_font_module
  70. BOOL CVirtualFontFontCache::Get(int16 encoding, int size, BOOL fixed, BOOL bold, 
  71.                                 BOOL italic, BOOL underline, CyaFont*& pFont )
  72. {
  73.     if(CVirtualFontFontCache::m_Cyacache)
  74.     {
  75.         CMapWordToOb*    pSizecache;
  76.         if(CVirtualFontFontCache::m_Cyacache->Lookup(encoding, (CObject*&)pSizecache))
  77.         {
  78.             CMapWordToOb*    pStylecache;
  79.             if(pSizecache->Lookup(size, (CObject*&)pStylecache))
  80.             {
  81.                 BOOL ret = pStylecache->Lookup( STYLEKEY(fixed,bold,italic,underline), (CObject*&)pFont);
  82.                 return ret;
  83.             }
  84.         }
  85.     }
  86.     return FALSE;
  87. }
  88. //#endif  //netscape_font_module
  89.  
  90. //------------------------------------------------------------------------------------------------
  91. //
  92. //    CVirtualFontFontCache::Add
  93. //
  94. //------------------------------------------------------------------------------------------------
  95. BOOL CVirtualFontFontCache::Add(int16 encoding, int size, BOOL fixed, BOOL bold, BOOL italic, BOOL underline, CFont*& pFont )
  96. {
  97.     ASSERT(pFont);
  98.     if(! CVirtualFontFontCache::m_cache)
  99.     {
  100.         // *** Fix me, we better tune the init of pSizecache
  101.         VERIFY(CVirtualFontFontCache::m_cache = new CMapWordToOb);
  102.         if(CVirtualFontFontCache::m_cache == NULL )
  103.             return FALSE;
  104.     }
  105.     CMapWordToOb*    pSizecache;
  106.     if(! CVirtualFontFontCache::m_cache->Lookup(encoding, (CObject*&)pSizecache))
  107.     {    
  108.         // *** Fix me, we better tune the init of pSizecache
  109.         VERIFY(pSizecache = new CMapWordToOb);
  110.         if(pSizecache == NULL)
  111.             return FALSE;    
  112.         CVirtualFontFontCache::m_cache->SetAt(encoding, (CObject*&)pSizecache);
  113.     }
  114.     CMapWordToOb*    pStylecache;
  115.     if(! pSizecache->Lookup(size, (CObject*&)pStylecache))
  116.     {
  117.         // *** Fix me, we better tune the init of pSizecache
  118.         VERIFY(pStylecache = new CMapWordToOb);
  119.         if(pStylecache == NULL )
  120.             return FALSE;
  121.         pSizecache->SetAt(size, (CObject*&)pStylecache);
  122.     }
  123.     pStylecache->SetAt(STYLEKEY(fixed,bold,italic,underline), (CObject*&)pFont);
  124.     return TRUE;
  125. }
  126.  
  127. //#ifdef netscape_font_module
  128. BOOL CVirtualFontFontCache::Add(int16 encoding, int size, BOOL fixed, BOOL bold, 
  129.                                 BOOL italic, BOOL underline, CyaFont*& pFont )
  130. {
  131.     ASSERT(pFont);
  132.     if(! CVirtualFontFontCache::m_Cyacache)
  133.     {
  134.         // *** Fix me, we better tune the init of pSizecache
  135.         VERIFY(CVirtualFontFontCache::m_Cyacache = new CMapWordToOb);
  136.         if(CVirtualFontFontCache::m_Cyacache == NULL )
  137.             return FALSE;
  138.     }
  139.     CMapWordToOb*    pSizecache;
  140.     if(! CVirtualFontFontCache::m_Cyacache->Lookup(encoding, (CObject*&)pSizecache))
  141.     {    
  142.         // *** Fix me, we better tune the init of pSizecache
  143.         VERIFY(pSizecache = new CMapWordToOb);
  144.         if(pSizecache == NULL)
  145.             return FALSE;    
  146.         CVirtualFontFontCache::m_Cyacache->SetAt(encoding, (CObject*&)pSizecache);
  147.     }
  148.     CMapWordToOb*    pStylecache;
  149.     if(! pSizecache->Lookup(size, (CObject*&)pStylecache))
  150.     {
  151.         // *** Fix me, we better tune the init of pSizecache
  152.         VERIFY(pStylecache = new CMapWordToOb);
  153.         if(pStylecache == NULL )
  154.             return FALSE;
  155.         pSizecache->SetAt(size, (CObject*&)pStylecache);
  156.     }
  157.     pStylecache->SetAt(STYLEKEY(fixed,bold,italic,underline), (CObject*&)pFont);
  158.     return TRUE;
  159. }
  160. //#endif  //netscape_font_module
  161.  
  162.  
  163.  
  164. //------------------------------------------------------------------------------------------------
  165. //
  166. //    CVirtualFontFontCache::Reset
  167. //
  168. //------------------------------------------------------------------------------------------------
  169.  
  170. void CVirtualFontFontCache::Reset()
  171. {
  172.     CMapWordToOb*    pEncodingcache = CVirtualFontFontCache::m_cache;
  173.     CVirtualFontFontCache::m_cache = NULL;
  174.     // we should really lock this function
  175.     if(pEncodingcache)
  176.     {
  177.         int16    encoding;
  178.         CMapWordToOb*    pSizecache;
  179.         POSITION i;
  180.         for(i = pEncodingcache->GetStartPosition(); i != NULL;)
  181.         {
  182.             pEncodingcache->GetNextAssoc(i, (WORD&)encoding, (CObject*&)pSizecache);
  183.             // pEncodingcache->RemoveKey(encoding);
  184.             ASSERT(pSizecache);
  185.             if(pSizecache)
  186.             {
  187.                 POSITION j;
  188.                 for(j = pSizecache->GetStartPosition(); j != NULL;)
  189.                 {        
  190.                     int size;
  191.                     CMapWordToOb*    pStylecache;
  192.                     pSizecache->GetNextAssoc(j, (WORD&)size, (CObject*&)pStylecache);
  193.                     // pSizecache->RemoveKey(size);
  194.                     ASSERT(pStylecache);
  195.                     if(pStylecache)
  196.                     {
  197.                         POSITION k;
  198.                         for(k = pStylecache->GetStartPosition(); k != NULL;)
  199.                         {        
  200.                             WORD style;
  201.                             CFont* pFont = NULL;
  202.                             pStylecache->GetNextAssoc(k, style, (CObject*&)pFont);
  203.                             // pStylecache->RemoveKey(style);
  204.                             ASSERT(pFont);
  205.                             if(pFont)
  206.                             {
  207.                                 delete pFont;
  208.                             }
  209.                         }    // for each style
  210.                         pStylecache->RemoveAll();
  211.                         ASSERT( pStylecache->GetCount() == 0);
  212.                         ASSERT( pStylecache->IsEmpty());
  213.                         delete pStylecache;
  214.                     }
  215.                 }    // for each size
  216.                 pSizecache->RemoveAll();
  217.                 ASSERT( pSizecache->GetCount() == 0);
  218.                 ASSERT( pSizecache->IsEmpty());
  219.                 delete pSizecache;
  220.             }
  221.         }    // for each encoding
  222.         pEncodingcache->RemoveAll();
  223.         ASSERT( pEncodingcache->GetCount() == 0);
  224.         ASSERT( pEncodingcache->IsEmpty());
  225.         delete pEncodingcache;
  226.     }
  227.  
  228. //#ifdef netscape_font_module
  229.     CVirtualFontFontCache::ResetCyacache();
  230. //#endif  //netscape_font_module
  231. }
  232.  
  233. //#ifdef netscape_font_module
  234. void CVirtualFontFontCache::ResetCyacache()
  235. {
  236.     CMapWordToOb*    pEncodingcache = CVirtualFontFontCache::m_Cyacache;
  237.     CVirtualFontFontCache::m_Cyacache = NULL;
  238.     // we should really lock this function
  239.     if(pEncodingcache)
  240.     {
  241.         int16    encoding;
  242.         CMapWordToOb*    pSizecache;
  243.         POSITION i;
  244.         for(i = pEncodingcache->GetStartPosition(); i != NULL;)
  245.         {
  246.             pEncodingcache->GetNextAssoc(i, (WORD&)encoding, (CObject*&)pSizecache);
  247.             // pEncodingcache->RemoveKey(encoding);
  248.             ASSERT(pSizecache);
  249.             if(pSizecache)
  250.             {
  251.                 POSITION j;
  252.                 for(j = pSizecache->GetStartPosition(); j != NULL;)
  253.                 {        
  254.                     int size;
  255.                     CMapWordToOb*    pStylecache;
  256.                     pSizecache->GetNextAssoc(j, (WORD&)size, (CObject*&)pStylecache);
  257.                     // pSizecache->RemoveKey(size);
  258.                     ASSERT(pStylecache);
  259.                     if(pStylecache)
  260.                     {
  261.                         POSITION k;
  262.                         for(k = pStylecache->GetStartPosition(); k != NULL;)
  263.                         {        
  264.                             WORD style;
  265.                             CyaFont* pFont = NULL;
  266.                             pStylecache->GetNextAssoc(k, style, (CObject*&)pFont);
  267.                             // pStylecache->RemoveKey(style);
  268.                             ASSERT(pFont);
  269.                             if(pFont)
  270.                             {
  271.                                 delete pFont;
  272.                             }
  273.                         }    // for each style
  274.                         pStylecache->RemoveAll();
  275.                         ASSERT( pStylecache->GetCount() == 0);
  276.                         ASSERT( pStylecache->IsEmpty());
  277.                         delete pStylecache;
  278.                     }
  279.                 }    // for each size
  280.                 pSizecache->RemoveAll();
  281.                 ASSERT( pSizecache->GetCount() == 0);
  282.                 ASSERT( pSizecache->IsEmpty());
  283.                 delete pSizecache;
  284.             }
  285.         }    // for each encoding
  286.         pEncodingcache->RemoveAll();
  287.         ASSERT( pEncodingcache->GetCount() == 0);
  288.         ASSERT( pEncodingcache->IsEmpty());
  289.         delete pEncodingcache;
  290.     }
  291. }
  292. //#endif  //netscape_font_module
  293.