遇到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文档,那么您一定不会拒绝接受其它第三 ...
随机推荐
- XSSFWorkbook
支持2007以后的 此类与HSSFWorkbook(支持2007之前) 类似,读取文件时把全部的内容都存放到内存中,关闭输入流后. 内存与硬盘完全是毫无关系的两份数据,所有的操作都是对内存的操作,最后 ...
- tensorboard报错:AttributeError: ‘Value’ object has no attribute ‘metadata’
tensorboard的网页可以访问,但是只能观察到graph数据,但是观察不到scalars数据. 原因:tensorflow版本需>=1.3.0 解决方法:升级tensorflow
- pyinstaller 转 exe 的一些坑,以及解决
2020年7月30日 打包了一个程序,各种报错,记录一下1.有时候,这个pyinstaller 打包程序吧,会出现闪退一下,一般原因是因为某个包没有加载进来,或者是包所在的路劲下面有中文,这样打包成功 ...
- 2020重新出发,JAVA入门,标识符&修饰符
标识符(Identifier ) 标识符是程序员用来命名变量,方法,类或标签的单词,其实就是我们在开发过程中凡是自己可以命名的一些单词就是标识符 标识符命名规则 标识符由字母(a-z,A-Z),数字( ...
- C++ 的字符串反转
C++ 的字符串反转 方法一: 使用 algorithm 中的 reverse 函数: // reverse 函数的定义(在 std 名称空间中) template<class BidirIt& ...
- Hyperledger Fabric介绍
转载地址 https://blog.csdn.net/xiaonu123/article/details/81006936 简介 Hyperledger介绍 超级账本(Hyperledger)项目是首 ...
- jquery—实现能滚动的选项卡效果
选项卡在网页中很常见,可以说是必备的一个元素了,网上其实也有很多案例讲解选项卡的做法,写这篇文章,就是记录下自己的写一个的实例效果图: html: css样式: 主要是滚动条的的样式设置width:1 ...
- HBA卡常用命令
HBA卡信息查看 查看对应的PCI设备lspci | grep LSI 如下:对应的HBA卡命令为sas3ircu 如下:对应的HBA卡使用sas2ircu 查看LSI控制器类型和型号 sas2irc ...
- 为 Eureka 添加 Http Basic 认证
简介 在网络世界中,任何网络中的服务都是不安全的,为了使我们的 Eureka 服务更加安全,我们可以添加各种各样的认证方式,以使客户端在提供相应的证明之后才能够注册到 Eureka 中.而这次我们就添 ...
- 前端vue2-org-tree实现精美组织架构图
最近遇到开发组织架构的需求,与以往开发的组织架构不同,不光要展示人名,还要显示职务(或者子公司名称).对应的头像等,并且要考虑,如果用户未上传头像,需使用默认头像(男.女.中性),(⊙o⊙)…要尊重尊 ...