aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorSean Dague2009-02-18 12:56:36 +0000
committerSean Dague2009-02-18 12:56:36 +0000
commit383f8b3ac601baef7b2cb322f53fb36b69367286 (patch)
treef90b2535f102be4f3ba50a41bb2668dc2cb956f2
parentremove legacy pre-migration code for mysql grid adapter, who knew this (diff)
downloadopensim-SC_OLD-383f8b3ac601baef7b2cb322f53fb36b69367286.zip
opensim-SC_OLD-383f8b3ac601baef7b2cb322f53fb36b69367286.tar.gz
opensim-SC_OLD-383f8b3ac601baef7b2cb322f53fb36b69367286.tar.bz2
opensim-SC_OLD-383f8b3ac601baef7b2cb322f53fb36b69367286.tar.xz
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.
-rw-r--r--OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs12
-rw-r--r--OpenSim/Region/CoreModules/Scripting/LoadImageURL/LoadImageURLModule.cs7
-rw-r--r--OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs14
-rw-r--r--OpenSim/Region/Framework/Interfaces/IDynamicTextureManager.cs4
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs18
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs1
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs6
7 files changed, 62 insertions, 0 deletions
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
143 return UUID.Zero; 143 return UUID.Zero;
144 } 144 }
145 145
146
147 public void GetDrawStringSize(string contentType, string text, string fontName, int fontSize,
148 out double xSize, out double ySize)
149 {
150 xSize = 0;
151 ySize = 0;
152 if (RenderPlugins.ContainsKey(contentType))
153 {
154 RenderPlugins[contentType].GetDrawStringSize(text, fontName, fontSize, out xSize, out ySize);
155 }
156 }
157
146 #endregion 158 #endregion
147 159
148 #region IRegionModule Members 160 #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
84 return false; 84 return false;
85 } 85 }
86 86
87 public void GetDrawStringSize(string text, string fontName, int fontSize,
88 out double xSize, out double ySize)
89 {
90 xSize = 0;
91 ySize = 0;
92 }
93
87 #endregion 94 #endregion
88 95
89 #region IRegionModule Members 96 #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
89 return true; 89 return true;
90 } 90 }
91 91
92 public void GetDrawStringSize(string text, string fontName, int fontSize,
93 out double xSize, out double ySize)
94 {
95 Bitmap bitmap = new Bitmap(1024, 1024, PixelFormat.Format32bppArgb);
96 Graphics graph = Graphics.FromImage(bitmap);
97
98 Font myFont = new Font(fontName, fontSize);
99 SizeF stringSize = new SizeF();
100 stringSize = graph.MeasureString(text, myFont);
101 xSize = stringSize.Width;
102 ySize = stringSize.Height;
103 }
104
105
92 #endregion 106 #endregion
93 107
94 #region IRegionModule Members 108 #region IRegionModule Members
diff --git a/OpenSim/Region/Framework/Interfaces/IDynamicTextureManager.cs b/OpenSim/Region/Framework/Interfaces/IDynamicTextureManager.cs
index e119bc3..9b29209 100644
--- a/OpenSim/Region/Framework/Interfaces/IDynamicTextureManager.cs
+++ b/OpenSim/Region/Framework/Interfaces/IDynamicTextureManager.cs
@@ -43,6 +43,8 @@ namespace OpenSim.Region.Framework.Interfaces
43 int updateTimer); 43 int updateTimer);
44 UUID AddDynamicTextureData(UUID simID, UUID primID, string contentType, string data, string extraParams, 44 UUID AddDynamicTextureData(UUID simID, UUID primID, string contentType, string data, string extraParams,
45 int updateTimer, bool SetBlending, byte AlphaValue); 45 int updateTimer, bool SetBlending, byte AlphaValue);
46 void GetDrawStringSize(string contentType, string text, string fontName, int fontSize,
47 out double xSize, out double ySize);
46 } 48 }
47 49
48 public interface IDynamicTextureRender 50 public interface IDynamicTextureRender
@@ -54,5 +56,7 @@ namespace OpenSim.Region.Framework.Interfaces
54 byte[] ConvertStream(Stream data, string extraParams); 56 byte[] ConvertStream(Stream data, string extraParams);
55 bool AsyncConvertUrl(UUID id, string url, string extraParams); 57 bool AsyncConvertUrl(UUID id, string url, string extraParams);
56 bool AsyncConvertData(UUID id, string bodyData, string extraParams); 58 bool AsyncConvertData(UUID id, string bodyData, string extraParams);
59 void GetDrawStringSize(string text, string fontName, int fontSize,
60 out double xSize, out double ySize);
57 } 61 }
58} 62}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 564648b..597592d 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -677,6 +677,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
677 return drawList; 677 return drawList;
678 } 678 }
679 679
680 public LSL_Vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize)
681 {
682 CheckThreatLevel(ThreatLevel.VeryLow, "osGetDrawStringSize");
683 m_host.AddScriptLPS(1);
684
685 LSL_Vector vec = new LSL_Vector(0,0,0);
686 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
687 if (textureManager != null)
688 {
689 double xSize, ySize;
690 textureManager.GetDrawStringSize(contentType, text, fontName, fontSize,
691 out xSize, out ySize);
692 vec.x = xSize;
693 vec.y = ySize;
694 }
695 return vec;
696 }
697
680 public void osSetStateEvents(int events) 698 public void osSetStateEvents(int events)
681 { 699 {
682 // This function is a hack. There is no reason for it's existence 700 // This function is a hack. There is no reason for it's existence
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index 72bb60c..1150d76 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -88,6 +88,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
88 string osSetPenSize(string drawList, int penSize); 88 string osSetPenSize(string drawList, int penSize);
89 string osSetPenColour(string drawList, string colour); 89 string osSetPenColour(string drawList, string colour);
90 string osDrawImage(string drawList, int width, int height, string imageUrl); 90 string osDrawImage(string drawList, int width, int height, string imageUrl);
91 vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize);
91 void osSetStateEvents(int events); 92 void osSetStateEvents(int events);
92 93
93 double osList2Double(LSL_Types.list src, int index); 94 double osList2Double(LSL_Types.list src, int index);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index a92f046..6ba8b20 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -212,6 +212,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
212 { 212 {
213 return m_OSSL_Functions.osDrawImage(drawList, width, height, imageUrl); 213 return m_OSSL_Functions.osDrawImage(drawList, width, height, imageUrl);
214 } 214 }
215
216 public vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize)
217 {
218 return m_OSSL_Functions.osGetDrawStringSize(contentType, text, fontName, fontSize);
219 }
220
215 public void osSetStateEvents(int events) 221 public void osSetStateEvents(int events)
216 { 222 {
217 m_OSSL_Functions.osSetStateEvents(events); 223 m_OSSL_Functions.osSetStateEvents(events);