From 383f8b3ac601baef7b2cb322f53fb36b69367286 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Wed, 18 Feb 2009 12:56:36 +0000 Subject: From: Christopher Yeoh 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. --- .../Scripting/DynamicTexture/DynamicTextureModule.cs | 12 ++++++++++++ .../Scripting/LoadImageURL/LoadImageURLModule.cs | 7 +++++++ .../Scripting/VectorRender/VectorRenderModule.cs | 14 ++++++++++++++ 3 files changed, 33 insertions(+) (limited to 'OpenSim/Region/CoreModules/Scripting') diff --git a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs index a8f841b..ab404bd 100644 --- a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs @@ -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 diff --git a/OpenSim/Region/CoreModules/Scripting/LoadImageURL/LoadImageURLModule.cs b/OpenSim/Region/CoreModules/Scripting/LoadImageURL/LoadImageURLModule.cs index 2eb8fc0..96618e0 100644 --- a/OpenSim/Region/CoreModules/Scripting/LoadImageURL/LoadImageURLModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/LoadImageURL/LoadImageURLModule.cs @@ -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 diff --git a/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs b/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs index 6a348a3..c3e39ad 100644 --- a/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs @@ -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 -- cgit v1.1