changeset 62:41c2c84fd73c

dup string when used as map keys
author Frank Benoit <benoit@tionex.de>
date Mon, 14 Apr 2008 02:10:46 +0200
parents a5e7bf70c050
children d0467f3a67b3
files dwtx/jface/resource/FontRegistry.d
diffstat 1 files changed, 17 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/dwtx/jface/resource/FontRegistry.d	Mon Apr 14 02:08:22 2008 +0200
+++ b/dwtx/jface/resource/FontRegistry.d	Mon Apr 14 02:10:46 2008 +0200
@@ -46,6 +46,7 @@
 import dwt.dwthelper.utils;
 import dwt.dwthelper.Runnable;
 version(Windows) import dwt.internal.win32.OS;
+import tango.util.log.Trace;
 
 /**
  * A font registry maintains a mapping between symbolic font names
@@ -351,15 +352,19 @@
         else version( Windows ){
             ImportData propdata;
             if( OS.IsWin95 && OS.WIN32_VERSION >= OS.VERSION (4, 10 )){
+                Trace.formatln( "JFaceResources {}, load win98", __LINE__ );
                 propdata = getImportData!( prefix ~ "windows98" ~ postfix );
             }
             else if( OS.WIN32_VERSION >= OS.VERSION (5, 1 )){
+                Trace.formatln( "JFaceResources {}, load winXP", __LINE__ );
                 propdata = getImportData!( prefix ~ "windowsxp" ~ postfix );
             }
             else if( OS.WIN32_VERSION >= OS.VERSION (5, 0)){
+                Trace.formatln( "JFaceResources {}, load win2k", __LINE__ );
                 propdata = getImportData!( prefix ~ "windows2000" ~ postfix );
             }
             else if( OS.WIN32_VERSION >= OS.VERSION (4, 0)){
+                Trace.formatln( "JFaceResources {}, load winNT", __LINE__ );
                 propdata = getImportData!( prefix ~ "windowsnt" ~ postfix );
             }
             else{
@@ -676,9 +681,11 @@
      * @return FontRecird
      */
     private FontRecord getFontRecord(String symbolicName) {
+        Trace.formatln( "FontRegistry {}: symbolicName={}",__LINE__,symbolicName);
         Assert.isNotNull(symbolicName);
-        Object result1 = stringToFontRecord.find(symbolicName);
+        auto result1 = stringToFontRecord.find(symbolicName);
         if (result1 !is null) {
+            Trace.formatln( "FontRegistry {}: ",__LINE__, (cast(FontRecord) result1).baseFont.toString );
             return cast(FontRecord) result1;
         }
 
@@ -696,7 +703,11 @@
             fontRecord = defaultFontRecord();
         }
 
-        stringToFontRecord.add(symbolicName, fontRecord);
+        stringToFontRecord.add(symbolicName.dup, fontRecord);
+            Trace.formatln( "FontRegistry {}: {}",__LINE__,fontRecord.baseFont.toString);
+            foreach( fd; fontRecord.baseFont.getFontData() ){
+                Trace.formatln( "FontRegistry {}: fontdata={}",__LINE__,fd.toString);
+            }
         return fontRecord;
 
     }
@@ -813,7 +824,7 @@
 
         FontRecord oldFont = stringToFontRecord.find(symbolicName);
         stringToFontRecord.removeKey(symbolicName);
-        stringToFontData.add(symbolicName, fontData);
+        stringToFontData.add(symbolicName.dup, fontData);
         if (update) {
             fireMappingChanged(symbolicName, new ArrayWrapperT!(FontData)(existing), new ArrayWrapperT!(FontData)(fontData));
         }
@@ -832,7 +843,7 @@
         foreach( key; bundle.getKeys() ){
             int pos = key.lastIndexOf('.');
             if (pos is -1) {
-                stringToFontData.add(key, [ makeFontData(bundle.getString(key)) ]);
+                stringToFontData.add(key.dup, [ makeFontData(bundle.getString(key)) ]);
             } else {
                 String name = key.substring(0, pos);
                 int i = 0;
@@ -846,13 +857,13 @@
                 FontData[] elements = stringToFontData.find(name);
                 if (elements is null) {
                     elements = new FontData[8];
-                    stringToFontData.add(name, elements);
+                    stringToFontData.add(name.dup, elements);
                 }
                 if (i > elements.length) {
                     FontData[] na = new FontData[i + 8];
                     System.arraycopy(elements, 0, na, 0, elements.length);
                     elements = na;
-                    stringToFontData.add(name, elements);
+                    stringToFontData.add(name.dup, elements);
                 }
                 elements[i] = makeFontData(bundle.getString(key));
             }