|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionHave you ever wanted to be able to display rotated text on a web page? Have you ever been handed a web site design from a graphic designer only to realize that every button, tab and other bit of text has suddenly turned into an image? Have you ever wanted to overlay the same text on all the images provided by part of your site - e.g. a copyright message? Well I had and I was bored of creating, and more than that, maintaining collections of images just to do some basic text overlay. So I created this project. BackgroundWhile not essential, it does make the project easier to use, if you make sure the user aspnet_wp runs as (normally ASPNET) has write access to your virtual directory location. For the <%@ Page language="c#" AutoEventWireup="false"
Inherits="Haley.RotateText.Control.RotateText" %>
For ease of setup, the demo includes a built version of the source. So once you have downloaded the demo, unzip the file into a new directory and create a new virtual directory in IIS to point at it. Running the demo should then be as simple as running up Test.aspx or Test2.aspx from there. To build the source, just unzip the source code to a new directory on in VS2003 and hit build. If you are playing with it much, it will probably be helpful to add both projects to the same solution. Using the codeThe code can logically be broken down into 4 sections:
Defintion objects
The basic classes are little more than encapsulations of a bunch of value properties. The TypeConverters are required to enable the Expandable features of the property grid. Getting the expandable property grid to work was not as easy as you might have thought. There are 2, what now seem like simple steps: Each of the properties need to be tagged with the following attributes: [NotifyParentProperty(true),
RefreshProperties(RefreshProperties.All),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
Each of the expandable objects need to have a type converter that inherits from public override PropertyDescriptorCollection
GetProperties(ITypeDescriptorContext context,
object value, Attribute[] attributes)
{
// return the list of properties ordering as we want
string [] names = {"TopBorder", "BottomBorder",
"LeftBorder", "RightBorder",
"TopLeft", "TopRight",
"BottomRight", "BottomLeft"};
PropertyDescriptorCollection pdc =
TypeDescriptor.GetProperties
(value,attributes).Sort(names);
return pdc;
}
public override object ConvertTo(ITypeDescriptorContext context,
CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ScalingDefn)
{
ScalingDefn sd = (ScalingDefn)value;
return "Expand for values";
}
if(destType == typeof(InstanceDescriptor))
{
// Create an instance descriptor for the type so that it
// can be recreated from a list of properties
System.Reflection.ConstructorInfo constructor;
constructor = typeof(ScalingDefn).GetConstructor
(new Type[] {typeof(Corner),typeof(Corner),
typeof(Corner),typeof(Corner), typeof(int),
typeof(int),typeof(int),typeof(int)});
ScalingDefn sd = (ScalingDefn)value;
return new InstanceDescriptor(constructor,
new Object[] {sd.TopLeft, sd.TopRight,
sd.BottomRight, sd.BottomLeft,
sd.TopBorder, sd.BottomBorder,
sd.LeftBorder, sd.RightBorder});
}
return base.ConvertTo(context, culture, value, destType);
}
Image generationImage generation is done by the
Creation of background imageThe background image can be created in a variety of ways:
The scaling definition defines 3 sets of areas as follows:
The size of the background is worked out either by the Overlaying the textIn order to overlay the text in the right place, we need to create 4 transformations:
The Control & Image pageThe control is just a simple wrapper round the definition objects and the generator that allows it to be dropped easily onto web forms. The image page is a thin aspx page that streams the CachingThere are 2 types of caching in use in the project.
The
When this request is processed by the server, it first checks to see if an image exists in the cache for the Caching as images can serve 2 purposes, it can enhance the speed of your site which is always important, but it can also allow the site to work behind load balancing servers where the return request is not guaranteed to be directed to the same machine and so any temporarily cached definition may not be there. Creating and caching images as required in the global.asax at startup will get round this. While not practical for large quantities of images, it would be fine for things like tabs, buttons, bits of styling etc. Advanced image creationIn order to be able to create more advanced images, it is possible via code to create an image either as a Future enhancements
History
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||