diff options
author | Andrej Shadura <andrewsh@debian.org> | 2018-05-08 15:59:31 +0200 |
---|---|---|
committer | Andrej Shadura <andrewsh@debian.org> | 2018-05-08 15:59:31 +0200 |
commit | 47aa8b00b2b11df13a100489e0f904a4947177ef (patch) | |
tree | b35c9acc778ea2f761f3c549f7bee2f4491b3144 /lib/editor/exports.tcl | |
parent | 5b8466f7fae0e071c0f4eda13051c93313910028 (diff) |
Import Upstream version 1.4.7
Diffstat (limited to 'lib/editor/exports.tcl')
-rw-r--r--[-rwxr-xr-x] | lib/editor/exports.tcl | 159 |
1 files changed, 92 insertions, 67 deletions
diff --git a/lib/editor/exports.tcl b/lib/editor/exports.tcl index 2ce2ed4..26441c7 100755..100644 --- a/lib/editor/exports.tcl +++ b/lib/editor/exports.tcl @@ -2,7 +2,7 @@ # Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) ############################################################################ -# Copyright (C) 2007-2009 by Martin Ošmera # +# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera # # martin.osmera@gmail.com # # # # This program is free software; you can redistribute it and#or modify # @@ -21,6 +21,11 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################ +# >>> File inclusion guard +if { ! [ info exists _EXPORTS_TCL ] } { +set _EXPORTS_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Implements exports to other data formats (XHTML && LaTeX) @@ -73,9 +78,9 @@ public method highlight_all {} { public method getDataAsXHTML_count_of_iterations {} { set result 0 foreach tag_def [concat \ - ${ASMsyntaxHighlight::hightlight_tags} \ - ${CsyntaxHighlight::hightlight_tags} \ - ${LSTsyntaxHighlight::hightlight_tags} \ + ${ASMsyntaxHighlight::highlight_tags} \ + ${CsyntaxHighlight::highlight_tags} \ + ${LSTsyntaxHighlight::highlight_tags} \ ] { set range [$editor tag ranges [lindex $tag_def 0]] incr result [llength $range] @@ -91,8 +96,8 @@ public method getDataAsLaTeX_abort_now {} { } ## Export editor content as LaTeX source (include colors) - # @return String - LaTeX source code -public method getDataAsLaTeX {} { + # @parm File file - Target data channel +public method getDataAsLaTeX {file} { # Reset abort variables set getDataAsLaTeX_abort 0 @@ -122,22 +127,22 @@ public method getDataAsLaTeX {} { } # Create LaTeX preamble - set latex "\\documentclass\[a4paper,12pt\]{article}" - append latex "\n\n% Creator: ${::APPNAME}\n\n" - append latex "\\usepackage\[utf-8\]{inputenc}\n" - append latex "\\usepackage\[T1\]{fontenc}\n" - append latex "\\usepackage{color}\n" - append latex "\\title{$filename}\n" - append latex "\\date{[clock format [clock seconds] -format {%D}]}\n" - append latex "\n% define highlighting\n" + puts -nonewline $file "\\documentclass\[a4paper,12pt\]{article}" + puts -nonewline $file "\n\n% Creator: ${::APPNAME}\n\n" + puts -nonewline $file "\\usepackage\[utf8\]{inputenc}\n" + puts -nonewline $file "\\usepackage\[T1\]{fontenc}\n" + puts -nonewline $file "\\usepackage{color}\n" + puts -nonewline $file "\\title{$filename}\n" + puts -nonewline $file "\\date{[clock format [clock seconds] -format {%D}]}\n" + puts -nonewline $file "\n% define highlighting\n" ## Determinate highlighting tag ranges and define colors for 'color' package set ranges {} # Iterate over predefined highlighting tags foreach tag_def [concat \ - ${ASMsyntaxHighlight::hightlight_tags} \ - ${CsyntaxHighlight::hightlight_tags} \ - ${LSTsyntaxHighlight::hightlight_tags} \ + ${ASMsyntaxHighlight::highlight_tags} \ + ${CsyntaxHighlight::highlight_tags} \ + ${LSTsyntaxHighlight::highlight_tags} \ ] { # Conditional abort @@ -148,13 +153,24 @@ public method getDataAsLaTeX {} { # Local variables set color [lindex $tag_def 1] ;# RGB color - set red [string range $color 1 2] ;# Color - RED - set green [string range $color 3 4] ;# Color - GREEN - set blue [string range $color 5 6] ;# Color - BLUE set tag [lindex $tag_def 0] ;# Tag name set range [$editor tag ranges $tag] ;# List of tag ranges set len [llength $range] ;# Number of ranges - set mirror_tag {} ;# Tag with exatly the same highlight + set mirror_tag {} ;# Tag with exatly the same highlight + + # Convert 48b color format to 24b format + if {[string length $color] == 13} { + set new_color {#} + for {set i 1} {$i < [string length $color]} {incr i 4} { + append new_color [string range $color $i [expr {$i + 1}]] + } + set color $new_color + } + + # Decompose the color code + set red [string range $color 1 2] ;# Color - RED + set green [string range $color 3 4] ;# Color - GREEN + set blue [string range $color 5 6] ;# Color - BLUE # Determinate mirror tag switch -- $tag { @@ -163,7 +179,7 @@ public method getDataAsLaTeX {} { } if {$mirror_tag != {}} { set mirror_range [$editor tag ranges $mirror_tag] - } { + } else { set mirror_range {} } @@ -179,7 +195,7 @@ public method getDataAsLaTeX {} { set green [string range [expr "0x$green / 255.0"] 0 4] set blue [string range [expr "0x$blue / 255.0"] 0 4] # Define color (for package color) - append latex "\\definecolor{highlight_$tag}{rgb}{$red, $green, $blue}\n" + puts -nonewline $file "\\definecolor{highlight_$tag}{rgb}{$red, $green, $blue}\n" # Adjust map of text tags set mirror_tag {} @@ -220,7 +236,7 @@ public method getDataAsLaTeX {} { set spaces 0 set correction 0 - while 1 { + while {1} { set idx [string first "\t" $textLine [expr {$idx + 1}]] if {$idx == -1} {break} @@ -258,7 +274,7 @@ public method getDataAsLaTeX {} { # Determinate string to insert if {[lindex $range 2]} { set tag "'\{\\color{highlight_[lindex $range 1]}\\verb'" - } { + } else { set tag "'\}\\verb'" } @@ -289,13 +305,10 @@ public method getDataAsLaTeX {} { regsub -all "\a" $text {'\\verb"'"\\verb'} text # Create final LaTeX document - append latex "\n\n\\begin{document}\n" - append latex "\\ \\\\\n" - append latex $text - append latex "\n\\end{document}" - - # Return result - return $latex + puts -nonewline $file "\n\n\\begin{document}\n" + puts -nonewline $file "\\ \\\\\n" + puts -nonewline $file $text + puts -nonewline $file "\n\\end{document}" } ## Abort export to XHTML @@ -305,8 +318,8 @@ public method getDataAsXHTML_abort_now {} { } ## Export editor content as XHTML source (include colors) - # @return String - XHTML source code -public method getDataAsXHTML {} { + # @parm File file - Target data channel +public method getDataAsXHTML {file} { # Reset abort variables set getDataAsXHTML_abort 0 @@ -336,26 +349,26 @@ public method getDataAsXHTML {} { } # Create XHTML header - set html "<?xml version='1.0' encoding='utf-8' standalone='no'?>\n" - append html "<!DOCTYPE html PUBLIC\n" - append html "\t'-//W3C//DTD XHTML 1.1//EN'\n" - append html "\t'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>\n" - append html "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>\n" - append html "<!--\n\tCreator: ${::APPNAME}\n\tDate: [clock format [clock seconds] -format {%D}]\n-->\n" - append html "\t<head>\n" - append html "\t\t<title>$filename</title>\n" - append html "\t\t<meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=UTF-8\" />\n" - append html "\t\t<meta name=\"Generator\" content=\"${::APPNAME}\" />\n" - append html "\t\t<style type=\"text/css\">\n" - append html "\t\t\tbody {\n\t\t\t\tfont-family: $fontFamily;\n\t\t\t\tfont-size: ${fontSize}px;\n\t\t\t}\n" + puts -nonewline $file "<?xml version='1.0' encoding='utf-8' standalone='no'?>\n" + puts -nonewline $file "<!DOCTYPE html PUBLIC\n" + puts -nonewline $file "\t'-//W3C//DTD XHTML 1.1//EN'\n" + puts -nonewline $file "\t'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>\n" + puts -nonewline $file "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>\n" + puts -nonewline $file "<!-- Creator: ${::APPNAME} -->\n" + puts -nonewline $file "\t<head>\n" + puts -nonewline $file "\t\t<title>$filename</title>\n" + puts -nonewline $file "\t\t<meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=UTF-8\" />\n" + puts -nonewline $file "\t\t<meta name=\"Generator\" content=\"${::APPNAME}\" />\n" + puts -nonewline $file "\t\t<style type=\"text/css\">\n" + puts -nonewline $file "\t\t\tbody {\n\t\t\t\tfont-family: $fontFamily;\n\t\t\t\tfont-size: ${fontSize}px;\n\t\t\t}\n" ## Determinate highlighting tag ranges and define inline CSS set ranges {} # Iterate over predefined highlighting tags foreach tag_def [concat \ - ${ASMsyntaxHighlight::hightlight_tags} \ - ${CsyntaxHighlight::hightlight_tags} \ - ${LSTsyntaxHighlight::hightlight_tags} \ + ${ASMsyntaxHighlight::highlight_tags} \ + ${CsyntaxHighlight::highlight_tags} \ + ${LSTsyntaxHighlight::highlight_tags} \ ] { # Conditional abort @@ -377,7 +390,7 @@ public method getDataAsXHTML {} { } if {$mirror_tag != {}} { set mirror_range [$editor tag ranges $mirror_tag] - } { + } else { set mirror_range {} } @@ -388,19 +401,30 @@ public method getDataAsXHTML {} { # Adjust tag name set tag [string replace $tag 0 3] + set color [lindex $tag_def 1] + + # Convert 48b color format to 24b format + if {[string length $color] == 13} { + set new_color {#} + for {set i 1} {$i < [string length $color]} {incr i 4} { + append new_color [string range $color $i [expr {$i + 1}]] + } + set color $new_color + } + # create CSS - append html "\t\t\t.$tag {\n" - append html "\t\t\t\tcolor: [lindex $tag_def 1];\n" + puts -nonewline $file "\t\t\t.$tag {\n" + puts -nonewline $file "\t\t\t\tcolor: $color;\n" if {[lindex $tag_def 2]} { - append html "\t\t\t\ttext-decoration: line-through;\n" + puts -nonewline $file "\t\t\t\ttext-decoration: line-through;\n" } if {[lindex $tag_def 3]} { - append html "\t\t\t\tfont-style: italic;\n" + puts -nonewline $file "\t\t\t\tfont-style: italic;\n" } if {[lindex $tag_def 4]} { - append html "\t\t\t\tfont-weight: bold;\n" + puts -nonewline $file "\t\t\t\tfont-weight: bold;\n" } - append html "\t\t\t}\n" + puts -nonewline $file "\t\t\t}\n" for {set i 0} {$i < $len} {incr i} { lappend ranges [list [lindex $range $i] $tag 1] @@ -416,8 +440,8 @@ public method getDataAsXHTML {} { } } } - append html "\t\t</style>\n" - append html "\t</head>\n" + puts -nonewline $file "\t\t</style>\n" + puts -nonewline $file "\t</head>\n" # Sort tag ranges (recursive) set ranges [lsort -command "::FileList::editor__sort_tag_ranges" $ranges] @@ -457,7 +481,7 @@ public method getDataAsXHTML {} { # Deterinate string to insert if {[lindex $range 2]} { set tag "span class='[lindex $range 1]'" - } { + } else { set tag {/span} } @@ -475,12 +499,13 @@ public method getDataAsXHTML {} { regsub -all "\b" $text {\>} text # Create final XHTML document - append html "\t<body>\n\t\t<pre>\n" - append html "\t\t<!-- CODE BLOCK - begin -->\n" - append html $text - append html "\t\t<!-- CODE BLOCK - end -->\n" - append html "\t\t</pre>\n\t</body>\n</html>" - - # Return result - return $html + puts -nonewline $file "\t<body>\n\t\t<pre>\n" + puts -nonewline $file "\t\t<!-- CODE BLOCK - begin -->\n" + puts -nonewline $file $text + puts -nonewline $file "\t\t<!-- CODE BLOCK - end -->\n" + puts -nonewline $file "\t\t</pre>\n\t</body>\n</html>" +} + +# >>> File inclusion guard } +# <<< File inclusion guard |