mirror of
https://github.com/opensim/opensim.git
synced 2026-07-31 05:45:37 +08:00
From: Christopher Yeoh <yeohc@au1.ibm.com>
The attached patch implements osGetDrawStringSize that looks like: vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize) in LSL. It is meant to be used in conjunction with the osDraw* functions. It returns accurate information on the size that a given string will be rendered given the specified font and font size. This allows for nicely formatted and positioned text on the generated image.
This commit is contained in:
@@ -89,6 +89,20 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
|
||||
return true;
|
||||
}
|
||||
|
||||
public void GetDrawStringSize(string text, string fontName, int fontSize,
|
||||
out double xSize, out double ySize)
|
||||
{
|
||||
Bitmap bitmap = new Bitmap(1024, 1024, PixelFormat.Format32bppArgb);
|
||||
Graphics graph = Graphics.FromImage(bitmap);
|
||||
|
||||
Font myFont = new Font(fontName, fontSize);
|
||||
SizeF stringSize = new SizeF();
|
||||
stringSize = graph.MeasureString(text, myFont);
|
||||
xSize = stringSize.Width;
|
||||
ySize = stringSize.Height;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region IRegionModule Members
|
||||
|
||||
Reference in New Issue
Block a user