[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm /xml lontexconvert.pm

raeburn raeburn at source.lon-capa.org
Wed Jun 18 02:06:50 EDT 2014


raeburn		Wed Jun 18 06:06:50 2014 EDT

  Modified files:              
    /loncom/xml	lontexconvert.pm 
    /loncom/interface	loncommon.pm 
  Log:
  - Bug 5873. Conversion of entities generated by tth to unicode bracket
  segment characters.
    - loncommon::decode_user_agent() sets additional item in %env               
      (browser.osversion) with information about Windows version.
    - Replacement of entities with unicode equvalents now the default,
      in lontexconvert::unicode_subst()
    - Exceptions: pre-Windows NT 6.0 (i.e., pre-Vista) and mobile devices
      (i.e., ipad, iphone etc.) -- entities replaced with ascii characters
      in those cases.
  
  
Index: loncom/xml/lontexconvert.pm
diff -u loncom/xml/lontexconvert.pm:1.113 loncom/xml/lontexconvert.pm:1.114
--- loncom/xml/lontexconvert.pm:1.113	Sun Sep 15 23:06:46 2013
+++ loncom/xml/lontexconvert.pm	Wed Jun 18 06:06:47 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # TeX Conversion Module
 #
-# $Id: lontexconvert.pm,v 1.113 2013/09/15 23:06:46 raeburn Exp $
+# $Id: lontexconvert.pm,v 1.114 2014/06/18 06:06:47 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -54,17 +54,37 @@
 #
 # Table of substitutions to unicode characters.
 #
+
+my %unicode_harpoons = (
+                        '\rightleftharpoons'  => 0x21cc,
+                      );
+
 my %unicode_translations = (
-    '\rightleftharpoons'  => 0x21cc,
 
-# Brackets - unicode is commented out with pure 8-bit ascii ugliness while we need it.
+# Brackets - unicode for browsers/OS which support it.
+
+    ''             => 0x23a1,
+    ''             => 0x23a2,
+    ''             => 0x23a3,   # when unicode catches up with browsers
+    ''             => 0x23a4,   # use these instead of the cheesey brackets below
+    ''             => 0x23a5,
+    ''             => 0x23a6, 
+
+#  Parens - unicode for browsers/OS which support it
+
+    ''              => 0x239b,
+    ''              => 0x239c,
+    ''              => 0x239d,
+    ''              => 0x239e,
+    ''              => 0x239f,
+    ''              => 0x23a0,
+
+);
+
+my %ascii_8bit_translations = (
+
+# Brackets - pure 8-bit ascii ugliness for browsers/OS which can't handle unicode
 
-#    ''             => 0x23a1,
-#    ''             => 0x23a2,
-#    ''             => 0x23a3,   # when unicode catches up with browsers
-#    ''             => 0x23a4,   # use these instead of the cheesey brackets below
-#    ''             => 0x23a5,
-#    ''             => 0x23a6   
     ''              => 0x5b,
     ''              => 0x5b,    # '['
     ''              => 0x5b,
@@ -72,24 +92,14 @@
     ''              => 0x5d,
     ''              => 0x5d,
 
-#  Parens..again the unicode is commented out with the 8-bit ascii ugliness
-#  turned on until browsers catch up with the unicode world.
-
-#    ''              => 0x239b,
-#    ''              => 0x239c,
-#    ''              => 0x239d,
-#    ''              => 0x239e,
-#    ''              => 0x239f,
-#    ''              => 0x23a0
+# Parens - pure 8-bit ascii ugliness for browsers/OS which can't handle unicode
 
     ''              => 0x28,
     ''              => 0x28,      # '('
     ''              => 0x28,
-
     ''              => 0x29,
     ''              => 0x29,      # '('
-    ''              => 0x29
-
+    ''              => 0x29,
 
 );
 
@@ -173,14 +183,31 @@
     #
     #  Several strings produced by tth require
     # transliteration -> unicode equivalents to render reliably
-    # in browsers. %unicode_translations is a table of
-    # string->substitution which we now apply:
+    # in browsers. %unicode_translations and %unicode_harpoons are tables of
+    # string->substitution which we now apply. (%ascii_8bit_translations used 
+    # instead for Windows XP and mobile devices.
+
+    my $use_ascii;
+    if ($env{'browser.os'} eq 'win') {
+        if (($env{'browser.osversion'}) && ($env{'browser.osversion'} < 6.0)) {
+            $use_ascii = 1;
+        }
+    }
+    if ($env{'browser.mobile'}) {
+        $use_ascii = 1;
+    }
 
     foreach my $pattern (keys(%unicode_translations)) {
 	my $unicode = $unicode_translations{$pattern};
+	if ($use_ascii) {
+	    $unicode = $ascii_8bit_translations{$pattern};
+	}
 	$xmlstring = &unicode_subst($xmlstring, $pattern, $unicode);
     }
 
+    foreach my $pattern (keys(%unicode_harpoons)) {
+        $xmlstring = &unicode_subst($xmlstring, $pattern, $unicode_harpoons{$pattern});
+    }
 
     return ($xmlstring,$errorstring);
 }
@@ -580,6 +607,8 @@
     $string =~s/\\lim\\left\((.+?),(.+?),(.+?)\\right\)/\\lim_{$2\\to $3}$1/gs;
     return $string;
 }
+
+
 1;
 __END__
 
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1193 loncom/interface/loncommon.pm:1.1194
--- loncom/interface/loncommon.pm:1.1193	Mon Jun 16 05:12:31 2014
+++ loncom/interface/loncommon.pm	Wed Jun 18 06:06:50 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1193 2014/06/16 05:12:31 raeburn Exp $
+# $Id: loncommon.pm,v 1.1194 2014/06/18 06:06:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2365,6 +2365,8 @@
 
 =item * $clientinfo
 
+=item * $clientosversion
+
 =back
 
 =back 
@@ -2384,6 +2386,7 @@
     my $clientmathml='';
     my $clientunicode='0';
     my $clientmobile=0;
+    my $clientosversion='';
     for (my $i=0;$i<=$#browsertype;$i++) {
         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
@@ -2405,7 +2408,12 @@
     if ($httpbrowser=~/next/i) { $clientos='next'; }
     if (($httpbrowser=~/mac/i) ||
         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
-    if ($httpbrowser=~/win/i) { $clientos='win'; }
+    if ($httpbrowser=~/win/i) {
+        $clientos='win';
+        if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
+            $clientosversion = $1;
+        }
+    }
     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
     if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
         $clientmobile=lc($1);
@@ -2416,7 +2424,8 @@
         $clientinfo = 'chromeframe-'.$1;
     }
     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
-            $clientunicode,$clientos,$clientmobile,$clientinfo);
+            $clientunicode,$clientos,$clientmobile,$clientinfo,
+            $clientosversion);
 }
 
 ###############################################################
@@ -14523,8 +14532,8 @@
     }
 # ------------------------------------ Check browser type and MathML capability
 
-    my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
-        $clientunicode,$clientos,$clientmobile,$clientinfo) = &decode_user_agent($r);
+    my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
+        $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
 
 # ------------------------------------------------------------- Get environment
 
@@ -14557,6 +14566,7 @@
 	     "browser.os"         => $clientos,
              "browser.mobile"     => $clientmobile,
              "browser.info"       => $clientinfo,
+             "browser.osversion"  => $clientosversion,
 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
 	     "request.course.fn"  => '',
 	     "request.course.uri" => '',




More information about the LON-CAPA-cvs mailing list