[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-libs-commits] CVS: xsharp/Xsharp/XWindows Font.cs,NONE,1.1 FontS
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-libs-commits] CVS: xsharp/Xsharp/XWindows Font.cs,NONE,1.1 FontStyle.cs,NONE,1.1 Application.cs,1.2,1.3 Display.cs,1.4,1.5 Xlib.cs.in,1.5,1.6 |
Date: |
Sat, 28 Sep 2002 07:18:31 -0400 |
Update of /cvsroot/dotgnu-libs/xsharp/Xsharp/XWindows
In directory subversions:/tmp/cvs-serv26090/Xsharp/XWindows
Modified Files:
Application.cs Display.cs Xlib.cs.in
Added Files:
Font.cs FontStyle.cs
Log Message:
Add some of the support logic that is needed for fonts.
--- NEW FILE ---
/*
* Font.cs - Font object for X#.
*
* This file is part of the X# library.
* Copyright (C) 2002 Southern Storm Software, Pty Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace XWindows
{
using System;
/// <summary>
/// <para>The <see cref="T:XWindows.Font"/> class encapsulates
/// the operations on an X font.</para>
/// </summary>
public sealed class Font
{
// Internal class that keeps track of displays and fontsets.
private class FontInfo
{
public FontInfo next;
public Display dpy;
public IntPtr fontSet;
} // class FontInfo
// Internal state.
private String family;
private int pointSize;
private FontStyle style;
private String xname;
private FontInfo infoList;
/// <summary>
/// <para>The family name for the default sans-serif font.</para>
/// </summary>
public static readonly String SansSerif = "helvetica";
/// <summary>
/// <para>The family name for the default serif font.</para>
/// </summary>
public static readonly String Serif = "times";
/// <summary>
/// <para>The family name for the default fixed-width font.</para>
/// </summary>
public static readonly String Fixed = "courier";
/// <summary>
/// <para>Constructs a new instance of <see cref="T:XWindows.Font"/>.
/// </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>
public Font(String family, int pointSize, FontStyle style)
{
if(family != null)
this.family = family;
else
this.family = SansSerif;
if(pointSize < 0 || pointSize > 1000)
this.pointSize = 120;
else
this.pointSize = pointSize;
this.style = style;
this.xname = null;
this.infoList = null;
}
/// <summary>
/// <para>Constructs a new instance of <see cref="T:XWindows.Font"/>
/// with a default point size and style.</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>
public Font(String family)
: this(family, 120, FontStyle.Normal)
{
// Nothing to do here.
}
/// <summary>
/// <para>Constructs a new instance of <see cref="T:XWindows.Font"/>
/// with a default style.</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>
public Font(String family, int pointSize)
: this(family, pointSize, FontStyle.Normal)
{
// Nothing to do here.
}
// Internal constructor that is called from "CreateFromXLFD".
private Font(String name, bool unused)
{
this.family = null;
this.pointSize = 0;
this.style = FontStyle.Normal;
this.xname = name;
this.infoList = null;
}
/// <summary>
/// <para>Get the family name of this font.</para>
/// </summary>
///
/// <value>
/// <para>The family name, or <see langword="null"/> if this font
/// was created from an XLFD name.</para>
/// </value>
public String Family
{
get
{
return family;
}
}
/// <summary>
/// <para>Get the point size of this font.</para>
/// </summary>
///
/// <value>
/// <para>The point size.</para>
/// </value>
public int PointSize
{
get
{
return pointSize;
}
}
/// <summary>
/// <para>Get the extra styles that are associated with this
font.</para>
/// </summary>
///
/// <value>
/// <para>The extra styles.</para>
/// </value>
public FontStyle Style
{
get
{
return style;
}
}
/// <summary>
/// <para>Get the XLFD name of this font.</para>
/// </summary>
///
/// <value>
/// <para>The XLFD name, or <see langword="null"/> if this font
/// was not created from an XLFD name.</para>
/// </value>
public String XLFD
{
get
{
return xname;
}
}
/// <summary>
/// <para>Determine if two font descriptions are equal.</para>
/// </summary>
///
/// <param name="obj">
/// <para>The font object to compare against.</para>
/// </param>
///
/// <returns>
/// <para>Returns <see langword="true"/> if the two fonts are equal;
/// <see langword="false"/> otherwise.</para>
/// </returns>
public override bool Equals(Object obj)
{
Font other = (obj as Font);
if(other != null)
{
if(this == other)
{
return true;
}
else
{
return (this.family ==
other.family &&
this.pointSize ==
other.pointSize &&
this.style ==
other.style &&
this.xname ==
other.xname);
}
}
else
{
return false;
}
}
/// <summary>
/// <para>Get the hash code for a font.</para>
/// </summary>
///
/// <returns>
/// <para>Returns the hash code.</para>
/// </returns>
public override int GetHashCode()
{
return (((family == null) ? xname.GetHashCode()
: family.GetHashCode()) +
pointSize + (int)style);
}
/// <summary>
/// <para>Construct a font from an XLFD name.</para>
/// </summary>
///
/// <param name="name">
/// <para>The XLFD name of the font.</para>
/// </param>
///
/// <returns>
/// <para>The font object that corresponds to
/// <paramref name="name"/>.</para>
/// </returns>
public static Font CreateFromXLFD(String name)
{
if(name == null)
{
return new Font(null);
}
else
{
return new Font(name, true);
}
}
// Get the XFontSet structure for this font on a particular display.
internal IntPtr GetFontSet(Display dpy)
{
lock(typeof(Font))
{
// Map this object to the one that
actually stores
// the font set information.
Font font = (Font)(dpy.fonts[this]);
if(font == null)
{
font = this;
}
// Search for existing font set
information.
FontInfo info = font.infoList;
while(info != null)
{
if(info.dpy == dpy)
{
return info.fontSet;
}
info = info.next;
}
// TODO: create a new font set.
// TODO: associate the font set with
the display.
return IntPtr.Zero;
}
}
// Disassociate this font from a particular display.
internal void Disassociate(Display dpy)
{
lock(typeof(Font))
{
FontInfo info, prev;
info = infoList;
prev = null;
while(info != null && info.dpy != dpy)
{
prev = info;
info = info.next;
}
if(info != null)
{
if(prev != null)
{
prev.next = info.next;
}
else
{
infoList = info.next;
}
Xlib.XFreeFontSet(dpy.dpy,
info.fontSet);
}
}
}
} // class Font
} // namespace XWindows
--- NEW FILE ---
/*
* FontStyle.cs - Font style values.
*
* This file is part of the X# library.
* Copyright (C) 2002 Southern Storm Software, Pty Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace XWindows
{
using System;
/// <summary>
/// <para>The <see cref="T:XWindows.FontStyle"/> enumeration specifies
/// masks for font styles like bold, italic, etc.</para>
/// </summary>
[Flags]
public enum FontStyle
{
Normal = 0,
Bold = (1<<0),
Italic = (1<<1),
Underlined = (1<<2)
} // enum FontStyle
} // namespace XWindows
Index: Application.cs
===================================================================
RCS file: /cvsroot/dotgnu-libs/xsharp/Xsharp/XWindows/Application.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** Application.cs 28 Sep 2002 04:56:17 -0000 1.2
--- Application.cs 28 Sep 2002 11:18:28 -0000 1.3
***************
*** 42,45 ****
--- 42,46 ----
private String title;
private String geometry;
+ private Font defaultFont;
private static Application primary;
***************
*** 66,69 ****
--- 67,71 ----
String[] envCmdLine;
int firstArg = 0;
+ String fontName;
// Set this as the primary application object
if necessary.
***************
*** 131,134 ****
--- 133,137 ----
title = null;
geometry = null;
+ fontName = null;
// Process the standard Xt command-line options.
***************
*** 202,206 ****
if(firstArg <
args.Length)
{
! // TODO: set
the application's default font.
}
}
--- 205,209 ----
if(firstArg <
args.Length)
{
! fontName =
args[firstArg];
}
}
***************
*** 249,252 ****
--- 252,259 ----
// Connect to the display.
display = XWindows.Display.Open(displayName,
this);
+
+ // Create the default font.
+ defaultFont = Font.CreateFromXLFD(fontName);
+ defaultFont.GetFontSet(display);
}
***************
*** 446,449 ****
--- 453,471 ----
{
return geometry;
+ }
+ }
+
+ /// <summary>
+ /// <para>Get the application's default font.</para>
+ /// </summary>
+ ///
+ /// <value>
+ /// <para>The default font object.</para>
+ /// </value>
+ public Font DefaultFont
+ {
+ get
+ {
+ return defaultFont;
}
}
Index: Display.cs
===================================================================
RCS file: /cvsroot/dotgnu-libs/xsharp/Xsharp/XWindows/Display.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** Display.cs 28 Sep 2002 04:47:49 -0000 1.4
--- Display.cs 28 Sep 2002 11:18:28 -0000 1.5
***************
*** 57,60 ****
--- 57,61 ----
internal ButtonName selectButton;
internal ButtonName menuButton;
+ internal Hashtable fonts;
// Constructor.
***************
*** 109,112 ****
--- 110,116 ----
}
selectButton = ButtonName.Button1;
+
+ // Construct the font map.
+ fonts = new Hashtable();
}
***************
*** 210,213 ****
--- 214,224 ----
screens[scr].RootWindow.Disassociate();
}
+
+ // Disassociate the
fonts from this display.
+ foreach(Font font in
fonts)
+ {
+
font.Disassociate(this);
+ }
+ fonts.Clear();
// Close the connection
to the X server.
Index: Xlib.cs.in
===================================================================
RCS file: /cvsroot/dotgnu-libs/xsharp/Xsharp/XWindows/Xlib.cs.in,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** Xlib.cs.in 28 Sep 2002 03:01:00 -0000 1.5
--- Xlib.cs.in 28 Sep 2002 11:18:28 -0000 1.6
***************
*** 424,427 ****
--- 424,432 ----
(IntPtr display, String name, Bool only_if_exists);
+ // Declare font-related external functions.
+
+ [DllImport("X11")]
+ extern public static void XFreeFontSet(IntPtr display, IntPtr fontSet);
+
} // class Xlib
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-libs-commits] CVS: xsharp/Xsharp/XWindows Font.cs,NONE,1.1 FontStyle.cs,NONE,1.1 Application.cs,1.2,1.3 Display.cs,1.4,1.5 Xlib.cs.in,1.5,1.6,
Rhys Weatherley <address@hidden> <=