~ubuntu-branches/debian/experimental/calibre/experimental

« back to all changes in this revision

Viewing changes to resources/viewer/mathjax/jax/output/SVG/autoload/mglyph.js

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2012-10-03 23:18:14 UTC
  • mfrom: (1.3.36)
  • Revision ID: package-import@ubuntu.com-20121003231814-i67zl632zxlj4qn1
Tags: 0.9.0+dfsg-1
* New upstream release.
* debian/control, debian/rules: ttf-liberation is no more, move to
  fonts-liberation. Thanks to Kan-Ru Chen! (Closes: #674838)
* debian/calibre.install: Drop pyPdf, not shipped upstream any more.
* debian/control: Add new python-netifaces dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*************************************************************
 
2
 *
 
3
 *  MathJax/jax/output/SVG/autoload/mglyph.js
 
4
 *  
 
5
 *  Implements the SVG output for <mglyph> elements.
 
6
 *
 
7
 *  ---------------------------------------------------------------------
 
8
 *  
 
9
 *  Copyright (c) 2011-2012 Design Science, Inc.
 
10
 * 
 
11
 *  Licensed under the Apache License, Version 2.0 (the "License");
 
12
 *  you may not use this file except in compliance with the License.
 
13
 *  You may obtain a copy of the License at
 
14
 * 
 
15
 *      http://www.apache.org/licenses/LICENSE-2.0
 
16
 * 
 
17
 *  Unless required by applicable law or agreed to in writing, software
 
18
 *  distributed under the License is distributed on an "AS IS" BASIS,
 
19
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
20
 *  See the License for the specific language governing permissions and
 
21
 *  limitations under the License.
 
22
 */
 
23
 
 
24
MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
 
25
  var VERSION = "2.0";
 
26
  var MML = MathJax.ElementJax.mml,
 
27
      SVG = MathJax.OutputJax.SVG,
 
28
      BBOX = SVG.BBOX;
 
29
  
 
30
  var XLINKNS = "http://www.w3.org/1999/xlink";
 
31
 
 
32
  BBOX.MGLYPH = BBOX.Subclass({
 
33
    type: "image", removeable: false,
 
34
    Init: function (img,w,h,align,mu,def) {
 
35
      if (def == null) {def = {}}
 
36
      var W = img.width*1000/SVG.em, H = img.height*1000/SVG.em, y = 0;
 
37
      if (w !== "") {W = SVG.length2em(w,mu,W)}
 
38
      if (h !== "") {H = SVG.length2em(h,mu,H)}
 
39
      if (align !== "" && align.match(/\d/)) {y = SVG.length2em(align,mu); def.y = -y}
 
40
      def.height = Math.floor(H); def.width = Math.floor(W);
 
41
      def.transform = "translate(0,"+H+") matrix(1 0 0 -1 0 0)";
 
42
      def.preserveAspectRatio = "none";
 
43
      this.SUPER(arguments).Init.call(this,def);
 
44
      this.element.setAttributeNS(XLINKNS,"href",img.src);
 
45
      this.w = this.r = W; this.h = this.H = H + y;
 
46
      this.d = this.D = -y; this.l = 0;
 
47
    }
 
48
  });
 
49
  
 
50
  MML.mglyph.Augment({
 
51
    toSVG: function (variant,scale) {
 
52
      this.SVGgetStyles(); var svg = this.SVG(), img, err;
 
53
      this.SVGhandleSpace(svg);
 
54
      var values = this.getValues("src","width","height","valign","alt");
 
55
      if (values.src === "") {
 
56
        values = this.getValues("index","fontfamily");
 
57
        if (values.index) {
 
58
          if (!scale) {scale = this.SVGgetScale()}
 
59
          var def = {}; if (values.fontfamily) {def["font-family"] = values.fontfamily}
 
60
          svg.Add(BBOX.TEXT(scale,String.fromCharCode(values.index),def));
 
61
        }
 
62
      } else {
 
63
        if (!this.img) {this.img = MML.mglyph.GLYPH[values.src]}
 
64
        if (!this.img) {
 
65
          this.img = MML.mglyph.GLYPH[values.src] = {img: new Image(), status: "pending"};
 
66
          img = this.img.img;
 
67
          img.onload  = MathJax.Callback(["SVGimgLoaded",this]);
 
68
          img.onerror = MathJax.Callback(["SVGimgError",this]);
 
69
          img.src = values.src;
 
70
          MathJax.Hub.RestartAfter(img.onload);
 
71
        }
 
72
        if (this.img.status !== "OK") {
 
73
          err = MML.merror("Bad mglyph: "+values.src).With({mathsize:"75%"});
 
74
          this.Append(err); svg = err.toSVG(); this.data.pop();
 
75
        } else {
 
76
          var mu = this.SVGgetMu(svg);
 
77
          svg.Add(BBOX.MGLYPH(this.img.img,values.width,values.height,values.valign,mu,
 
78
                              {src:values.src, alt:values.alt, title:values.alt}));
 
79
        }
 
80
      }
 
81
      svg.Clean();
 
82
      this.SVGhandleColor(svg);
 
83
      this.SVGsaveData(svg);
 
84
      return svg;
 
85
    },
 
86
    SVGimgLoaded: function (event,status) {
 
87
      if (typeof(event) === "string") {status = event}
 
88
      this.img.status = (status || "OK")
 
89
    },
 
90
    SVGimgError: function () {this.img.img.onload("error")}
 
91
  },{
 
92
    GLYPH: {}    // global list of all loaded glyphs
 
93
  });
 
94
  
 
95
  MathJax.Hub.Startup.signal.Post("SVG mglyph Ready");
 
96
  MathJax.Ajax.loadComplete(SVG.autoloadDir+"/mglyph.js");
 
97
  
 
98
});
 
99