[gbrainy/gbrainy_16x] Support for different font sizes at string text



commit c307523938dd78ae334124c2ef587b981edc2a6b
Author: Jordi Mas <jmas softcatala org>
Date:   Mon Sep 13 22:51:15 2010 +0200

    Support for different font sizes at string text

 data/games.xml                         |    9 ++++-----
 src/Core/Main/Xml/GameXml.cs           |   23 +++++++++++++++++++----
 src/Core/Main/Xml/GameXmlDefinition.cs |   16 +++++++++++++++-
 src/Core/Main/Xml/GameXmlFactory.cs    |   27 +++++++++++++++++++++++----
 tests/Core/GameXmlFactoryTest.cs       |    2 +-
 tests/test_games.xml                   |    2 +-
 6 files changed, 63 insertions(+), 16 deletions(-)
---
diff --git a/data/games.xml b/data/games.xml
index 2e69372..6a8f838 100644
--- a/data/games.xml
+++ b/data/games.xml
@@ -166,7 +166,7 @@
 				int rslt = num_b - num_a;
 			</variables>
 			<_question>What number plus [num_a] equals [num_b]?</_question>
-			<string _text = "x + [num_a] = [num_b]" x = "0.5" y = "0.4" centered = "yes" size = "big"/>
+			<string _text = "x + [num_a] = [num_b]" x = "0.5" y = "0.4" centered = "yes" size = "large"/>
 			<answer>[rslt]</answer>
 			<_rationale>It is the result of the operation [num_b] - [num_a].</_rationale>
 		</variant>
@@ -179,7 +179,7 @@
 				int rslt = num_b + num_a;
 			</variables>
 			<_question>What number minus [num_a] equals [num_b]?</_question>
-			<string _text = "x - [num_a] = [num_b]" x = "0.5" y = "0.4" centered = "yes" size = "big"/>
+			<string _text = "x - [num_a] = [num_b]" x = "0.5" y = "0.4" centered = "yes" size = "large"/>
 			<answer>[rslt]</answer>
 			<_rationale>It is the result of the operation [num_a] + [num_b].</_rationale>
 		</variant>
@@ -192,7 +192,7 @@
 				int rslt = num_b / num_a;
 			</variables>
 			<_question>What number multiplied by [num_a] equals [num_b]?</_question>
-			<string _text = "x * [num_a] = [num_b]" x = "0.5" y = "0.4" centered = "yes" size = "big"/>
+			<string _text = "x * [num_a] = [num_b]" x = "0.5" y = "0.4" centered = "yes" size = "large"/>
 			<answer>[rslt]</answer>
 			<_rationale>It is the result of the operation [num_b] / [num_a].</_rationale>
 		</variant>
@@ -205,7 +205,7 @@
 				int rslt = num_a * num_b;
 			</variables>
 			<_question>What number divided by [num_a] equals [num_b]?</_question>
-			<string _text = "x / [num_a] = [num_b]" x = "0.5" y = "0.4" centered = "yes" size = "big"/>
+			<string _text = "x / [num_a] = [num_b]" x = "0.5" y = "0.4" centered = "yes" size = "large"/>
 			<answer>[rslt]</answer>
 			<_rationale>It is the result of the operation [num_a] * [num_b].</_rationale>
 		</variant>
@@ -254,6 +254,5 @@
 			<answer_checkattributes>Trim | MatchAll </answer_checkattributes>
 			<_rationale>Palindrome years occur usually at 110 year intervals except for the end of each millennium that occur at a 11 years interval.</_rationale>
 		</variant>
-
 	</game>
 </games>
diff --git a/src/Core/Main/Xml/GameXml.cs b/src/Core/Main/Xml/GameXml.cs
index c984ef8..384d1e3 100644
--- a/src/Core/Main/Xml/GameXml.cs
+++ b/src/Core/Main/Xml/GameXml.cs
@@ -245,10 +245,25 @@ namespace gbrainy.Core.Main.Xml
 						text = CatalogGetString (draw_string.Text);
 						text = CodeEvaluation.ReplaceVariables (text);
 
-						if (draw_string.Big)
-							gr.SetPangoLargeFontSize ();
-						else
-							gr.SetPangoNormalFontSize ();
+						switch (draw_string.Size) {
+						case TextDrawingObject.Sizes.Small:
+							gr.SetPangoFontSize (0.018);
+							break;
+						case TextDrawingObject.Sizes.Medium:
+							gr.SetPangoNormalFontSize (); // 0.022
+							break;
+						case TextDrawingObject.Sizes.Large:
+							gr.SetPangoLargeFontSize (); // 0.0325
+							break;
+						case TextDrawingObject.Sizes.XLarge:
+							gr.SetPangoFontSize (0.06);
+							break;
+						case TextDrawingObject.Sizes.XXLarge:
+							gr.SetPangoFontSize (0.08);
+							break;
+						default:
+							throw new InvalidOperationException ("Invalid value");
+						}
 
 						if (draw_string.Centered) {
 							gr.DrawTextCentered (draw_string.X, draw_string.Y, text);
diff --git a/src/Core/Main/Xml/GameXmlDefinition.cs b/src/Core/Main/Xml/GameXmlDefinition.cs
index 66585bd..e18bdc8 100644
--- a/src/Core/Main/Xml/GameXmlDefinition.cs
+++ b/src/Core/Main/Xml/GameXmlDefinition.cs
@@ -57,11 +57,25 @@ namespace gbrainy.Core.Main.Xml
 
 	public class TextDrawingObject : DrawingObject
 	{
+		public enum Sizes
+		{
+			Small,
+			Medium,
+			Large,
+			XLarge,
+			XXLarge,
+		}
+
 		public string Text { get; set; }
 		public double X { get; set; }
 		public double Y { get; set; }
 		public bool Centered { get; set; }
-		public bool Big { get; set; }
+		public Sizes Size { get; set; }
+
+		public TextDrawingObject ()
+		{
+			Size = Sizes.Medium;
+		}
 	};
 
 	public class GameXmlDefinitionVariant
diff --git a/src/Core/Main/Xml/GameXmlFactory.cs b/src/Core/Main/Xml/GameXmlFactory.cs
index ec0eb5c..2715358 100644
--- a/src/Core/Main/Xml/GameXmlFactory.cs
+++ b/src/Core/Main/Xml/GameXmlFactory.cs
@@ -161,11 +161,30 @@ namespace gbrainy.Core.Main.Xml
 							draw_string.Centered = false;
 
 						str = reader.GetAttribute ("size");
-						if (String.Compare (str, "big", true) == 0)
-							draw_string.Big = true;
-						else
-							draw_string.Big = false;
 
+						if (String.IsNullOrEmpty (str) == false)
+						{
+							switch (str.ToLower ()) {
+							case "small":
+								draw_string.Size = TextDrawingObject.Sizes.Small;
+								break;
+							case "medium":
+								draw_string.Size = TextDrawingObject.Sizes.Medium;
+								break;
+							case "large":
+								draw_string.Size = TextDrawingObject.Sizes.Large;
+								break;
+							case "x-large":
+								draw_string.Size = TextDrawingObject.Sizes.XLarge;
+								break;
+							case "xx-large":
+								draw_string.Size = TextDrawingObject.Sizes.XXLarge;
+								break;
+							default:
+								Console.WriteLine ("GameXmlFactory. Unsupported value for size attribute: {0}", str);
+								break;
+							}
+						}
 						break;
 					case "_question":
 					case "question":
diff --git a/tests/Core/GameXmlFactoryTest.cs b/tests/Core/GameXmlFactoryTest.cs
index 17043bc..6e9f197 100644
--- a/tests/Core/GameXmlFactoryTest.cs
+++ b/tests/Core/GameXmlFactoryTest.cs
@@ -89,7 +89,7 @@ namespace gbrainyTest
 			Assert.AreEqual (0.5, text.X);
 			Assert.AreEqual (0.4, text.Y);
 			Assert.AreEqual (true, text.Centered);
-			Assert.AreEqual (true, text.Big);
+			Assert.AreEqual (TextDrawingObject.Sizes.Large, text.Size);
 		}
 
 		[Test]
diff --git a/tests/test_games.xml b/tests/test_games.xml
index 8c9f210..c87ea5b 100644
--- a/tests/test_games.xml
+++ b/tests/test_games.xml
@@ -9,7 +9,7 @@
 		</variables>
 		<_rationale>Rationale text</_rationale>
 		<svg file = "clock.svg" x = "0.30" y = "0.40" width = "0.50" height = "0.60"/>
-		<string _text = "Sample text for unit tests" x = "0.5" y = "0.4" centered = "yes" size = "big"/>
+		<string _text = "Sample text for unit tests" x = "0.5" y = "0.4" centered = "yes" size = "large"/>
 		<question>How many degrees rotates the minute hand of a clock?</question>
 		<question plural ="[rslt]">How many degrees rotates the minute hand of a clocks?</question>
 		<answer>[rslt]</answer>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]