src/Pure/Thy/html.scala
changeset 74709 d73a7e3c618c
parent 74679 0efa6a8b6e20
child 74754 eaeab1358ced
equal deleted inserted replaced
74708:b2df121ccfc1 74709:d73a7e3c618c
   374   }
   374   }
   375 
   375 
   376 
   376 
   377   /* fonts */
   377   /* fonts */
   378 
   378 
       
   379   val fonts_path: Path = Path.explode("fonts")
       
   380 
       
   381   def init_fonts(dir: Path): Unit =
       
   382   {
       
   383     val fonts_dir = Isabelle_System.make_directory(dir + HTML.fonts_path)
       
   384     for (entry <- Isabelle_Fonts.fonts(hidden = true))
       
   385       Isabelle_System.copy_file(entry.path, fonts_dir)
       
   386   }
       
   387 
       
   388   def fonts_dir(prefix: String)(ttf_name: String): String = prefix + "/" + ttf_name
       
   389 
   379   def fonts_url(): String => String =
   390   def fonts_url(): String => String =
   380     (for (entry <- Isabelle_Fonts.fonts(hidden = true))
   391     (for (entry <- Isabelle_Fonts.fonts(hidden = true))
   381      yield (entry.path.file_name -> Url.print_file(entry.path.file))).toMap
   392      yield (entry.path.file_name -> Url.print_file(entry.path.file))).toMap
   382 
       
   383   def fonts_dir(prefix: String)(ttf_name: String): String =
       
   384     prefix + "/" + ttf_name
       
   385 
   393 
   386   def fonts_css(make_url: String => String = fonts_url()): String =
   394   def fonts_css(make_url: String => String = fonts_url()): String =
   387   {
   395   {
   388     def font_face(entry: Isabelle_Fonts.Entry): String =
   396     def font_face(entry: Isabelle_Fonts.Entry): String =
   389       cat_lines(
   397       cat_lines(
   397 
   405 
   398     ("/* Isabelle fonts */" :: Isabelle_Fonts.fonts(hidden = true).map(font_face))
   406     ("/* Isabelle fonts */" :: Isabelle_Fonts.fonts(hidden = true).map(font_face))
   399       .mkString("", "\n\n", "\n")
   407       .mkString("", "\n\n", "\n")
   400   }
   408   }
   401 
   409 
   402 
   410   def fonts_css_dir(prefix: String = ""): String =
   403   /* document directory */
   411   {
       
   412     val prefix1 = if (prefix.isEmpty || prefix.endsWith("/")) prefix else prefix + "/"
       
   413     fonts_css(fonts_dir(prefix1 + fonts_path.implode))
       
   414   }
       
   415 
       
   416 
       
   417   /* document directory context (fonts + css) */
       
   418 
       
   419   def relative_prefix(dir: Path, base: Option[Path]): String =
       
   420     base match {
       
   421       case None => ""
       
   422       case Some(base_dir) =>
       
   423         File.path(dir.absolute.java_path.relativize(base_dir.absolute.java_path).toFile).implode
       
   424     }
   404 
   425 
   405   def isabelle_css: Path = Path.explode("~~/etc/isabelle.css")
   426   def isabelle_css: Path = Path.explode("~~/etc/isabelle.css")
   406 
   427 
   407   def write_isabelle_css(dir: Path, make_url: String => String = fonts_dir("fonts")): Unit =
       
   408   {
       
   409     File.write(dir + isabelle_css.base,
       
   410       fonts_css(make_url) + "\n\n" + File.read(isabelle_css))
       
   411   }
       
   412 
       
   413   def init_dir(dir: Path): Unit =
       
   414     write_isabelle_css(Isabelle_System.make_directory(dir))
       
   415 
       
   416   def write_document(dir: Path, name: String, head: XML.Body, body: XML.Body,
   428   def write_document(dir: Path, name: String, head: XML.Body, body: XML.Body,
       
   429     base: Option[Path] = None,
   417     css: String = isabelle_css.file_name,
   430     css: String = isabelle_css.file_name,
   418     hidden: Boolean = true,
   431     hidden: Boolean = true,
   419     structural: Boolean = true): Unit =
   432     structural: Boolean = true): Unit =
   420   {
   433   {
   421     init_dir(dir)
   434     Isabelle_System.make_directory(dir)
       
   435     val prefix = relative_prefix(dir, base)
       
   436     File.write(dir + isabelle_css.base, fonts_css_dir(prefix) + "\n\n" + File.read(isabelle_css))
   422     File.write(dir + Path.basic(name),
   437     File.write(dir + Path.basic(name),
   423       output_document(head, body, css = css, hidden = hidden, structural = structural))
   438       output_document(head, body, css = css, hidden = hidden, structural = structural))
   424   }
   439   }
   425 }
   440 }