Esempio n. 1
0
 /**
  * Returns <code>FontData</code> objects which describe the fonts that match the given arguments.
  * If the <code>faceName</code> is null, all fonts will be returned.
  *
  * @param faceName the name of the font to look for, or null
  * @param scalable if true only scalable fonts are returned, otherwise only non-scalable fonts are
  *     returned.
  * @return the matching font data
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed
  *     </ul>
  */
 public FontData[] getFontList(String faceName, boolean scalable) {
   checkDevice();
   if (!scalable) return new FontData[0];
   int typefaces;
   if (faceName != null) {
     int length = faceName.length();
     char[] chars = new char[length + 1];
     faceName.getChars(0, length, chars, 0);
     int str = OS.gcnew_String(chars);
     int fontFamily = OS.gcnew_FontFamily(str);
     typefaces = OS.FontFamily_GetTypefaces(fontFamily);
     OS.GCHandle_Free(fontFamily);
     OS.GCHandle_Free(str);
   } else {
     typefaces = OS.Fonts_SystemTypefaces();
   }
   int count = OS.TypefaceCollection_Count(typefaces);
   int index = 0;
   FontData[] result = new FontData[count];
   int enumerator = OS.TypefaceCollection_GetEnumerator(typefaces);
   while (OS.IEnumerator_MoveNext(enumerator)) {
     int typeface = OS.TypefaceCollection_Current(enumerator);
     int fontFamily = OS.Typeface_FontFamily(typeface);
     int style = OS.Typeface_Style(typeface);
     int weight = OS.Typeface_Weight(typeface);
     int stretch = OS.Typeface_Stretch(typeface);
     int str = OS.FontFamily_Source(fontFamily);
     int charArray = OS.String_ToCharArray(str);
     char[] chars = new char[OS.String_Length(str)];
     OS.memcpy(chars, charArray, chars.length * 2);
     int fontStyle = OS.FontStyles_Normal;
     if (OS.Object_Equals(style, OS.FontStyles_Italic)) fontStyle = OS.FontStyles_Italic;
     if (OS.Object_Equals(style, OS.FontStyles_Oblique)) fontStyle = OS.FontStyles_Oblique;
     FontData data =
         FontData.wpf_new(
             new String(chars),
             fontStyle,
             OS.FontWeight_ToOpenTypeWeight(weight),
             OS.FontStretch_ToOpenTypeStretch(stretch),
             0);
     OS.GCHandle_Free(charArray);
     OS.GCHandle_Free(str);
     OS.GCHandle_Free(fontFamily);
     OS.GCHandle_Free(style);
     OS.GCHandle_Free(weight);
     OS.GCHandle_Free(stretch);
     OS.GCHandle_Free(typeface);
     result[index++] = data;
   }
   OS.GCHandle_Free(enumerator);
   OS.GCHandle_Free(typefaces);
   return result;
 }