src/Tools/jEdit/src/token_markup.scala
author wenzelm
Tue, 21 Jun 2011 21:34:36 +0200
changeset 43502 736183a22fa4
parent 43491 7b7baa283434
child 43511 d138e7482a1b
permissions -rw-r--r--
more precise font transformations: shift sub/superscript, adjust size for user fonts; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43414
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
     1
/*  Title:      Tools/jEdit/src/token_markup.scala
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
     3
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
     4
Outer syntax token markup.
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
     5
*/
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
     6
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
     7
package isabelle.jedit
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
     8
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
     9
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
    10
import isabelle._
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
    11
43482
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    12
import java.awt.{Font, Color}
43502
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    13
import java.awt.font.{TextAttribute, TransformAttribute, FontRenderContext, LineMetrics}
43491
7b7baa283434 hidden font: full height makes cursor more visible;
wenzelm
parents: 43489
diff changeset
    14
import java.awt.geom.AffineTransform
43482
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    15
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    16
import org.gjt.sp.util.SyntaxUtilities
43452
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
    17
import org.gjt.sp.jedit.Mode
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
    18
import org.gjt.sp.jedit.syntax.{Token => JEditToken, TokenMarker, TokenHandler,
43482
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    19
  ParserRuleSet, ModeProvider, XModeHandler, SyntaxStyle}
43452
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
    20
43414
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
    21
import javax.swing.text.Segment
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
    22
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
    23
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
    24
object Token_Markup
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
    25
{
43502
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    26
  /* font operations */
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    27
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    28
  private def font_metrics(font: Font): LineMetrics =
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    29
    font.getLineMetrics("", new FontRenderContext(null, false, false))
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    30
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    31
  private def imitate_font(family: String, font: Font): Font =
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    32
  {
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    33
    val font1 = new Font (family, font.getStyle, font.getSize)
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    34
    font1.deriveFont(font_metrics(font).getAscent / font_metrics(font1).getAscent * font.getSize)
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    35
  }
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    36
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    37
  private def transform_font(font: Font, transform: AffineTransform): Font =
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    38
  {
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    39
    import scala.collection.JavaConversions._
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    40
    font.deriveFont(Map(TextAttribute.TRANSFORM -> new TransformAttribute(transform)))
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    41
  }
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    42
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    43
43443
5d9693c2337e basic support for extended syntax styles: sub/superscript;
wenzelm
parents: 43440
diff changeset
    44
  /* extended syntax styles */
43414
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
    45
43440
a1db9a251a03 tuned signature;
wenzelm
parents: 43429
diff changeset
    46
  private val plain_range: Int = JEditToken.ID_COUNT
43488
39035276927c Symbol.is_ctrl: handle decoded version as well;
wenzelm
parents: 43487
diff changeset
    47
  private val full_range = 6 * plain_range + 1
43414
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
    48
  private def check_range(i: Int) { require(0 <= i && i < plain_range) }
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
    49
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
    50
  def subscript(i: Byte): Byte = { check_range(i); (i + plain_range).toByte }
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
    51
  def superscript(i: Byte): Byte = { check_range(i); (i + 2 * plain_range).toByte }
43460
2852f309174a support for bold style within text buffer;
wenzelm
parents: 43458
diff changeset
    52
  def bold(i: Byte): Byte = { check_range(i); (i + 3 * plain_range).toByte }
43487
98cd7e83fc5b some support for user symbol fonts;
wenzelm
parents: 43482
diff changeset
    53
  def user_font(idx: Int, i: Byte): Byte = { check_range(i); (i + (4 + idx) * plain_range).toByte }
98cd7e83fc5b some support for user symbol fonts;
wenzelm
parents: 43482
diff changeset
    54
  val hidden: Byte = (6 * plain_range).toByte
98cd7e83fc5b some support for user symbol fonts;
wenzelm
parents: 43482
diff changeset
    55
98cd7e83fc5b some support for user symbol fonts;
wenzelm
parents: 43482
diff changeset
    56
  private def font_style(style: SyntaxStyle, f: Font => Font): SyntaxStyle =
98cd7e83fc5b some support for user symbol fonts;
wenzelm
parents: 43482
diff changeset
    57
    new SyntaxStyle(style.getForegroundColor, style.getBackgroundColor, f(style.getFont))
43414
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
    58
43482
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    59
  private def script_style(style: SyntaxStyle, i: Int): SyntaxStyle =
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    60
  {
43502
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    61
    font_style(style, font0 =>
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    62
      {
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    63
        import scala.collection.JavaConversions._
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    64
        val font1 = font0.deriveFont(Map(TextAttribute.SUPERSCRIPT -> new java.lang.Integer(i)))
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    65
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    66
        def shift(y: Float): Font =
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    67
          transform_font(font1, AffineTransform.getTranslateInstance(0.0, y.toDouble))
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    68
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    69
        val m0 = font_metrics(font0)
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    70
        val m1 = font_metrics(font1)
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    71
        val a = m1.getAscent - m0.getAscent
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    72
        val b = (m1.getDescent + m1.getLeading) - (m0.getDescent + m0.getLeading)
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    73
        if (a > 0.0f) shift(a)
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    74
        else if (b > 0.0f) shift(- b)
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    75
        else font1
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    76
      })
43482
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    77
  }
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    78
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    79
  private def bold_style(style: SyntaxStyle): SyntaxStyle =
43487
98cd7e83fc5b some support for user symbol fonts;
wenzelm
parents: 43482
diff changeset
    80
    font_style(style, _.deriveFont(Font.BOLD))
43482
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    81
43487
98cd7e83fc5b some support for user symbol fonts;
wenzelm
parents: 43482
diff changeset
    82
  class Style_Extender(symbols: Symbol.Interpretation) extends SyntaxUtilities.StyleExtender
43482
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    83
  {
43487
98cd7e83fc5b some support for user symbol fonts;
wenzelm
parents: 43482
diff changeset
    84
    if (symbols.font_names.length > 2)
98cd7e83fc5b some support for user symbol fonts;
wenzelm
parents: 43482
diff changeset
    85
      error("Too many user symbol fonts (max 2 permitted): " + symbols.font_names.mkString(", "))
98cd7e83fc5b some support for user symbol fonts;
wenzelm
parents: 43482
diff changeset
    86
43482
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    87
    override def extendStyles(styles: Array[SyntaxStyle]): Array[SyntaxStyle] =
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    88
    {
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    89
      val new_styles = new Array[SyntaxStyle](full_range)
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    90
      for (i <- 0 until plain_range) {
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    91
        val style = styles(i)
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    92
        new_styles(i) = style
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    93
        new_styles(subscript(i.toByte)) = script_style(style, -1)
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    94
        new_styles(superscript(i.toByte)) = script_style(style, 1)
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    95
        new_styles(bold(i.toByte)) = bold_style(style)
43502
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    96
        for ((family, idx) <- symbols.font_index)
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    97
          new_styles(user_font(idx, i.toByte)) = font_style(style, imitate_font(family, _))
43482
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
    98
      }
43502
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
    99
      new_styles(hidden) =
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
   100
        new SyntaxStyle(Color.white, null,
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
   101
          { val font = styles(0).getFont
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
   102
            transform_font(new Font(font.getFamily, 0, 1),
736183a22fa4 more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents: 43491
diff changeset
   103
              AffineTransform.getScaleInstance(1.0, font.getSize.toDouble)) })
43482
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   104
      new_styles
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   105
    }
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   106
  }
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   107
43487
98cd7e83fc5b some support for user symbol fonts;
wenzelm
parents: 43482
diff changeset
   108
  def extended_styles(symbols: Symbol.Interpretation, text: CharSequence)
43443
5d9693c2337e basic support for extended syntax styles: sub/superscript;
wenzelm
parents: 43440
diff changeset
   109
    : Map[Text.Offset, Byte => Byte] =
5d9693c2337e basic support for extended syntax styles: sub/superscript;
wenzelm
parents: 43440
diff changeset
   110
  {
43482
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   111
    // FIXME \\<^bsub> \\<^esub> \\<^bsup> \\<^esup>
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   112
    def ctrl_style(sym: String): Option[Byte => Byte] =
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   113
      if (symbols.is_subscript_decoded(sym)) Some(subscript(_))
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   114
      else if (symbols.is_superscript_decoded(sym)) Some(superscript(_))
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   115
      else if (symbols.is_bold_decoded(sym)) Some(bold(_))
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   116
      else None
43455
4b4b93672f15 some unicode chars for special control symbols;
wenzelm
parents: 43452
diff changeset
   117
43482
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   118
    var result = Map[Text.Offset, Byte => Byte]()
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   119
    def mark(start: Text.Offset, stop: Text.Offset, style: Byte => Byte)
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   120
    {
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   121
      for (i <- start until stop) result += (i -> style)
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   122
    }
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   123
    var offset = 0
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   124
    var ctrl = ""
43489
132f99cc0a43 tuned iteration over short symbols;
wenzelm
parents: 43488
diff changeset
   125
    for (sym <- Symbol.iterator_string(text)) {
43482
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   126
      if (ctrl_style(sym).isDefined) ctrl = sym
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   127
      else if (ctrl != "") {
43487
98cd7e83fc5b some support for user symbol fonts;
wenzelm
parents: 43482
diff changeset
   128
        if (symbols.is_controllable(sym) && sym != "\"" && !symbols.fonts.isDefinedAt(sym)) {
43482
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   129
          mark(offset - ctrl.length, offset, _ => hidden)
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   130
          mark(offset, offset + sym.length, ctrl_style(ctrl).get)
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   131
        }
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   132
        ctrl = ""
43443
5d9693c2337e basic support for extended syntax styles: sub/superscript;
wenzelm
parents: 43440
diff changeset
   133
      }
43488
39035276927c Symbol.is_ctrl: handle decoded version as well;
wenzelm
parents: 43487
diff changeset
   134
      symbols.lookup_font(sym) match {
39035276927c Symbol.is_ctrl: handle decoded version as well;
wenzelm
parents: 43487
diff changeset
   135
        case Some(idx) => mark(offset, offset + sym.length, user_font(idx, _))
43487
98cd7e83fc5b some support for user symbol fonts;
wenzelm
parents: 43482
diff changeset
   136
        case _ =>
98cd7e83fc5b some support for user symbol fonts;
wenzelm
parents: 43482
diff changeset
   137
      }
43482
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   138
      offset += sym.length
43443
5d9693c2337e basic support for extended syntax styles: sub/superscript;
wenzelm
parents: 43440
diff changeset
   139
    }
43482
ebb90ff55b79 added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents: 43464
diff changeset
   140
    result
43443
5d9693c2337e basic support for extended syntax styles: sub/superscript;
wenzelm
parents: 43440
diff changeset
   141
  }
5d9693c2337e basic support for extended syntax styles: sub/superscript;
wenzelm
parents: 43440
diff changeset
   142
43414
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
   143
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
   144
  /* token marker */
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
   145
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
   146
  private val isabelle_rules = new ParserRuleSet("isabelle", "MAIN")
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
   147
43429
095f90f8dca3 simplified Line_Context (again);
wenzelm
parents: 43416
diff changeset
   148
  private class Line_Context(val context: Scan.Context)
095f90f8dca3 simplified Line_Context (again);
wenzelm
parents: 43416
diff changeset
   149
    extends TokenMarker.LineContext(isabelle_rules, null)
43414
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
   150
  {
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
   151
    override def hashCode: Int = context.hashCode
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
   152
    override def equals(that: Any): Boolean =
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
   153
      that match {
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
   154
        case other: Line_Context => context == other.context
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
   155
        case _ => false
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
   156
      }
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
   157
  }
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
   158
43452
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   159
  class Marker extends TokenMarker
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   160
  {
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   161
    override def markTokens(context: TokenMarker.LineContext,
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   162
        handler: TokenHandler, line: Segment): TokenMarker.LineContext =
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   163
    {
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   164
      val symbols = Isabelle.system.symbols
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   165
      val syntax = Isabelle.session.current_syntax()
43414
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
   166
43452
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   167
      val ctxt =
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   168
        context match {
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   169
          case c: Line_Context => c.context
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   170
          case _ => Scan.Finished
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   171
        }
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   172
      val (tokens, ctxt1) = syntax.scan_context(line, ctxt)
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   173
      val context1 = new Line_Context(ctxt1)
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   174
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   175
      val extended = extended_styles(symbols, line)
43443
5d9693c2337e basic support for extended syntax styles: sub/superscript;
wenzelm
parents: 43440
diff changeset
   176
43452
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   177
      var offset = 0
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   178
      for (token <- tokens) {
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   179
        val style = Isabelle_Markup.token_markup(syntax, token)
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   180
        val length = token.source.length
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   181
        val end_offset = offset + length
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   182
        if ((offset until end_offset) exists extended.isDefinedAt) {
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   183
          for (i <- offset until end_offset) {
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   184
            val style1 =
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   185
              extended.get(i) match {
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   186
                case None => style
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   187
                case Some(ext) => ext(style)
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   188
              }
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   189
            handler.handleToken(line, style1, i, 1, context1)
43443
5d9693c2337e basic support for extended syntax styles: sub/superscript;
wenzelm
parents: 43440
diff changeset
   190
          }
43414
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
   191
        }
43452
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   192
        else handler.handleToken(line, style, offset, length, context1)
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   193
        offset += length
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   194
      }
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   195
      handler.handleToken(line, JEditToken.END, line.count, 0, context1)
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   196
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   197
      val context2 = context1.intern
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   198
      handler.setLineContext(context2)
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   199
      context2
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   200
    }
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   201
  }
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   202
43416
e730cdd97dcf more precise imitatation of original TokenMarker: no locking, interned context etc.;
wenzelm
parents: 43414
diff changeset
   203
43452
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   204
  /* mode provider */
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   205
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   206
  class Mode_Provider(orig_provider: ModeProvider) extends ModeProvider
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   207
  {
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   208
    for (mode <- orig_provider.getModes) addMode(mode)
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   209
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   210
    val isabelle_token_marker = new Token_Markup.Marker
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   211
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   212
    override def loadMode(mode: Mode, xmh: XModeHandler)
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   213
    {
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   214
      super.loadMode(mode, xmh)
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   215
      if (mode.getName == "isabelle")
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   216
        mode.setTokenMarker(isabelle_token_marker)
43414
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
   217
    }
43452
5cf548485529 avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents: 43443
diff changeset
   218
  }
43414
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
   219
}
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents:
diff changeset
   220