Re: Suspected HTML Help Compiler (hhc) limitation

From: Date: Mon, 05 May 2003 18:13:33 +0000
Subject: Re: Suspected HTML Help Compiler (hhc) limitation
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969353200@lists.php.net to get a copy of this message
Derick Rethans <derick@php.net> wrote: > Atleast the index showed up, and all the pages with content show real > chinese and korean chars without problems. Only the navigation still > shows squares as titles. Hm, that's exactly what I see when I opened these chms. Would you mind applying the attached patch and launch the build again? The patch may also fix some encoding mismatching issue in central european docs. Thanks. Moriyoshi

Common subdirectories: /home/koizumi/src/phpdoc/chm/CVS and ./CVS diff -u -N /home/koizumi/src/phpdoc/chm/chm_settings.php ./chm_settings.php --- chm/chm_settings.php 1970-01-01 09:00:00.000000000 +0900 +++ chm/chm_settings.php 2003-05-04 23:01:24.000000000 +0900 @@ -0,0 +1,105 @@ +<?php +$DEFAULT_FONT = "Arial,10,0"; + +// Array to manual code -> HTML Help Code conversion +// Code list: http://www.helpware.net/htmlhelp/hh_info.htm +// Charset list: http://www.microsoft.com/globaldev/nlsweb/default.asp +// Language code: http://www.unicode.org/unicode/onlinedat/languages.html +$LANGUAGES = array( + "tw" => array( + "langcode" => "0x404 Traditional Chinese", + "preferred_charset" => "CP950", + "preferred_font" => $DEFAULT_FONT + ), + "cs" => array( + "langcode" => "0x405 Czech", + "preferred_charset" => "Windows-1250", + "preferred_font" => $DEFAULT_FONT + ), + "de" => array( + "langcode" => "0x407 German (Germany)", + "preferred_charset" => "Windows-1252", + "preferred_font" => $DEFAULT_FONT + ), + "en" => array( + "langcode" => "0x809 English (United Kingdom)", + "preferred_charset" => "Windows-1252", + "preferred_font" => $DEFAULT_FONT + ), + "es" => array( + "langcode" => "0xc0a Spanish (International Sort)", + "preferred_charset" => "Windows-1252", + "preferred_font" => $DEFAULT_FONT + ), + "fr" => array( + "langcode" => "0x40c French (France)", + "preferred_charset" => "Windows-1252", + "preferred_font" => $DEFAULT_FONT + ), + "fi" => array( + "langcode" => "0x40b Finnish", + "preferred_charset" => "Windows-1252", + "preferred_font" => $DEFAULT_FONT + ), + "hu" => array( + "langcode" => "0x40e Hungarian", + "preferred_charset" => "Windows-1250", + "preferred_font" => $DEFAULT_FONT + ), + "it" => array( + "langcode" => "0x410 Italian (Italy)", + "preferred_charset" => "Windows-1252", + "preferred_font" => $DEFAULT_FONT + ), + "ja" => array( + "langcode" => "0x411 Japanese", + "preferred_charset" => "CP932", + "preferred_font" => "‚l‚r ‚oƒSƒVƒbƒN,10,0" + ), + "kr" => array( + "langcode" => "0x412 Korean", + "preferred_charset" => "CP949", + "preferred_font" => $DEFAULT_FONT + ), + "nl" => array( + "langcode" => "0x413 Dutch (Netherlands)", + "preferred_charset" => "Windows-1252", + "preferred_font" => $DEFAULT_FONT + ), + "pl" => array( + "langcode" => "0x415 Polish", + "preferred_charset" => "Windows-1250", + "preferred_font" => $DEFAULT_FONT + ), + "pt_BR" => array( + "langcode" => "0x416 Portuguese (Brazil)", + "preferred_charset" => "Windows-1252", + "preferred_font" => $DEFAULT_FONT + ), + "ro" => array( + "langcode" => "0x418 Romanian", + "preferred_charset" => "Windows-1250", + "preferred_font" => $DEFAULT_FONT + ), + "sk" => array( + "langcode" => "0x41b Slovak", + "preferred_charset" => "Windows-1250", + "preferred_font" => $DEFAULT_FONT + ), + "sl" => array( + "langcode" => "0x424 Slovenian", + "preferred_charset" => "Windows-1250", + "preferred_font" => $DEFAULT_FONT + ), + "sv" => array( + "langcode" => "0x41d Swedish", + "preferred_charset" => "Windows-1252", + "preferred_font" => $DEFAULT_FONT + ), + "zh" => array( + "langcode" => "0x804 Simplified Chinese", + "preferred_charset" => "CP936", + "preferred_font" => $DEFAULT_FONT + ) +); +?> diff -u -N /home/koizumi/src/phpdoc/chm/common.php ./common.php --- chm/common.php 1970-01-01 09:00:00.000000000 +0900 +++ chm/common.php 2003-05-05 05:48:49.000000000 +0900 @@ -0,0 +1,83 @@ +<?php +// Used directories and files +$HTML_PATH = getenv("PHP_HELP_COMPILE_DIR"); +$FANCY_PATH = getenv("PHP_HELP_COMPILE_FANCYDIR"); +$LANGUAGE = getenv("PHP_HELP_COMPILE_LANG"); +$INTERNAL_CHARSET = "UTF-8"; + +// backwards compatibility +if (!function_exists("file_get_contents")) { + function file_get_contents($file) + { + $cnt = file($file); + if ($cnt !== false) { + return join('', $cnt); + } + return false; + } +} + +// Return a file joined on one line +function oneLiner($filename) +{ + global $INTERNAL_CHARSET; + + $buf = preg_replace("/[\r|\n]{1,2}/U", " ", file_get_contents($filename)); + $charset = detectDocumentCharset($buf); + + if ($charset === false) $charset = "UTF-8"; + + if ($charset != $INTERNAL_CHARSET) { + if (function_exists("iconv")) { + $buf = iconv($charset, $INTERNAL_CHARSET, $buf); + } elseif (function_exists("mb_convert_encoding")) { + $buf = mb_convert_encoding($buf, $INTERNAL_CHARSET, $charset); + } elseif (preg_match("/^UTF-?8$/i", $INTERNAL_CHARSET) && preg_match("/^(ISO-8859-1|WINDOWS-1252)$/i", $charset)) { + $buf = utf8_encode($buf); + } else { + die("charset conversion function is not available."); + } + } + return $buf; +} + +function fputs_wrapper($fp, $str) +{ + fputs($fp, convertCharset($str)); +} + +function convertCharset($buf) +{ + global $LANGUAGE, $LANGUAGES, $INTERNAL_CHARSET; + + $charset = $LANGUAGES[$LANGUAGE]['preferred_charset']; + + if ($charset != $INTERNAL_CHARSET) { + if (function_exists("iconv")) { + $buf = iconv($INTERNAL_CHARSET, "$charset//TRANSLIT", $buf); + } elseif (function_exists("mb_convert_encoding")) { + $buf = mb_convert_encoding($buf, $charset, $INTERNAL_CHARSET); + } elseif (preg_match("/^UTF-?8$/i", $INTERNAL_CHARSET) && preg_match("/^(ISO-8859-1|WINDOWS-1252)$/i", $charset)) { + $buf = utf8_decode($buf); + } else { + die("$LANGUAGE locale is not supported."); + } + } + return $buf; +} // oneLiner() function end + +// Returns the name of character set in the given document +function detectDocumentCharset($doc) +{ + if (preg_match("/<META\\s+HTTP-EQUIV=\"CONTENT-TYPE\"\\s+CONTENT=\"TEXT\\/HTML;\\s+CHARSET=([\\w\\d-]*)\"\\s*>/iU", $doc, $reg)) { + return $reg[1]; + } + return false; +} + +function setDocumentCharset($doc, $charset) +{ + return preg_replace("/(<META\\s+HTTP-EQUIV=\"CONTENT-TYPE\"\\s+CONTENT=\"TEXT\\/HTML;\\s+CHARSET=)([\\w\\d-]*)(\"\\s*>)/iU", "\$1$charset\$3", $doc); +} +?> + diff -u -N /home/koizumi/src/phpdoc/chm/make_chm.php ./make_chm.php --- chm/make_chm.php 2003-04-29 16:53:23.000000000 +0900 +++ chm/make_chm.php 2003-05-05 05:52:01.000000000 +0900 @@ -9,118 +9,13 @@ See make_chm.README for information about this system. */ -// Used directories and files -$HTML_PATH = getenv("PHP_HELP_COMPILE_DIR"); -$FANCY_PATH = getenv("PHP_HELP_COMPILE_FANCYDIR"); -$LANGUAGE = getenv("PHP_HELP_COMPILE_LANG"); +include_once('common.php'); +include_once('chm_settings.php'); + $INDEX_IN_HTML = "index.html"; -$INTERNAL_CHARSET = "UTF-8"; -$DEFAULT_FONT = "Arial,10,0"; if (empty($FANCY_PATH)) { $FANCY_PATH = $HTML_PATH; } -// Array to manual code -> HTML Help Code conversion -// Code list: http://www.helpware.net/htmlhelp/hh_info.htm -// Charset list: http://www.microsoft.com/globaldev/nlsweb/default.asp -// Language code: http://www.unicode.org/unicode/onlinedat/languages.html -$LANGUAGES = array( - "tw" => array( - "langcode" => "0x404 Traditional Chinese", - "preferred_charset" => "CP950", - "preferred_font" => $DEFAULT_FONT - ), - "cs" => array( - "langcode" => "0x405 Czech", - "preferred_charset" => "Windows-1250", - "preferred_font" => $DEFAULT_FONT - ), - "de" => array( - "langcode" => "0x407 German (Germany)", - "preferred_charset" => "Windows-1252", - "preferred_font" => $DEFAULT_FONT - ), - "en" => array( - "langcode" => "0x809 English (United Kingdom)", - "preferred_charset" => "Windows-1252", - "preferred_font" => $DEFAULT_FONT - ), - "es" => array( - "langcode" => "0xc0a Spanish (International Sort)", - "preferred_charset" => "Windows-1252", - "preferred_font" => $DEFAULT_FONT - ), - "fr" => array( - "langcode" => "0x40c French (France)", - "preferred_charset" => "Windows-1252", - "preferred_font" => $DEFAULT_FONT - ), - "fi" => array( - "langcode" => "0x40b Finnish", - "preferred_charset" => "Windows-1252", - "preferred_font" => $DEFAULT_FONT - ), - "hu" => array( - "langcode" => "0x40e Hungarian", - "preferred_charset" => "Windows-1250", - "preferred_font" => $DEFAULT_FONT - ), - "it" => array( - "langcode" => "0x410 Italian (Italy)", - "preferred_charset" => "Windows-1252", - "preferred_font" => $DEFAULT_FONT - ), - "ja" => array( - "langcode" => "0x411 Japanese", - "preferred_charset" => "CP932", - "preferred_font" => "‚l‚r ‚oƒSƒVƒbƒN,10,0" - ), - "kr" => array( - "langcode" => "0x412 Korean", - "preferred_charset" => "CP949", - "preferred_font" => $DEFAULT_FONT - ), - "nl" => array( - "langcode" => "0x413 Dutch (Netherlands)", - "preferred_charset" => "Windows-1252", - "preferred_font" => $DEFAULT_FONT - ), - "pl" => array( - "langcode" => "0x415 Polish", - "preferred_charset" => "Windows-1250", - "preferred_font" => $DEFAULT_FONT - ), - "pt_BR" => array( - "langcode" => "0x416 Portuguese (Brazil)", - "preferred_charset" => "Windows-1252", - "preferred_font" => $DEFAULT_FONT - ), - "ro" => array( - "langcode" => "0x418 Romanian", - "preferred_charset" => "Windows-1250", - "preferred_font" => $DEFAULT_FONT - ), - "sk" => array( - "langcode" => "0x41b Slovak", - "preferred_charset" => "Windows-1250", - "preferred_font" => $DEFAULT_FONT - ), - "sl" => array( - "langcode" => "0x424 Slovenian", - "preferred_charset" => "Windows-1250", - "preferred_font" => $DEFAULT_FONT - ), - "sv" => array( - "langcode" => "0x41d Swedish", - "preferred_charset" => "Windows-1252", - "preferred_font" => $DEFAULT_FONT - ), - "zh" => array( - "langcode" => "0x804 Simplified Chinese", - "preferred_charset" => "CP936", - "preferred_font" => "MS Song,10,0" - ) -); - // Files on the top level of the TOC $MAIN_FILES = array( "getting-started.html", @@ -132,18 +27,6 @@ "appendixes.html" ); -// backwards compatibility -if (!function_exists("file_get_contents")) { - function file_get_contents($file) - { - $cnt = file($file); - if ($cnt !== false) { - return join('', $cnt); - } - return false; - } -} - // Header for index and toc $HEADER = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <html> @@ -350,62 +233,4 @@ } } // findDeeperLinks() function end - -function fputs_wrapper($fp, $str) -{ - fputs($fp, convertCharset($str)); -} - -// Return a file joined on one line -function oneLiner($filename) -{ - global $INTERNAL_CHARSET; - - $buf = preg_replace("/[\r|\n]{1,2}/U", " ", file_get_contents($filename)); - $charset = detectDocumentCharset($buf); - - if ($charset === false) $charset = "UTF-8"; - - if ($charset != $INTERNAL_CHARSET) { - if (function_exists("iconv")) { - $buf = iconv($charset, $INTERNAL_CHARSET, $buf); - } elseif (function_exists("mb_convert_encoding")) { - $buf = mb_convert_encoding($buf, $INTERNAL_CHARSET, $charset); - } elseif (preg_match("/^UTF-?8$/i", $INTERNAL_CHARSET) && preg_match("/^(ISO-8859-1|WINDOWS-1252)$/i", $charset)) { - $buf = utf8_encode($buf); - } else { - die("charset conversion function is not available."); - } - } - return $buf; -} - -function convertCharset($buf) -{ - global $LANGUAGE, $LANGUAGES, $INTERNAL_CHARSET; - - $charset = $LANGUAGES[$LANGUAGE]['preferred_charset']; - - if ($charset != $INTERNAL_CHARSET) { - if (function_exists("iconv")) { - $buf = iconv($INTERNAL_CHARSET, "$charset//TRANSLIT", $buf); - } elseif (function_exists("mb_convert_encoding")) { - $buf = mb_convert_encoding($buf, $charset, $INTERNAL_CHARSET); - } elseif (preg_match("/^UTF-?8$/i", $INTERNAL_CHARSET) && preg_match("/^(ISO-8859-1|WINDOWS-1252)$/i", $charset)) { - $buf = utf8_decode($buf); - } else { - die("$LANGUAGE locale is not supported."); - } - } - return $buf; -} // oneLiner() function end - -// Returns the name of character set in the given document -function detectDocumentCharset($doc) -{ - if (preg_match("/<META\\s+HTTP-EQUIV=\"CONTENT-TYPE\"\\s+CONTENT=\"TEXT\\/HTML;\\s+CHARSET=([\\w\\d-]*)\"\\s*>/iU", $doc, $reg)) { - return $reg[1]; - } - return false; -} ?> diff -u -N chm/make_chm_fancy.php ./make_chm_fancy.php --- chm/make_chm_fancy.php 2002-08-31 01:04:32.000000000 +0900 +++ ./make_chm_fancy.php 2003-05-05 01:23:43.000000000 +0900 @@ -7,20 +7,20 @@ to put here in CVS. */ +include_once('common.php'); +include_once('chm_settings.php'); + // This script takes much time to run set_time_limit(0); // Get ENV vars from the system -$htmldir = getenv("PHP_HELP_COMPILE_DIR"); -$fancydir = getenv("PHP_HELP_COMPILE_FANCYDIR"); -$language = getenv("PHP_HELP_COMPILE_LANG"); $original_index = "index.html"; // How many files were processed $counter = 0; // Open the directory, and do the work on all HTML files -$handle = opendir($htmldir); +$handle = opendir($HTML_PATH); while (false !== ($filename = readdir($handle))) { if (strpos($filename, ".html") && ($filename != "fancy-index.html")) { fancy_design($filename); @@ -29,29 +29,30 @@ closedir($handle); // Look for CHM index file (snap-downloader, cvs-usr with/without lang-support) -if (false == ($content = join("", @file("make_chm_index_$language.html")))) { - if (false == ($content = join("", @file("$language/make_chm_index_$language.html")))) { - if (false == ($content = join("", @file("$htmldir/../$language/make_chm_index_$language.html")))) { - $content = join("", @file("en/make_chm_index_en.html")); - } +if (false == ($content = oneLiner("make_chm_index_$LANGUAGE.html"))) { + if (false == ($content = oneLiner("$LANGUAGE/make_chm_index_$LANGUAGE.html"))) { + if (false == ($content = oneLiner("$HTML_PATH/../$LANGUAGE/make_chm_index_$LANGUAGE.html"))) { + $content = oneLiner("en/make_chm_index_en.html"); + } } } // Make GENTIME the actual date/time $content = str_replace("[GENTIME]", date("D M d H:i:s Y"), $content); $content = str_replace("[PUBTIME]", $publication_date, $content); -$fp = fopen("$fancydir/fancy-index.html", "w"); -fputs($fp, $content); +$content = setDocumentCharset($content, $LANGUAGES[$LANGUAGE]['preferred_charset']); +$fp = fopen("$FANCY_PATH/fancy-index.html", "w"); +fputs_wrapper($fp, $content); fclose($fp); -copy("chm/make_chm_style.css", "$fancydir/style.css"); -copy("chm/make_chm_spc.gif", "$fancydir/spacer.gif"); +copy("chm/make_chm_style.css", "$FANCY_PATH/style.css"); +copy("chm/make_chm_spc.gif", "$FANCY_PATH/spacer.gif"); // Three files added (fancy-index.html, style.css and spacer.gif) $counter += 3; echo "\nConverting ready...\n"; -echo "Total number of files written in $fancydir directory: $counter\n\n"; +echo "Total number of files written in $FANCY_PATH directory: $counter\n\n"; /***********************************************************************/ /* End of script lines, one main function follows */ @@ -60,10 +61,10 @@ // Convert one file from HTML => fancy HTML function fancy_design($fname) { - global $htmldir, $fancydir, $counter, $original_index, $publication_date; + global $HTML_PATH, $FANCY_PATH, $LANGUAGE, $LANGUAGES, $counter, $original_index, $publication_date; - // Get the contents of the file from $htmldir - $content = join("", file("$htmldir/$fname")); + // Get the contents of the file from $HTML_PATH + $content = oneLiner("$HTML_PATH/$fname"); // CSS file linking $content = preg_replace("|</HEAD|", '<LINK REL="stylesheet" HREF="style.css"></HEAD', $content); @@ -119,13 +120,14 @@ } - // Print out that new file to $fancydir - $fp = fopen("$fancydir/$fname", "w"); - fputs($fp, $content); + // Print out that new file to $FANCY_PATH + $fp = fopen("$FANCY_PATH/$fname", "w"); + $content = setDocumentCharset($content, $LANGUAGES[$LANGUAGE]['preferred_charset']); + fputs_wrapper($fp, $content); fclose($fp); // Print out a message to see the progress - echo "$fancydir/$fname ready...\n"; + echo "$FANCY_PATH/$fname ready...\n"; $counter++; } // fancy_design() function end
« previous php.doc (#969353200) next »