public override int stringWidth(java.lang.Object n1, java.lang.String n2) {
     int result = f(n1).getStringWidth(toCSharp(n2));
     StringFontPair sfp = new StringFontPair(toCSharp(n2), f(n1));
     if (!stringWidthCache.ContainsKey(sfp)) {
         stringWidthCache.Add(sfp, result);
     }
     return stringWidthCache[sfp];
 }
        public override bool Equals(Object stfpo)
        {
            StringFontPair stfp = (StringFontPair)stfpo;

            return(str.Equals(stfp.str) && font.Equals(stfp.font));
        }
 public override int stringWidth(java.lang.Object n1, java.lang.String n2)
 {
     NativeFont font = f(n1);
     string str = toCSharp(n2);
     StringFontPair sfp = new StringFontPair(str, font);
     if (stringWidthCache.ContainsKey(sfp))
     {
         return stringWidthCache[sfp];
     }
     int result = 0;
     using (AutoResetEvent are = new AutoResetEvent(false))
     {
         System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
         {
             TextBlock tb = new TextBlock();
             tb.FontSize = font.height;
             tb.Text = str;
             tb.Measure(new Size(1000000, 1000000));
             result = (int)tb.ActualWidth;
             are.Set();
         });
         are.WaitOne();
     }
     stringWidthCache.Add(sfp, result);
     return result;
 }