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.
GenericGridServerConcept
Sean Dague 2009-02-18 12:56:36 +00:00
parent 8d23d97084
commit 383f8b3ac6
7 changed files with 62 additions and 0 deletions

View File

@ -143,6 +143,18 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture
return UUID.Zero;
}
public void GetDrawStringSize(string contentType, string text, string fontName, int fontSize,
out double xSize, out double ySize)
{
xSize = 0;
ySize = 0;
if (RenderPlugins.ContainsKey(contentType))
{
RenderPlugins[contentType].GetDrawStringSize(text, fontName, fontSize, out xSize, out ySize);
}
}
#endregion
#region IRegionModule Members

View File

@ -84,6 +84,13 @@ namespace OpenSim.Region.CoreModules.Scripting.LoadImageURL
return false;
}
public void GetDrawStringSize(string text, string fontName, int fontSize,
out double xSize, out double ySize)
{
xSize = 0;
ySize = 0;
}
#endregion
#region IRegionModule Members

View File

@ -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

View File

@ -43,6 +43,8 @@ namespace OpenSim.Region.Framework.Interfaces
int updateTimer);
UUID AddDynamicTextureData(UUID simID, UUID primID, string contentType, string data, string extraParams,
int updateTimer, bool SetBlending, byte AlphaValue);
void GetDrawStringSize(string contentType, string text, string fontName, int fontSize,
out double xSize, out double ySize);
}
public interface IDynamicTextureRender
@ -54,5 +56,7 @@ namespace OpenSim.Region.Framework.Interfaces
byte[] ConvertStream(Stream data, string extraParams);
bool AsyncConvertUrl(UUID id, string url, string extraParams);
bool AsyncConvertData(UUID id, string bodyData, string extraParams);
void GetDrawStringSize(string text, string fontName, int fontSize,
out double xSize, out double ySize);
}
}

View File

@ -677,6 +677,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return drawList;
}
public LSL_Vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize)
{
CheckThreatLevel(ThreatLevel.VeryLow, "osGetDrawStringSize");
m_host.AddScriptLPS(1);
LSL_Vector vec = new LSL_Vector(0,0,0);
IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
if (textureManager != null)
{
double xSize, ySize;
textureManager.GetDrawStringSize(contentType, text, fontName, fontSize,
out xSize, out ySize);
vec.x = xSize;
vec.y = ySize;
}
return vec;
}
public void osSetStateEvents(int events)
{
// This function is a hack. There is no reason for it's existence

View File

@ -88,6 +88,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
string osSetPenSize(string drawList, int penSize);
string osSetPenColour(string drawList, string colour);
string osDrawImage(string drawList, int width, int height, string imageUrl);
vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize);
void osSetStateEvents(int events);
double osList2Double(LSL_Types.list src, int index);

View File

@ -212,6 +212,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
{
return m_OSSL_Functions.osDrawImage(drawList, width, height, imageUrl);
}
public vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize)
{
return m_OSSL_Functions.osGetDrawStringSize(contentType, text, fontName, fontSize);
}
public void osSetStateEvents(int events)
{
m_OSSL_Functions.osSetStateEvents(events);