[gbrainy] Initial PDF export support
- From: Jordi Mas <jmas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gbrainy] Initial PDF export support
- Date: Sun, 21 Nov 2010 10:29:02 +0000 (UTC)
commit 4210652d472cb162a9dc3c71c01bcb5c54080438
Author: Jordi Mas <jmas softcatala org>
Date: Sun Nov 21 11:30:29 2010 +0100
Initial PDF export support
gbrainy.csproj | 10 ++-
po/POTFILES.in | 3 +
src/Clients/Classical/Dialogs/AboutDialog.cs | 2 +-
src/Clients/Classical/Dialogs/BuilderDialog.cs | 2 +-
src/Clients/Classical/Dialogs/CustomGameDialog.cs | 3 +-
src/Clients/Classical/Dialogs/HigMessageDialog.cs | 2 +-
.../Classical/Dialogs/PlayerHistoryDialog.cs | 2 +-
src/Clients/Classical/Dialogs/PreferencesDialog.cs | 2 +-
src/Clients/Classical/Makefile.am | 12 ++-
src/Clients/Classical/SimpleLabel.cs | 100 --------------------
src/Clients/Classical/gbrainy.cs | 13 +++-
src/Clients/Classical/gbrainy.ui | 17 +++-
src/Core/Core.csproj | 1 +
src/Core/Libraries/CairoContext.cs | 26 ++++--
src/Core/Main/GameManager.cs | 60 ------------
src/Core/Main/Xml/GameXml.cs | 5 -
src/Core/Makefile.am | 1 +
17 files changed, 74 insertions(+), 187 deletions(-)
---
diff --git a/gbrainy.csproj b/gbrainy.csproj
index 1451909..fb0d79d 100644
--- a/gbrainy.csproj
+++ b/gbrainy.csproj
@@ -31,26 +31,30 @@
<ItemGroup>
<Reference Include="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
<SpecificVersion>False</SpecificVersion>
+ <Package>gtk-sharp-2.0</Package>
</Reference>
<Reference Include="gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
<SpecificVersion>False</SpecificVersion>
+ <Package>gtk-sharp-2.0</Package>
</Reference>
<Reference Include="glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
<SpecificVersion>False</SpecificVersion>
+ <Package>glib-sharp-2.0</Package>
</Reference>
<Reference Include="pango-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
<SpecificVersion>False</SpecificVersion>
+ <Package>gtk-sharp-2.0</Package>
</Reference>
<Reference Include="Mono.Posix" />
<Reference Include="Mono.Cairo" />
<Reference Include="atk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
+ <Package>gtk-sharp-2.0</Package>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="src\Clients\Classical\gbrainy.cs" />
<Compile Include="src\Clients\Classical\GtkSynchronize.cs" />
- <Compile Include="src\Clients\Classical\SimpleLabel.cs" />
<Compile Include="src\Clients\Classical\Dialogs\CustomGameDialog.cs" />
<Compile Include="src\Clients\Classical\Dialogs\PlayerHistoryDialog.cs" />
<Compile Include="src\Clients\Classical\Dialogs\AboutDialog.cs" />
@@ -63,11 +67,15 @@
<Compile Include="src\Clients\Classical\Defines.cs" />
<Compile Include="src\Clients\Classical\Dialogs\HigMessageDialog.cs" />
<Compile Include="src\Clients\Classical\CommandLine.cs" />
+ <Compile Include="src\Clients\Classical\Widgets\BrowseFile.cs" />
+ <Compile Include="src\Clients\Classical\Widgets\SimpleLabel.cs" />
+ <Compile Include="src\Clients\Classical\Dialogs\PdfExportDialog.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<None Include="data\game-graphics\handshake.svg" />
<None Include="data\game-graphics\present.svg" />
+ <None Include="src\Clients\Classical\Dialogs\ui\PdfExportDialog.ui" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="src\Clients\Classical\gbrainy.ui">
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3258ac1..059cf46 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -29,11 +29,14 @@ src/Clients/Classical/gbrainy.cs
src/Clients/Classical/CommandLine.cs
src/Clients/Classical/Dialogs/AboutDialog.cs
src/Clients/Classical/Dialogs/CustomGameDialog.cs
+src/Clients/Classical/Dialogs/PdfExportDialog.cs
src/Clients/Classical/Dialogs/PlayerHistoryDialog.cs
src/Clients/Classical/Dialogs/PreferencesDialog.cs
[type: gettext/glade] src/Clients/Classical/Dialogs/ui/CustomGameDialog.ui
+[type: gettext/glade] src/Clients/Classical/Dialogs/ui/PdfExportDialog.ui
[type: gettext/glade] src/Clients/Classical/Dialogs/ui/PlayerHistoryDialog.ui
[type: gettext/glade] src/Clients/Classical/Dialogs/ui/PreferencesDialog.ui
+src/Clients/Classical/Widgets/BrowseFile.cs
src/Games/Logic/Puzzle3DCube.cs
src/Games/Logic/PuzzleBalance.cs
src/Games/Logic/PuzzleBuildTriangle.cs
diff --git a/src/Clients/Classical/Dialogs/AboutDialog.cs b/src/Clients/Classical/Dialogs/AboutDialog.cs
index 9096bb9..7bf2082 100644
--- a/src/Clients/Classical/Dialogs/AboutDialog.cs
+++ b/src/Clients/Classical/Dialogs/AboutDialog.cs
@@ -23,7 +23,7 @@ using Gdk;
using Mono.Unix;
using System.Text;
-namespace gbrainy.Clients.Classical
+namespace gbrainy.Clients.Classical.Dialogs
{
public class AboutDialog : Gtk.AboutDialog
{
diff --git a/src/Clients/Classical/Dialogs/BuilderDialog.cs b/src/Clients/Classical/Dialogs/BuilderDialog.cs
index b5126eb..ea26339 100644
--- a/src/Clients/Classical/Dialogs/BuilderDialog.cs
+++ b/src/Clients/Classical/Dialogs/BuilderDialog.cs
@@ -20,7 +20,7 @@
using Gtk;
using GtkBeans;
-namespace gbrainy.Clients.Classical
+namespace gbrainy.Clients.Classical.Dialogs
{
public class BuilderDialog : Gtk.Dialog
{
diff --git a/src/Clients/Classical/Dialogs/CustomGameDialog.cs b/src/Clients/Classical/Dialogs/CustomGameDialog.cs
index 4565554..565d65d 100644
--- a/src/Clients/Classical/Dialogs/CustomGameDialog.cs
+++ b/src/Clients/Classical/Dialogs/CustomGameDialog.cs
@@ -23,8 +23,9 @@ using Mono.Unix;
using System.Collections.Generic;
using gbrainy.Core.Main;
+using gbrainy.Clients.Classical.Widgets;
-namespace gbrainy.Clients.Classical
+namespace gbrainy.Clients.Classical.Dialogs
{
public class CustomGameDialog : BuilderDialog
{
diff --git a/src/Clients/Classical/Dialogs/HigMessageDialog.cs b/src/Clients/Classical/Dialogs/HigMessageDialog.cs
index b7d002e..3e48b16 100644
--- a/src/Clients/Classical/Dialogs/HigMessageDialog.cs
+++ b/src/Clients/Classical/Dialogs/HigMessageDialog.cs
@@ -22,7 +22,7 @@
using System;
using Gtk;
-namespace gbrainy.Clients.Classical
+namespace gbrainy.Clients.Classical.Dialogs
{
public class HigMessageDialog : Gtk.Dialog
{
diff --git a/src/Clients/Classical/Dialogs/PlayerHistoryDialog.cs b/src/Clients/Classical/Dialogs/PlayerHistoryDialog.cs
index 6b61e02..7edaf3e 100644
--- a/src/Clients/Classical/Dialogs/PlayerHistoryDialog.cs
+++ b/src/Clients/Classical/Dialogs/PlayerHistoryDialog.cs
@@ -24,7 +24,7 @@ using Mono.Unix;
using gbrainy.Core.Main;
using gbrainy.Core.Views;
-namespace gbrainy.Clients.Classical
+namespace gbrainy.Clients.Classical.Dialogs
{
public class PlayerHistoryDialog : BuilderDialog
{
diff --git a/src/Clients/Classical/Dialogs/PreferencesDialog.cs b/src/Clients/Classical/Dialogs/PreferencesDialog.cs
index 3f5cae6..650f72b 100644
--- a/src/Clients/Classical/Dialogs/PreferencesDialog.cs
+++ b/src/Clients/Classical/Dialogs/PreferencesDialog.cs
@@ -23,7 +23,7 @@ using Mono.Unix;
using gbrainy.Core.Main;
-namespace gbrainy.Clients.Classical
+namespace gbrainy.Clients.Classical.Dialogs
{
public class PreferencesDialog : BuilderDialog
{
diff --git a/src/Clients/Classical/Makefile.am b/src/Clients/Classical/Makefile.am
index f28c6d1..cd70a75 100644
--- a/src/Clients/Classical/Makefile.am
+++ b/src/Clients/Classical/Makefile.am
@@ -7,7 +7,6 @@ GBRAINY_CSDISTFILES = \
$(srcdir)/CommandLine.cs \
$(srcdir)/gbrainy.cs \
$(srcdir)/GtkSynchronize.cs \
- $(srcdir)/SimpleLabel.cs \
$(srcdir)/Builder/Builder.cs \
$(srcdir)/Builder/BuilderConnectFunc.cs \
$(srcdir)/Builder/GtkBeansSharp.BuilderConnectFuncNative.cs \
@@ -17,7 +16,11 @@ GBRAINY_CSDISTFILES = \
$(srcdir)/Dialogs/BuilderDialog.cs \
$(srcdir)/Dialogs/HigMessageDialog.cs \
$(srcdir)/Dialogs/PlayerHistoryDialog.cs \
- $(srcdir)/Dialogs/PreferencesDialog.cs
+ $(srcdir)/Dialogs/PreferencesDialog.cs \
+ $(srcdir)/Dialogs/PdfExportDialog.cs \
+ $(srcdir)/Widgets/SimpleLabel.cs \
+ $(srcdir)/Widgets/BrowseFile.cs
+
ASSEMBLIES = \
$(GBRAINY_LIBS) \
@@ -31,6 +34,7 @@ RESOURCES = \
-resource:$(srcdir)/Dialogs/ui/PreferencesDialog.ui \
-resource:$(srcdir)/Dialogs/ui/PlayerHistoryDialog.ui \
-resource:$(srcdir)/Dialogs/ui/CustomGameDialog.ui \
+-resource:$(srcdir)/Dialogs/ui/PdfExportDialog.ui \
-resource:$(top_srcdir)/data/app-graphics/resume-32.png \
-resource:$(top_srcdir)/data/app-graphics/endgame-32.png \
-resource:$(top_srcdir)/data/app-graphics/pause-32.png \
@@ -52,7 +56,8 @@ GBRAINY_CSFILES = $(GBRAINY_CSDISTFILES) \
Defines.cs
../../gbrainy.exe: $(GBRAINY_CSFILES) gbrainy.ui $(srcdir)/Dialogs/ui/PreferencesDialog.ui \
- $(srcdir)/Dialogs/ui/PlayerHistoryDialog.ui $(srcdir)/Dialogs/ui/CustomGameDialog.ui
+ $(srcdir)/Dialogs/ui/PlayerHistoryDialog.ui $(srcdir)/Dialogs/ui/CustomGameDialog.ui \
+ $(srcdir)/Dialogs/ui/PdfExportDialog.ui
$(CSC) -target:winexe -out:$@ $(EXTRAFLAGS) $(GBRAINY_CSFILES) $(ASSEMBLIES) $(RESOURCES)
$(TARGET_CFG): gbrainy.exe.config.in
@@ -69,6 +74,7 @@ EXTRA_DIST = \
$(srcdir)/Dialogs/ui/PreferencesDialog.ui \
$(srcdir)/Dialogs/ui/PlayerHistoryDialog.ui \
$(srcdir)/Dialogs/ui/CustomGameDialog.ui \
+ $(srcdir)/Dialogs/ui/PdfExportDialog.ui \
$(GBRAINY_CSDISTFILES)
diff --git a/src/Clients/Classical/gbrainy.cs b/src/Clients/Classical/gbrainy.cs
index 446b4b6..0e22ba4 100755
--- a/src/Clients/Classical/gbrainy.cs
+++ b/src/Clients/Classical/gbrainy.cs
@@ -26,6 +26,8 @@ using Gdk;
using gbrainy.Core.Main;
using gbrainy.Core.Platform;
+using gbrainy.Clients.Classical.Dialogs;
+using gbrainy.Clients.Classical.Widgets;
#if MONO_ADDINS
using Mono.Addins;
@@ -465,7 +467,7 @@ namespace gbrainy.Clients.Classical
void OnMenuAbout (object sender, EventArgs args)
{
- AboutDialog about = new AboutDialog ();
+ Dialogs.AboutDialog about = new Dialogs.AboutDialog ();
about.Run ();
}
@@ -562,6 +564,15 @@ namespace gbrainy.Clients.Classical
OnNewGame (GameSession.Types.MemoryTrainers);
}
+ void OnPdfExport (object sender, EventArgs args)
+ {
+ PdfExportDialog pdf;
+
+ pdf = new PdfExportDialog ();
+ pdf.Run ();
+ pdf.Destroy ();
+ }
+
void OnPreferences (object sender, EventArgs args)
{
PreferencesDialog dialog;
diff --git a/src/Clients/Classical/gbrainy.ui b/src/Clients/Classical/gbrainy.ui
index acb30f4..745fa63 100644
--- a/src/Clients/Classical/gbrainy.ui
+++ b/src/Clients/Classical/gbrainy.ui
@@ -21,13 +21,11 @@
<property name="step_increment">1</property>
</object>
<object class="GtkWindow" id="gbrainy">
- <property name="visible">False</property>
<property name="title" translatable="yes">gbrainy</property>
<signal name="delete_event" handler="OnDeleteWindow"/>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
<child>
<object class="GtkMenuBar" id="menubar1">
<property name="visible">True</property>
@@ -122,6 +120,19 @@
</object>
</child>
<child>
+ <object class="GtkMenuItem" id="pdf_export_menuitem">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Export Games to PDF for Off-line Playing...</property>
+ <property name="use_underline">True</property>
+ <signal name="activate" handler="OnPdfExport"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparatorMenuItem" id="separatormenuitem3">
+ <property name="visible">True</property>
+ </object>
+ </child>
+ <child>
<object class="GtkImageMenuItem" id="imagemenuitem5">
<property name="label">gtk-quit</property>
<property name="visible">True</property>
@@ -153,7 +164,7 @@
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem6">
- <property name="label" translatable="yes" >Player's Game Session History</property>
+ <property name="label" translatable="yes">Player's Game Session History</property>
<property name="visible">True</property>
<property name="use_stock">False</property>
<signal name="activate" handler="OnHistory"/>
diff --git a/src/Core/Core.csproj b/src/Core/Core.csproj
index 30c8f99..c332f89 100644
--- a/src/Core/Core.csproj
+++ b/src/Core/Core.csproj
@@ -102,6 +102,7 @@
<Compile Include="Main\Xml\LocalizableString.cs" />
<Compile Include="Main\Xml\TextDrawingObject.cs" />
<Compile Include="Main\Xml\DrawingObject.cs" />
+ <Compile Include="Main\PdfExporter.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
diff --git a/src/Core/Libraries/CairoContext.cs b/src/Core/Libraries/CairoContext.cs
index cca5d34..9b76116 100644
--- a/src/Core/Libraries/CairoContext.cs
+++ b/src/Core/Libraries/CairoContext.cs
@@ -59,6 +59,9 @@ namespace gbrainy.Core.Libraries
}
}
+ // True if we want Pango to process XML entites and formatting attributes
+ public bool UseMarkup { get; set; }
+
// No dispose of resources on this class
protected override void Dispose (bool disposing)
{
@@ -80,7 +83,14 @@ namespace gbrainy.Core.Libraries
and Pango paints on the top-left of the coordinates
*/
-
+ void SetText (string text)
+ {
+ if (UseMarkup)
+ layout.SetMarkup (text);
+ else
+ layout.SetText (text);
+ }
+
// Shows a text from the current position. No Width defined then no RTL positioning
public void ShowPangoText (string str)
{
@@ -88,7 +98,7 @@ namespace gbrainy.Core.Libraries
UpdateFontSize ();
Matrix = new Cairo.Matrix ();
- layout.SetText (str);
+ SetText (str);
layout.SingleParagraphMode = true;
Pango.CairoHelper.ShowLayout (this, layout);
Matrix = old;
@@ -115,7 +125,7 @@ namespace gbrainy.Core.Libraries
UpdateFontSize ();
Matrix = new Cairo.Matrix ();
Rotate (rotation);
- layout.SetText (str);
+ SetText (str);
layout.SingleParagraphMode = true;
Pango.CairoHelper.ShowLayout (this, layout);
@@ -147,7 +157,7 @@ namespace gbrainy.Core.Libraries
UpdateFontSize ();
Matrix = new Cairo.Matrix ();
- layout.SetText (str);
+ SetText (str);
layout.SingleParagraphMode = true;
layout.Width = -1;
layout.GetPixelSize (out w, out h);
@@ -165,7 +175,7 @@ namespace gbrainy.Core.Libraries
UpdateFontSize ();
Matrix = new Cairo.Matrix ();
- layout.SetText (str);
+ SetText (str);
layout.SingleParagraphMode = true;
layout.Width = -1;
layout.GetPixelSize (out w, out h);
@@ -179,7 +189,7 @@ namespace gbrainy.Core.Libraries
int w, h;
Cairo.Matrix old = Matrix;
- if (max_width < 0 || max_width > 1)
+ if (max_width < 0 )
throw new ArgumentOutOfRangeException ("Invalid maximum width value");
MoveTo (x, y);
@@ -190,7 +200,7 @@ namespace gbrainy.Core.Libraries
layout.Spacing = (int) (line_spacing * (old.Yy * Pango.Scale.PangoScale));
layout.SingleParagraphMode = false;
- layout.SetText (str);
+ SetText (str);
Pango.CairoHelper.ShowLayout (this, layout);
layout.GetPixelSize (out w, out h);
Matrix = old;
@@ -211,7 +221,7 @@ namespace gbrainy.Core.Libraries
layout.Spacing = (int) (line_spacing * (old.Xx * Pango.Scale.PangoScale));
layout.SingleParagraphMode = !wrapping;
- layout.SetText (str);
+ SetText (str);
layout.GetPixelSize (out w, out h);
Matrix = old;
height = h / old.Yy;
diff --git a/src/Core/Main/GameManager.cs b/src/Core/Main/GameManager.cs
index db6e8e3..8c68e54 100644
--- a/src/Core/Main/GameManager.cs
+++ b/src/Core/Main/GameManager.cs
@@ -22,12 +22,6 @@ using System.Collections.Generic;
using System.Reflection;
using Mono.Unix;
-// When defined, exports all the games in a single PDF
-#if PDF_DUMP
-using Cairo;
-using gbrainy.Core.Libraries;
-#endif
-
#if MONO_ADDINS
using Mono.Addins;
using Mono.Addins.Setup;
@@ -488,59 +482,5 @@ namespace gbrainy.Core.Main
puzzle.CurrentDifficulty = Difficulty;
return puzzle;
}
-#if PDF_DUMP
- // Generates a single PDF document with all the puzzles contained in gbrainy (4 games per page)
- public void GeneratePDF ()
- {
- int width = 400, height = 400, margin = 20, x, y, cnt, games_page = 4;
- Game puzzle;
- game_type = GameSession.Types.AllGames;
- GameManager.GameLocator [] games;
-
-
- games = AvailableGames;
-
- PdfSurface pdf = new PdfSurface ("games.pdf", (width + margin) * 2, (height + margin) * games_page / 2);
- x = y = cnt = 0;
- CairoContextEx cr = new CairoContextEx (pdf, "sans 12", 72);
-
- for (int i = 0; i < games.Length; i++)
- {
- if (games[i].IsGame == false)
- continue;
-
- puzzle = (Game) Activator.CreateInstance (games[i].TypeOf, true);
- puzzle.Variant = games[i].Variant;
-
- puzzle.Begin ();
-
- cnt++;
- cr.Save ();
- cr.Translate (x, y);
- cr.Rectangle (0, 0, width, height);;
- cr.Clip ();
- cr.Save ();
- puzzle.DrawPreview (cr, width, height, false);
- x += width + margin;
- if (x > width + margin) {
- x = 0;
- y += height + margin;
- }
- cr.Restore ();
- cr.MoveTo (50, height - 10);
- cr.ShowText (String.Format ("Game: {0} / D:{1}", puzzle.Name, puzzle.GameDifficulty));
- cr.Stroke ();
- cr.Restore ();
-
- if (cnt >= games_page) {
- cr.ShowPage ();
- cnt = x = y = 0;
- }
- }
- pdf.Finish ();
- ((IDisposable)cr).Dispose();
- return;
- }
-#endif
}
}
diff --git a/src/Core/Main/Xml/GameXml.cs b/src/Core/Main/Xml/GameXml.cs
index dba3e55..389a515 100644
--- a/src/Core/Main/Xml/GameXml.cs
+++ b/src/Core/Main/Xml/GameXml.cs
@@ -215,8 +215,6 @@ namespace gbrainy.Core.Main.Xml
}
}
- string q;
-
for (int i = 0; i < options.Count - 1; i++)
answers += String.Format (Catalog.GetString ("{0}, "), GetPossibleAnswer (i));
@@ -284,7 +282,6 @@ namespace gbrainy.Core.Main.Xml
{
OptionDrawingObject [] originals;
ArrayListIndicesRandom random_indices;
- DrawingObject temporary;
int index = 0;
random_indices = new ArrayListIndicesRandom (randomized_options);
@@ -358,8 +355,6 @@ namespace gbrainy.Core.Main.Xml
return;
OptionDrawingObject _option = options [idx];
- Widget widget = (Widget) sender;
-
e.Context.SetPangoLargeFontSize ();
DrawObjects (e.Context, _option.DrawingObjects, idx);
diff --git a/src/Core/Makefile.am b/src/Core/Makefile.am
index cec80e5..499bb66 100644
--- a/src/Core/Makefile.am
+++ b/src/Core/Makefile.am
@@ -31,6 +31,7 @@ CSDISTFILES = \
$(srcdir)/Main/Xml/OptionDrawingObject.cs \
$(srcdir)/Main/Xml/TextDrawingObject.cs \
$(srcdir)/Main/Memory.cs \
+ $(srcdir)/Main/PdfExporter.cs \
$(srcdir)/Main/PlayerHistory.cs \
$(srcdir)/Main/PlayerPersonalRecord.cs \
$(srcdir)/Main/Preferences.cs \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]