From fc19a773539b63c3eecd3a6ca5c24a70c5e6df36 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Wed, 10 Oct 2012 10:45:39 +0100 Subject: [PATCH] Added support for PDF images --- core/boot.js | 5 +++++ core/modules/parsers/imageparser.js | 11 ++++++++--- core/styles/tiddlywiki.css | 8 +++++++- cssbuild/tiddlywiki.less | 7 ++++++- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/core/boot.js b/core/boot.js index b8c819ca5..cc54802e8 100644 --- a/core/boot.js +++ b/core/boot.js @@ -81,6 +81,9 @@ $tw.modules = $tw.modules || {}; $tw.modules.titles = $tw.modules.titles || {}; // hashmap by module title of {fn:, exports:, moduleType:} $tw.modules.types = $tw.modules.types || {}; // hashmap by module type of array of exports +// Plugin information +$tw.plugins = $tw.plugins || {}; + // Config object $tw.config = $tw.config || {}; @@ -102,6 +105,7 @@ $tw.config.fileExtensionInfo = { ".html": {type: "text/html"}, ".js": {type: "application/javascript"}, ".json": {type: "application/json"}, + ".pdf": {type: "application/pdf"}, ".jpg": {type: "image/jpeg"}, ".jpeg": {type: "image/jpeg"}, ".png": {type: "image/png"}, @@ -119,6 +123,7 @@ $tw.config.contentTypeInfo = { "text/html": {encoding: "utf8"}, "application/javascript": {encoding: "utf8"}, "application/json": {encoding: "utf8"}, + "application/pdf": {encoding: "base64"}, "image/jpeg": {encoding: "base64"}, "image/png": {encoding: "base64"}, "image/gif": {encoding: "base64"}, diff --git a/core/modules/parsers/imageparser.js b/core/modules/parsers/imageparser.js index 9e1c5924b..03afda8f9 100644 --- a/core/modules/parsers/imageparser.js +++ b/core/modules/parsers/imageparser.js @@ -17,13 +17,17 @@ var ImageParser = function(options) { }; ImageParser.prototype.parse = function(type,text) { - var src; - if(type === "image/svg+xml" || type === ".svg") { + var element = "img", + src; + if(type === "application/pdf" || type === ".pdf") { + src = "data:application/pdf;base64," + text; + element = "embed"; + } else if(type === "image/svg+xml" || type === ".svg") { src = "data:image/svg+xml," + encodeURIComponent(text); } else { src = "data:" + type + ";base64," + text; } - return new $tw.Renderer([$tw.Tree.Element("img",{src: src})],new $tw.Dependencies()); + return new $tw.Renderer([$tw.Tree.Element(element,{src: src})],new $tw.Dependencies()); }; exports["image/svg+xml"] = ImageParser; @@ -31,5 +35,6 @@ exports["image/jpg"] = ImageParser; exports["image/jpeg"] = ImageParser; exports["image/png"] = ImageParser; exports["image/gif"] = ImageParser; +exports["application/pdf"] = ImageParser; })(); diff --git a/core/styles/tiddlywiki.css b/core/styles/tiddlywiki.css index 1e29bd3fa..65f19c494 100644 --- a/core/styles/tiddlywiki.css +++ b/core/styles/tiddlywiki.css @@ -5103,10 +5103,16 @@ canvas.tw-edit-field { } img, -canvas { +canvas, +embed { max-width: 100%; } +embed { + width: 100%; + height: 20em; +} + a.tw-tiddlylink { font-style: normal; font-weight: normal; diff --git a/cssbuild/tiddlywiki.less b/cssbuild/tiddlywiki.less index 31885f295..ce7e22af4 100644 --- a/cssbuild/tiddlywiki.less +++ b/cssbuild/tiddlywiki.less @@ -119,10 +119,15 @@ canvas.tw-edit-field { -ms-user-select: none; } -img, canvas { +img, canvas, embed { max-width: 100%; } +embed { + width: 100%; + height: 20em; +} + a.tw-tiddlylink { font-style: normal; font-weight: normal;