]> git.lyx.org Git - features.git/commitdiff
Added the formatting of the credits text.
authorBaruch Even <baruch@lyx.org>
Sat, 31 Mar 2001 15:59:17 +0000 (15:59 +0000)
committerBaruch Even <baruch@lyx.org>
Sat, 31 Mar 2001 15:59:17 +0000 (15:59 +0000)
Currently there is no check if the needed font exists or not, the worst is
that everything is rendered in the regular font.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1866 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/gnome/ChangeLog
src/frontends/gnome/FormCredits.C
src/frontends/gnome/Makefile.am
src/frontends/gnome/dialogs/diahelpcredits.glade
src/frontends/gnome/gnome_helpers.h

index b69bb20c67535475f5419b06fd0f0ee2ea348f03..bae1f4078ceebe80d0cc5def8bf40d82b9a5b327 100644 (file)
@@ -1,3 +1,9 @@
+2001-03-30  Baruch Even  <baruch@lyx.org>
+
+       * FormCredits.C: Added the formatting of the credits text.
+
+       * gnome_helpers.[Ch]: Added functions to get font name from font.
+
 2001-03-30  Baruch Even  <baruch@lyx.org>
 
        * GnomeBase.[Ch]: Added the dialog as a responsibility.
index f40f7ae948b644d4a7b27fba60d0c0721530c1cf..af913b225483b8acae877cf406c9690f79cf4c65 100644 (file)
 
 #include <config.h>
 
+#include "debug.h"
+
 #include "gnomeBC.h"
 #include "FormCredits.h"
+#include "gnome_helpers.h"
 
 #include <gtk--/button.h>
 #include <gtk--/text.h>
+#include <gtk--/style.h>
 
 FormCredits::FormCredits(ControlCredits & c)
        : FormCB<ControlCredits>(c, "diahelpcredits.glade", "DiaHelpCredits")
@@ -34,8 +38,59 @@ void FormCredits::build()
        // get a click on "Cancel"
        ok()->clicked.connect(SigC::slot(this, &FormCredits::CancelClicked));
 
+       // Do not update the dialog when we insert the text
+       text()->freeze();
+       
+       // Get the credits into the string stream
        std::stringstream ss;
-       text()->insert(controller().getCredits(ss).str());
+       string credits = controller().getCredits(ss).str();
+
+       // Create the strings that we need to detect.
+       string const bold("@b");
+       string const italic("@i");
+
+       // Create the drawing contexts.
+       Gtk::Text_Helpers::Context c_italic;
+       Gtk::Text_Helpers::Context c_bold;
+
+       {
+               string bold = get_font_name(text()->get_style()->get_font());
+               //lyxerr << "Font name: " << bold << std::endl;
+               string italic(bold);
+
+               string const medium("Medium-");
+               std::string::size_type index = bold.find(medium);
+               bold.replace(index, medium.size()-1, "bold");
+
+               string const r("R-");
+               index = italic.find(r);
+               italic.replace(index, r.size()-1, "i");
+               
+               //lyxerr << "Bold: " << bold << "\nItalic: " << italic << std::endl;
+               c_bold.set_font(Gdk_Font(bold));
+               c_italic.set_font(Gdk_Font(italic));
+       }
+
+       // Insert it into the text and parse the attributes.
+       while (!credits.empty()) {
+               std::string::size_type end = credits.find('\n');
+               string const line = credits.substr(0, ++end);
+               credits = credits.substr(end);
+               
+//             lyxerr << "Line got: '" << line << "'\nend = " << end << std::endl;
+               
+               string const prefix = line.substr(0, 2);
+               if (prefix == bold) {
+                       text()->insert(c_bold, line.substr(2));
+               } else if (prefix == italic) {
+                       text()->insert(c_italic, line.substr(2));
+               } else {
+                       text()->insert(line);
+               }
+       }
+       
+       // Allow the text area to be drawn.
+       text()->thaw();
 }
 
 
index 8338d1132b6278857a61337e72436c3762633217..29c1335520b4f445e838f4f49d5f961e127d1f29 100644 (file)
@@ -73,6 +73,7 @@ libgnome_la_SOURCES = \
        Timeout_pimpl.h \
        gnomeBC.C \
        gnomeBC.h \
+       gnome_helpers.C \
        gnome_helpers.h \
        mainapp.C \
        mainapp.h \
index f3d22547d0e54ed9d0c3a35053736d1be7abcd63..4883e4d95f1624037d33493c94c0000d7a21e9c0 100644 (file)
@@ -26,6 +26,7 @@
   <type>GTK_WINDOW_DIALOG</type>
   <position>GTK_WIN_POS_NONE</position>
   <modal>False</modal>
+  <default_width>330</default_width>
   <default_height>300</default_height>
   <allow_shrink>True</allow_shrink>
   <allow_grow>True</allow_grow>
@@ -121,8 +122,7 @@ Matthias</label>
          <name>credits_text</name>
          <can_focus>True</can_focus>
          <editable>False</editable>
-         <text>
-</text>
+         <text></text>
        </widget>
       </widget>
     </widget>
index e6a89dca08732b19cf4187f896e4544420454660..8c7094e0fe52cb25929634090171416502d7d1be 100644 (file)
 #include <glib.h>
 
 // Glade Helper Function.  
+
+
+/** This function will get a widget from the glade XML representation and
+ * will wrap it into the gtk--/gnome-- representation.
+ */
 template<class T>
 T* getWidgetPtr(GladeXML* xml, char const * name)
 {   
@@ -31,6 +36,19 @@ T* getWidgetPtr(GladeXML* xml, char const * name)
        return result;
 }
 
+class Gdk_Font;
+
+/** Takes a Gdk::Font object reference and returns the name associated
+ * with the font it holds.
+ */
+string get_font_name(Gdk_Font const & font);
 
 
+/** Takes a GdkFont pointer and returns the name associated with the font
+ * it holds. It returns a newly allocated gchar* string.
+ *
+ * This function was lifted from e-font.c from the gabber package.
+ */
+gchar * get_font_name(GdkFont const * font);
+
 #endif