[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] pnetlib/Xsharp Font.cs,1.9,1.10
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] pnetlib/Xsharp Font.cs,1.9,1.10 |
Date: |
Mon, 01 Dec 2003 02:03:48 +0000 |
Update of /cvsroot/dotgnu-pnet/pnetlib/Xsharp
In directory subversions:/tmp/cvs-serv25649/Xsharp
Modified Files:
Font.cs
Log Message:
Implement a font registration system, and register some PCF fonts through
it (not fully implemented yet).
Index: Font.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Font.cs,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** Font.cs 30 Nov 2003 23:12:03 -0000 1.9
--- Font.cs 1 Dec 2003 02:03:46 -0000 1.10
***************
*** 23,27 ****
--- 23,29 ----
using System;
+ using System.IO;
using System.Text;
+ using System.Reflection;
using Xsharp.Types;
***************
*** 42,45 ****
--- 44,59 ----
} // class FontInfo
+ // Information about a registered font.
+ private class RegisteredFont
+ {
+ public RegisteredFont next;
+ public String family;
+ public int pointSize;
+ public FontStyle style;
+ public byte[] data;
+ public IntPtr loadedData;
+
+ } // class RegisteredFont
+
// Internal state.
internal String family;
***************
*** 48,51 ****
--- 62,66 ----
internal String xname;
internal FontInfo infoList;
+ private static RegisteredFont registeredFonts;
/// <summary>
***************
*** 241,244 ****
--- 256,260 ----
/// </param>
///
+ /// <returns>
/// <para>The font object that corresponds to the given
parameters.</para>
/// </returns>
***************
*** 246,252 ****
(String family, int pointSize, FontStyle style)
{
if(family == DefaultSansSerif)
{
- // TODO: we will need to map this
differently in future.
family = SansSerif;
}
--- 262,290 ----
(String family, int pointSize, FontStyle style)
{
+ // Do we have a registered font for this name,
size, and style?
+ RegisteredFont font;
+ lock(typeof(Font))
+ {
+ font = registeredFonts;
+ while(font != null)
+ {
+ if(font.family == family &&
+ font.pointSize == pointSize
&&
+ font.style == (style &
~(FontStyle.Underlined |
+
FontStyle.StrikeOut)))
+ {
+ break;
+ }
+ font = font.next;
+ }
+ }
+ if(font != null)
+ {
+ // TODO: create a font based on a
registered font image.
+ }
+
+ // Search for a regular X font that matches the
conditions.
if(family == DefaultSansSerif)
{
family = SansSerif;
}
***************
*** 274,277 ****
--- 312,319 ----
/// use the default sans-serif font.</para>
/// </param>
+ ///
+ /// <returns>
+ /// <para>The font object that corresponds to the given
parameters.</para>
+ /// </returns>
public static Font CreateFont(String family)
{
***************
*** 292,295 ****
--- 334,341 ----
/// <para>The point size (120 is typically "normal height").</para>
/// </param>
+ ///
+ /// <returns>
+ /// <para>The font object that corresponds to the given
parameters.</para>
+ /// </returns>
public static Font CreateFont(String family, int pointSize)
{
***************
*** 319,322 ****
--- 365,503 ----
return new Font(name, true);
}
+ }
+
+ /// <summary>
+ /// <para>Register font data with a particular set of font
+ /// parameters.</para>
+ /// </summary>
+ ///
+ /// <param name="family">
+ /// <para>The name of the font family, or <see langword="null"/> to
+ /// use the default sans-serif font.</para>
+ /// </param>
+ ///
+ /// <param name="pointSize">
+ /// <para>The point size (120 is typically "normal height").</para>
+ /// </param>
+ ///
+ /// <param name="style">
+ /// <para>Additional styles to apply to the font.</para>
+ /// </param>
+ ///
+ /// <param name="data">
+ /// <para>The font data. This will normally be uncompressed
+ /// PCF font data.</para>
+ /// </param>
+ ///
+ /// <remarks>
+ /// <para>Registering a style will also register the underlined and
+ /// strikeout versions of the font, which are synthesized.</para>
+ /// </remarks>
+ ///
+ /// <exception cref="T:System.ArgumentNullException">
+ /// <para>Raised if <paramref name="family"/> or <paramref name="data"/>
+ /// is <see langword="null"/>.</para>
+ /// </exception>
+ public static void RegisterFont
+ (String family, int pointSize, FontStyle style,
byte[] data)
+ {
+ if(family == null)
+ {
+ throw new
ArgumentNullException("family");
+ }
+ if(data == null)
+ {
+ throw new ArgumentNullException("data");
+ }
+ RegisteredFont font = new RegisteredFont();
+ font.family = family;
+ font.pointSize = pointSize;
+ font.style = style;
+ font.data = data;
+ font.loadedData = IntPtr.Zero;
+ lock(typeof(Font))
+ {
+ font.next = registeredFonts;
+ registeredFonts = font;
+ }
+ }
+
+ /// <summary>
+ /// <para>Register font data with a particular set of font
+ /// parameters. The font data is obtained from a manifest resource
+ /// within an assembly.</para>
+ /// </summary>
+ ///
+ /// <param name="family">
+ /// <para>The name of the font family, or <see langword="null"/> to
+ /// use the default sans-serif font.</para>
+ /// </param>
+ ///
+ /// <param name="pointSize">
+ /// <para>The point size (120 is typically "normal height").</para>
+ /// </param>
+ ///
+ /// <param name="style">
+ /// <para>Additional styles to apply to the font.</para>
+ /// </param>
+ ///
+ /// <param name="assembly">
+ /// <para>The assembly containing the font data.</para>
+ /// </param>
+ ///
+ /// <param name="resourceName">
+ /// <para>The name of the resource containing the font data. This will
+ /// normally be uncompressed PCF font data.</para>
+ /// </param>
+ ///
+ /// <remarks>
+ /// <para>Registering a style will also register the underlined and
+ /// strikeout versions of the font, which are synthesized.</para>
+ /// </remarks>
+ ///
+ /// <exception cref="T:System.ArgumentNullException">
+ /// <para>Raised if <paramref name="family"/>, <paramref
name="assembly"/>,
+ /// or <paramref name="resourceName"/> is <see langword="null"/>, or
+ /// if the resource does not exist in the assembly.</para>
+ /// </exception>
+ public static void RegisterFont
+ (String family, int pointSize, FontStyle style,
+ Assembly assembly, String resourceName)
+ {
+ Stream stream;
+ byte[] data;
+
+ // Validate the parameters.
+ if(family == null)
+ {
+ throw new
ArgumentNullException("family");
+ }
+ if(assembly == null)
+ {
+ throw new
ArgumentNullException("assembly");
+ }
+ if(resourceName == null)
+ {
+ throw new
ArgumentNullException("resourceName");
+ }
+
+ // Load the font data from the resource.
+ stream =
assembly.GetManifestResourceStream(resourceName);
+ if(stream == null)
+ {
+ throw new
ArgumentNullException("resourceName");
+ }
+ try
+ {
+ data = new byte [(int)(stream.Length)];
+ stream.Read(data, 0, data.Length);
+ }
+ finally
+ {
+ stream.Close();
+ }
+
+ // Register the font with the data that we just
loaded.
+ RegisterFont(family, pointSize, style, data);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] pnetlib/Xsharp Font.cs,1.9,1.10,
Rhys Weatherley <address@hidden> <=