遇到doxygen生成的chm文档目录如果有中文是乱码?
原因不在于doxygen,它没有问题,问题出在微软的HTML Help Workshop的hhc.exe不支持utf8.所以要解决这个问题,需要做两个额外的步骤:
1.将html/index.hhp中的Language=0x409 English (United States)换成Language=0x804 中文 (中国),并将文本存成UTF8格式。
2.将html/index.hhc整个文件从UTF8编码换成gb2312,再次手动调用hhc.exe去处理这个hhp文件即可生成不是乱码的中文chm帮助文档。
我自己用C#写了个小工具来处理这个过程,源代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics; namespace Generator
{
class Program
{ static void Main(string[] args)
{
if(args.Length <=)
{
Console.WriteLine("Error:缺少目标配置文件");
return;
} string path = args[]; if(!File.Exists(path))
{
Console.WriteLine(string.Format("{0}不存在", path));
return;
} using(ChmGenerator generator = new ChmGenerator(path))
{
generator.Generate();
}
}
} public class ChmGenerator : IDisposable
{
static readonly string HHC_CONFIG_LOCATION = "HHC_LOCATION = \"C:/Program Files (x86)/HTML Help Workshop/hhc.exe\""; string WorkDirectory;
string InputFile;
string ConfigText;
string NewHHCConfig;
string NewConfigText;
string NewConfigPath; string HHCLocation;
string DoxygenPath; string IntermediatePath;
string IntermediateHHP;
string IntermediateHHC; public ChmGenerator(string inputFile)
{
InputFile = inputFile; string Directory = Path.GetDirectoryName(InputFile);
WorkDirectory = Directory; System.IO.Directory.SetCurrentDirectory(WorkDirectory); HHCLocation = Path.Combine(Directory, "hhc.exe");
DoxygenPath = Path.Combine(Directory, "doxygen.exe");
IntermediatePath = Path.Combine(Directory, "Intermediate");
IntermediateHHP = Path.Combine(IntermediatePath, @"html/index.hhp");
IntermediateHHC = Path.Combine(IntermediatePath, @"html/index.hhc");
NewHHCConfig = string.Format("HHC_LOCATION = \"{0}\"", HHCLocation);
} public void Dispose()
{
try
{
if (!string.IsNullOrEmpty(NewConfigPath) && File.Exists(NewConfigPath))
{
File.Delete(NewConfigPath);
}
}
finally
{ }
} public void Generate()
{
ConfigText = File.ReadAllText(InputFile, Encoding.UTF8); NewConfigPath = Path.Combine(WorkDirectory, Guid.NewGuid().ToString() + ".doxygenProj");
NewConfigText = ConfigText.Replace(HHC_CONFIG_LOCATION, NewHHCConfig); File.WriteAllText(NewConfigPath, NewConfigText, Encoding.UTF8); // 调用doxygen来生成
StartProc(DoxygenPath, string.Format(" {0}", NewConfigPath)); if(!PrepareInputFiles())
{
Console.WriteLine("无法正确生成chm");
return;
} // 调用hhc生成chm
StartProc(HHCLocation, string.Format(" {0}", IntermediateHHP)); } private bool PrepareInputFiles()
{
// 替换Language
if (File.Exists(IntermediateHHP))
{
ReplaceFileText(IntermediateHHP, "Language=0x409 English (United States)", "Language=0x804 中文 (中国)", Encoding.UTF8); if (File.Exists(IntermediateHHC))
{
ChangeFileToAnsi(IntermediateHHC, Encoding.UTF8, Encoding.GetEncoding("gb2312")); return true;
}
else
{
Console.WriteLine(string.Format("Error:{0}不存在", IntermediateHHC));
}
}
else
{
Console.WriteLine(string.Format("Error:{0}不存在", IntermediateHHP));
} return false;
} private void ChangeFileToAnsi(string inputPath, Encoding sourceEncoding, Encoding destEncoding)
{
var text = File.ReadAllText(inputPath, sourceEncoding);
byte[] bytes = sourceEncoding.GetBytes(text); // convert to win bytes
var destBytes = Encoding.Convert(
sourceEncoding, destEncoding, bytes); File.WriteAllBytes(inputPath, destBytes);
} private void ReplaceFileText(string inputPath, string sourceText, string destText, Encoding encoding)
{
var text = File.ReadAllText(inputPath, Encoding.UTF8);
text = text.Replace(sourceText, destText);
File.WriteAllText(inputPath, text, encoding);
} static void StartProc(string application, string command)
{
Debug.Assert(File.Exists(application)); var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = application,
Arguments = " " + command,
RedirectStandardOutput = true,
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
StandardOutputEncoding = Encoding.UTF8
}
}; process.Start(); while (!process.StandardOutput.EndOfStream)
{
string line = process.StandardOutput.ReadLine(); Console.WriteLine(line);
// Debug.WriteLine(line);
} process.WaitForExit();
}
}
}
另外为了确保目标机器没有安装doxygen或者hhc都不影响我生成文档,因此我将这些执行档都复制了一份放到了doxygen项目下,代码中的一些额外步骤就是强行将原始project文件中的hhc路径改成当前目录下的hhc。
目录结构如下:
遇到doxygen生成的chm文档目录如果有中文是乱码?的更多相关文章
- 使用Doxygen生成net帮助文档
一. 什么是Doxygen? Doxygen 是一个程序的文件产生工具,可将程序中的特定批注转换成为说明文件.通常我们在写程序时,或多或少都会写上批注,但是对于其它人而言,要直接探索程序里的批注,与打 ...
- 使用Doxygen生成C#帮助文档
一. 什么是Doxygen? Doxygen 是一个程序的文件产生工具,可将程序中的特定批注转换成为说明文件.通常我们在写程序时,或多或少都会写上批注,但是对于其它人而言,要直接探索程序里的批注,与打 ...
- Doxygen生成美丽注释文档(1):初体验
Chapter 1 - 准备工作 (Windows环境) 1.1 程序包下载 1. Doxygen * 源码: git clone https://github.com/doxygen/doxygen ...
- YUIDoc example代码高亮错误、生成API文档目录不按源文件注释顺序
1.如果发现yuidoc命令用不了,那就重装nodejs吧 昨天不知道是清扫电脑的原因,yuidoc命令用不了(命令不存在),也没有找到好的解决方法,怒重装YUIDoc也不行.最后想了想,怒重装了no ...
- 制作Aspose CHM文档的过程记录
欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...
- 用doxygen风格注释代码生成文档
目录 用doxygen风格注释代码生成文档 1. 说明 2. 具体操作 2.1 生成头部注释 2.2 安装doxygen 2.3 工程配置 3. 总结 用doxygen风格注释代码生成文档 1. 说明 ...
- 安装doxygen(一个自动文档生成工具)+Graphviz图形可视化软件
参考文章: http://www.fmddlmyy.cn/text21.html http://www.cnblogs.com/duguguiyu/archive/2008/06/29/1231852 ...
- 生成chm文档工具- Sandcastle -摘自网络
Sandcastle是微软官方的文档生成工具,NDoc开发停止后,这个貌似也是唯一的一个这方面的工具.它从dll文件及其xml注释文件能够 生成完整的帮助文档,支持多种生成格式(Helpe1x:chm ...
- IDEA生成doc文档-生成chm文档
首先,打开IDEA,并找到Tools -> Generate JavaDoc- 可供查询的chm比那些HTML页面好看多了. 如果您用过JDK API的chm文档,那么您一定不会拒绝接受其它第三 ...
随机推荐
- 006_go语言中的互斥锁的作用练习与思考
在go语言基本知识点中,我练习了一下互斥锁,感觉还是有点懵逼状,接下来为了弄懂,我再次进行了一些尝试,以下就是经过我的尝试后得出的互斥锁的作用. 首先还是奉上我改造后的代码: package main ...
- 安装mpi的那些坑
安装mpi可以用 yum 安装 具体从操作步骤可参考这个链接mpi的yum安装方式 mpi在linux下 使用root权限 会报错 修改方式有两种 1 2.换其他账户 mpi会自行评估我们cpu的 ...
- 创建shell脚本文件
简单来说脚本就是将需要执行的命令保存到文本中,按照顺序(由上往下执行),它是解释型的,不需要 编译 脚本格式 #!/bin/bash或者#!/bin/env bash开头 第一个shell脚本:hel ...
- 剑指offer之字符串是否为数值
1. 题目 这是<剑指offer>上的一道题,刚开始觉得这是一道挺简单的题目,后来发现自己太年轻了,考虑的因素太少了,思考了而是分钟还是无从下手,看了作者的思路深深被他折服了,题目如下: ...
- java二进制表示形式与移位操作符
java二进制表示形式 java中数字的二进制表示形式称为"有符号的二进制补码",下面先介绍原码,反码,补码. 编码 计算方法 原码 用最高位表示符号位,'1'表示负号,'0'表示 ...
- JS学习第二天
数组: var arr1=[2,5,6]; 定义时直接给数组元素赋值 var arr2=[]; 定义一个空数组 var arr3=new Array(); 定义一个空数组并通过索引来 ...
- 浏览器编年史与UserAgent大乱斗
1993 世界上第一个支持显示图片的浏览器Mosaic诞生 为了区分浏览器是否能显示图片,UserAgent诞生了,Mosaic将自己标志为NCSA_Mosaic/2.0(windows 3.1) 1 ...
- C#LeetCode刷题之#56-合并区间(Merge Intervals)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3676 访问. 给出一个区间的集合,请合并所有重叠的区间. 输入: ...
- C#LeetCode刷题之#496-下一个更大元素 I(Next Greater Element I)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4026 访问. 给定两个没有重复元素的数组 nums1 和 num ...
- 思维导图概览SpringCloud
@ 目录 1.什么是微服务 1.1.架构演进 1.2.微服务架构 1.3.微服务解决方案 2.SpringCloud概览 2.1.什么是SpringCloud 2.1.SpringCloud主要组件 ...