support for bold style within text buffer;
authorwenzelm
Sun Jun 19 21:34:55 2011 +0200 (2011-06-19)
changeset 434602852f309174a
parent 43459 def9784a3316
child 43461 d5187dd0e5fa
support for bold style within text buffer;
hidden: white foreground;
src/Tools/jEdit/patches/extended_styles
src/Tools/jEdit/patches/scriptstyles
src/Tools/jEdit/src/plugin.scala
src/Tools/jEdit/src/token_markup.scala
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/Tools/jEdit/patches/extended_styles	Sun Jun 19 21:34:55 2011 +0200
     1.3 @@ -0,0 +1,89 @@
     1.4 +diff -ru jEdit/org/gjt/sp/jedit/Buffer.java jEdit-patched/org/gjt/sp/jedit/Buffer.java
     1.5 +--- jEdit/org/gjt/sp/jedit/Buffer.java	2010-05-09 14:29:25.000000000 +0200
     1.6 ++++ jEdit-patched/org/gjt/sp/jedit/Buffer.java	2011-06-18 18:28:19.000000000 +0200
     1.7 +@@ -2232,7 +2232,7 @@
     1.8 + 			start = next;
     1.9 + 			token = token.next;
    1.10 + 		}
    1.11 +-		if (token.id == Token.END || token.id == Token.NULL)
    1.12 ++		if (token.id == Token.END || (token.id % Token.ID_COUNT) == Token.NULL)
    1.13 + 		{
    1.14 + 			JOptionPane.showMessageDialog(jEdit.getActiveView(),
    1.15 + 				jEdit.getProperty("syntax-style-no-token.message"),
    1.16 +diff -ru jEdit/org/gjt/sp/jedit/syntax/Token.java jEdit-patched/org/gjt/sp/jedit/syntax/Token.java
    1.17 +--- jEdit/org/gjt/sp/jedit/syntax/Token.java	2010-05-09 14:29:24.000000000 +0200
    1.18 ++++ jEdit-patched/org/gjt/sp/jedit/syntax/Token.java	2011-06-18 18:28:10.000000000 +0200
    1.19 +@@ -57,7 +57,7 @@
    1.20 + 	 */
    1.21 + 	public static String tokenToString(byte token)
    1.22 + 	{
    1.23 +-		return (token == Token.END) ? "END" : TOKEN_TYPES[token];
    1.24 ++		return (token == Token.END) ? "END" : TOKEN_TYPES[token % ID_COUNT];
    1.25 + 	} //}}}
    1.26 + 
    1.27 + 	//{{{ Token types
    1.28 +diff -ru jEdit/org/gjt/sp/util/SyntaxUtilities.java jEdit-patched/org/gjt/sp/util/SyntaxUtilities.java
    1.29 +--- jEdit/org/gjt/sp/util/SyntaxUtilities.java	2010-05-09 14:29:29.000000000 +0200
    1.30 ++++ jEdit-patched/org/gjt/sp/util/SyntaxUtilities.java	2011-06-19 21:24:41.000000000 +0200
    1.31 +@@ -26,6 +26,7 @@
    1.32 + //{{{ Imports
    1.33 + import java.awt.Color;
    1.34 + import java.awt.Font;
    1.35 ++import java.awt.font.TextAttribute;
    1.36 + import java.util.Locale;
    1.37 + import java.util.StringTokenizer;
    1.38 + import org.gjt.sp.jedit.syntax.SyntaxStyle;
    1.39 +@@ -194,6 +195,22 @@
    1.40 + 	}
    1.41 + 	
    1.42 + 	/**
    1.43 ++	 * Style with sub/superscript font attribute.
    1.44 ++	 */
    1.45 ++	public static SyntaxStyle scriptStyle(SyntaxStyle style, int script)
    1.46 ++	{
    1.47 ++		java.util.Map attributes = new java.util.HashMap();
    1.48 ++		attributes.put(TextAttribute.SUPERSCRIPT, new Integer(script));
    1.49 ++		return new SyntaxStyle(style.getForegroundColor(), style.getBackgroundColor(),
    1.50 ++                  style.getFont().deriveFont(attributes));
    1.51 ++	}
    1.52 ++
    1.53 ++	public static SyntaxStyle boldStyle(SyntaxStyle style) {
    1.54 ++		return new SyntaxStyle(style.getForegroundColor(), style.getBackgroundColor(),
    1.55 ++                  style.getFont().deriveFont(Font.BOLD));
    1.56 ++	}
    1.57 ++	
    1.58 ++	/**
    1.59 + 	 * Loads the syntax styles from the properties, giving them the specified
    1.60 + 	 * base font family and size.
    1.61 + 	 * @param family The font family
    1.62 +@@ -203,10 +220,10 @@
    1.63 + 	 */
    1.64 + 	public static SyntaxStyle[] loadStyles(String family, int size, boolean color)
    1.65 + 	{
    1.66 +-		SyntaxStyle[] styles = new SyntaxStyle[Token.ID_COUNT];
    1.67 ++		SyntaxStyle[] styles = new SyntaxStyle[4 * Token.ID_COUNT + 1];
    1.68 + 
    1.69 + 		// start at 1 not 0 to skip Token.NULL
    1.70 +-		for(int i = 1; i < styles.length; i++)
    1.71 ++		for(int i = 1; i < Token.ID_COUNT; i++)
    1.72 + 		{
    1.73 + 			try
    1.74 + 			{
    1.75 +@@ -223,6 +240,17 @@
    1.76 + 			}
    1.77 + 		}
    1.78 + 
    1.79 ++		styles[0] = new SyntaxStyle(Color.black, null, new Font(family, 0, size));
    1.80 ++		for(int i = 0; i < Token.ID_COUNT; i++)
    1.81 ++		{
    1.82 ++			styles[i + Token.ID_COUNT] = scriptStyle(styles[i], -1);
    1.83 ++			styles[i + 2 * Token.ID_COUNT] = scriptStyle(styles[i], 1);
    1.84 ++			styles[i + 3 * Token.ID_COUNT] = boldStyle(styles[i]);
    1.85 ++		}
    1.86 ++		styles[0] = null;
    1.87 ++		styles[4 * Token.ID_COUNT] =
    1.88 ++			new SyntaxStyle(Color.white, null, new Font(family, 0, 1));
    1.89 ++
    1.90 + 		return styles;
    1.91 + 	} //}}}
    1.92 + 	
     2.1 --- a/src/Tools/jEdit/patches/scriptstyles	Sun Jun 19 15:31:16 2011 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,83 +0,0 @@
     2.4 -diff -ru jEdit/org/gjt/sp/jedit/Buffer.java jEdit-patched/org/gjt/sp/jedit/Buffer.java
     2.5 ---- jEdit/org/gjt/sp/jedit/Buffer.java	2010-05-09 14:29:25.000000000 +0200
     2.6 -+++ jEdit-patched/org/gjt/sp/jedit/Buffer.java	2011-06-18 18:28:19.000000000 +0200
     2.7 -@@ -2232,7 +2232,7 @@
     2.8 - 			start = next;
     2.9 - 			token = token.next;
    2.10 - 		}
    2.11 --		if (token.id == Token.END || token.id == Token.NULL)
    2.12 -+		if (token.id == Token.END || (token.id % Token.ID_COUNT) == Token.NULL)
    2.13 - 		{
    2.14 - 			JOptionPane.showMessageDialog(jEdit.getActiveView(),
    2.15 - 				jEdit.getProperty("syntax-style-no-token.message"),
    2.16 -diff -ru jEdit/org/gjt/sp/jedit/syntax/Token.java jEdit-patched/org/gjt/sp/jedit/syntax/Token.java
    2.17 ---- jEdit/org/gjt/sp/jedit/syntax/Token.java	2010-05-09 14:29:24.000000000 +0200
    2.18 -+++ jEdit-patched/org/gjt/sp/jedit/syntax/Token.java	2011-06-18 18:28:10.000000000 +0200
    2.19 -@@ -57,7 +57,7 @@
    2.20 - 	 */
    2.21 - 	public static String tokenToString(byte token)
    2.22 - 	{
    2.23 --		return (token == Token.END) ? "END" : TOKEN_TYPES[token];
    2.24 -+		return (token == Token.END) ? "END" : TOKEN_TYPES[token % ID_COUNT];
    2.25 - 	} //}}}
    2.26 - 
    2.27 - 	//{{{ Token types
    2.28 -diff -ru jEdit/org/gjt/sp/util/SyntaxUtilities.java jEdit-patched/org/gjt/sp/util/SyntaxUtilities.java
    2.29 ---- jEdit/org/gjt/sp/util/SyntaxUtilities.java	2010-05-09 14:29:29.000000000 +0200
    2.30 -+++ jEdit-patched/org/gjt/sp/util/SyntaxUtilities.java	2011-06-18 18:28:10.000000000 +0200
    2.31 -@@ -26,6 +26,7 @@
    2.32 - //{{{ Imports
    2.33 - import java.awt.Color;
    2.34 - import java.awt.Font;
    2.35 -+import java.awt.font.TextAttribute;
    2.36 - import java.util.Locale;
    2.37 - import java.util.StringTokenizer;
    2.38 - import org.gjt.sp.jedit.syntax.SyntaxStyle;
    2.39 -@@ -194,6 +195,17 @@
    2.40 - 	}
    2.41 - 	
    2.42 - 	/**
    2.43 -+	 * Style with sub/superscript font attribute.
    2.44 -+	 */
    2.45 -+	public static SyntaxStyle scriptStyle(SyntaxStyle style, int script)
    2.46 -+	{
    2.47 -+		java.util.Map attributes = new java.util.HashMap();
    2.48 -+		attributes.put(TextAttribute.SUPERSCRIPT, new Integer(script));
    2.49 -+		return new SyntaxStyle(style.getForegroundColor(), style.getBackgroundColor(),
    2.50 -+                  style.getFont().deriveFont(attributes));
    2.51 -+	}
    2.52 -+	
    2.53 -+	/**
    2.54 - 	 * Loads the syntax styles from the properties, giving them the specified
    2.55 - 	 * base font family and size.
    2.56 - 	 * @param family The font family
    2.57 -@@ -203,10 +215,10 @@
    2.58 - 	 */
    2.59 - 	public static SyntaxStyle[] loadStyles(String family, int size, boolean color)
    2.60 - 	{
    2.61 --		SyntaxStyle[] styles = new SyntaxStyle[Token.ID_COUNT];
    2.62 -+		SyntaxStyle[] styles = new SyntaxStyle[3 * Token.ID_COUNT + 1];
    2.63 - 
    2.64 - 		// start at 1 not 0 to skip Token.NULL
    2.65 --		for(int i = 1; i < styles.length; i++)
    2.66 -+		for(int i = 1; i < Token.ID_COUNT; i++)
    2.67 - 		{
    2.68 - 			try
    2.69 - 			{
    2.70 -@@ -223,6 +235,16 @@
    2.71 - 			}
    2.72 - 		}
    2.73 - 
    2.74 -+		styles[0] = new SyntaxStyle(Color.black, null, new Font(family, 0, size));
    2.75 -+		for(int i = 0; i < Token.ID_COUNT; i++)
    2.76 -+		{
    2.77 -+			styles[i + Token.ID_COUNT] = scriptStyle(styles[i], -1);
    2.78 -+			styles[i + 2 * Token.ID_COUNT] = scriptStyle(styles[i], 1);
    2.79 -+		}
    2.80 -+		styles[0] = null;
    2.81 -+		styles[3 * Token.ID_COUNT] =
    2.82 -+			new SyntaxStyle(Color.black, null, new Font(family, 0, 1));
    2.83 -+
    2.84 - 		return styles;
    2.85 - 	} //}}}
    2.86 - 	
     3.1 --- a/src/Tools/jEdit/src/plugin.scala	Sun Jun 19 15:31:16 2011 +0200
     3.2 +++ b/src/Tools/jEdit/src/plugin.scala	Sun Jun 19 21:34:55 2011 +0200
     3.3 @@ -279,7 +279,7 @@
     3.4      val family = jEdit.getProperty("view.font")
     3.5      val size = jEdit.getIntegerProperty("view.fontsize", 12)
     3.6      val styles = SyntaxUtilities.loadStyles(family, size)
     3.7 -    _extended_styles = (styles.length == JEditToken.ID_COUNT * 3 + 1)
     3.8 +    _extended_styles = (styles.length == JEditToken.ID_COUNT * 4 + 1)
     3.9    }
    3.10  
    3.11  
     4.1 --- a/src/Tools/jEdit/src/token_markup.scala	Sun Jun 19 15:31:16 2011 +0200
     4.2 +++ b/src/Tools/jEdit/src/token_markup.scala	Sun Jun 19 21:34:55 2011 +0200
     4.3 @@ -25,17 +25,18 @@
     4.4  
     4.5    def subscript(i: Byte): Byte = { check_range(i); (i + plain_range).toByte }
     4.6    def superscript(i: Byte): Byte = { check_range(i); (i + 2 * plain_range).toByte }
     4.7 -  val hidden: Byte = (3 * plain_range).toByte
     4.8 +  def bold(i: Byte): Byte = { check_range(i); (i + 3 * plain_range).toByte }
     4.9 +  val hidden: Byte = (4 * plain_range).toByte
    4.10  
    4.11    private def extended_styles(symbols: Symbol.Interpretation, text: CharSequence)
    4.12      : Map[Text.Offset, Byte => Byte] =
    4.13    {
    4.14      if (Isabelle.extended_styles) {
    4.15        // FIXME \\<^bsub> \\<^esub> \\<^bsup> \\<^esup>
    4.16 -      // FIXME \\<^bold>
    4.17        def ctrl_style(sym: String): Option[Byte => Byte] =
    4.18          if (symbols.is_subscript_decoded(sym)) Some(subscript(_))
    4.19          else if (symbols.is_superscript_decoded(sym)) Some(superscript(_))
    4.20 +        else if (symbols.is_bold_decoded(sym)) Some(bold(_))
    4.21          else None
    4.22  
    4.23        var result = Map[Text.Offset, Byte => Byte]()