Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

support custom fonts and importing of google web fonts

  • Loading branch information...
commit 736a65b533b07c898a1854b0f3a5f81f877f8e50 1 parent 7f27b8d
JJ Allaire jjallaire authored
10 src/cpp/session/modules/presentation/SlideParser.cpp
View
@@ -74,6 +74,8 @@ bool isValidField(const std::string& name)
boost::iequals(name, "author") ||
boost::iequals(name, "date") ||
boost::iequals(name, "transition") ||
+ boost::iequals(name, "font-family") ||
+ boost::iequals(name, "font-import") ||
boost::iequals(name, "navigation") ||
boost::iequals(name, "incremental") ||
boost::iequals(name, "id") ||
@@ -225,6 +227,14 @@ std::string SlideDeck::title() const
return std::string();
}
+std::string SlideDeck::fontFamily() const
+{
+ if (!slides_.empty())
+ return slides_[0].fontFamily();
+ else
+ return std::string();
+}
+
std::string SlideDeck::transition() const
{
if (!slides_.empty())
12 src/cpp/session/modules/presentation/SlideParser.hpp
View
@@ -77,20 +77,24 @@ class Slide
{
}
+public:
+ // title
std::string title() const { return title_; }
bool showTitle() const;
- // title slide fields
std::string author() const { return fieldValue("author"); }
std::string date() const { return fieldValue("date"); }
+ std::string fontFamily() const { return fieldValue("font-family"); }
std::string transition() const;
std::string navigation() const { return fieldValue("navigation", "slides"); }
+
+public:
+ // global/local fields
std::string incremental() const { return fieldValue("incremental"); }
+ // local fields
std::string id() const { return fieldValue("id"); }
-
std::string type() const { return fieldValue("type"); }
-
std::string video() const { return fieldValue("video"); }
std::string audio() const { return fieldValue("audio"); }
@@ -122,6 +126,8 @@ class SlideDeck
std::string title() const;
+ std::string fontFamily() const;
+
std::string transition() const;
std::string navigation() const;
std::string incremental() const;
46 src/cpp/session/modules/presentation/SlideRequestHandler.cpp
View
@@ -50,6 +50,9 @@ namespace presentation {
namespace {
+const char * const kDefaultRevealFont = "\"Lato\"";
+const char * const kDefaultRevealHeadingFont = "\"News Cycle\"";
+
class ResourceFiles : boost::noncopyable
{
private:
@@ -509,6 +512,40 @@ void viewInBrowserVars(const std::string& slides,
vars["mathjax"] = "";
}
+void fontVars(const SlideDeck& slideDeck,
+ std::map<std::string,std::string>* pVars)
+{
+ std::map<std::string,std::string>& vars = *pVars;
+
+ // font imports
+ vars["user_font_imports"] = std::string();
+ if (slideDeck.slides().size() > 0)
+ {
+ std::ostringstream ostr;
+ std::vector<std::string> fontImports =
+ slideDeck.slides().at(0).fieldValues("font-import");
+
+ BOOST_FOREACH(const std::string& fontImport, fontImports)
+ {
+ ostr << "@import url('" << fontImport << "');" << std::endl;
+ }
+
+ vars["user_font_imports"] = ostr.str();
+ }
+
+ // fonts
+ if (!slideDeck.fontFamily().empty())
+ {
+ vars["reveal_font"] = slideDeck.fontFamily();
+ vars["reveal_heading_font"] = slideDeck.fontFamily();
+ }
+ else
+ {
+ vars["reveal_font"] = kDefaultRevealFont;
+ vars["reveal_heading_font"] = kDefaultRevealHeadingFont;
+ }
+}
+
void localRevealVars(std::map<std::string,std::string>* pVars)
{
@@ -564,6 +601,9 @@ bool createStandalonePresentation(const FilePath& targetFile,
vars["reveal_head_js"] = revealEmbed("revealjs/lib/js/head.min.js");
vars["reveal_js"] = revealEmbed("revealjs/js/reveal.min.js");
+ // font vars
+ fontVars(slideDeck, &vars);
+
// call var source hook function
varSource(targetFile, slides, &vars);
@@ -636,6 +676,9 @@ void handlePresentationRootRequest(const std::string& path,
// linked versions of reveal assets
localRevealVars(&vars);
+ // font vars
+ fontVars(slideDeck, &vars);
+
// no print css for qtwebkit
vars["reveal_print_css"] = "";
@@ -807,6 +850,9 @@ void handlePresentationViewInBrowserRequest(const http::Request& request,
// linked versions of reveal assets
localRevealVars(&vars);
+ // font vars
+ fontVars(slideDeck, &vars);
+
// link to reveal print css
vars["reveal_print_css"] = "";
14 src/cpp/session/resources/presentation/slides.html
View
@@ -14,6 +14,7 @@
<!-- web fonts -->
<style type="text/css">
#!google_webfonts#
+#!user_font_imports#
</style>
<!-- reveal.js -->
@@ -22,6 +23,19 @@
<style type="text/css">
#!slides_css#
+
+.reveal {
+ font-family: #!reveal_font#, Times, "Times New Roman", serif;
+}
+
+.reveal h1,
+.reveal h2,
+.reveal h3,
+.reveal h4,
+.reveal h5,
+.reveal h6 {
+ font-family: #!reveal_heading_font#, Impact, sans-serif;
+}
</style>
<!-- reveal print css -->
Please sign in to comment.
Something went wrong with that request. Please try again.