最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】给docbook中生成的htmlhelp即chm文件集成css文件

Docbook crifan 3270浏览 0评论

【问题】

早已可以通过docbook生成htmlhelp,然后用微软的HTML Help Workshop中的hhc.exe制作出chm文件。

但是现在遇到一个问题:

制作出来的chm,打开后,是可以正常显示出css作用后的效果的:

chm show effect of css

但是,通过查看源码:

check chm source of html

发现其调用的css,是本地的css文件:

<link rel="stylesheet" type="text/css" href="file:///E:/Dev_Root/docbook/dev/config/css/docbook_crl.css">

而如果本地故意把css文件改名,以模拟别人拿到此chm,没有css的时候,结果就没了css效果了:

chm no css effect

所以希望:

能够制作chm的时候,将本地的css文件,集成到chm中。

以此实现:

任何人拿到此chm,都可以用上内置的css。

 

后来注意到,其实图片也是没有集成进来,而是引用本地的图片的:

即:点击图片从属性中看到是:

mk:@MSITStore:E:\Dev_Root\docbook\dev\books\docbook_dev_note\output\htmlhelp\docbook_dev_note.chm::/images/docbook_xml_src.gif

所以,也要想办法,把图片集成进chm中。

(实际上的确是引用当前自己下面的子文件夹中的图片,而这些图片,在hhp中都已加入了。

是正常的。是自己无解了。)

 

【解决过程】

1.经过研究后,对于chm的制作工具:

E:\dev_install_root\HTML Help Workshop\hhw.exe

中,是没有找到相关的配置选项,可以集成css进去的。

2.参考:

Can we integrate CSS file into a CHM file ?

去试试:

先试试用hhw去操作:

html help workshop add remove topic files

topic files click add 

但是,却发现文件类型过滤中,没法选择css:

can not filter out the css file

只有*.htm

不过,通过输入:

*.css

点击打开:是可以显示对应的css文件的,所以,此处选择对应的

docbook_css__.css

input star css then click open will show all css then select docbook css file

然后就可以在项目中有这个css文件了:

topic files list contain that added css file

then in html project can see that css file

然后去编译:

then goto compile html help file

yes to save changes then compile

对应编译的输出log:

Microsoft HTML Help Compiler 4.74.8702

Compiling e:\Dev_Root\docbook\dev\books\docbook_dev_note\output\htmlhelp\docbook_dev_note.chm

index.html
pr01.html
pr01s02.html
ch01.html
ch01s02.html
ch01s03.html
ch02.html
ch02s02.html
ch02s03.html
ch02s04.html
ch02s05.html
ch02s06.html
ch02s07.html
ch02s08.html
ch02s09.html
ch03.html
ch04.html
ch04s02.html
ch05.html
ch05s02.html
ch05s03.html
ch06.html
ch06s02.html
ch06s03.html
ch06s04.html
ch06s05.html
ch06s06.html
ch06s07.html
ch06s08.html
ch06s09.html
ch06s10.html
ch06s11.html
ch06s12.html
apa.html
apas02.html
apas03.html
apas04.html
..\..\..\..\config\css\docbook_crl__.css
toc.hhc
images\docbook_xml_src.gif
images\docbook_multi_format.png
images\docbook_html.png
images\docbook_htmls.png
images\docbook_pdf.gif
images\docbook_txt.png
images\docbook_rtf.png
images\done_docbook_arch.png
images\generated_html_effect.png
images\pdf_with_bookmark.png
images\pdf_with_toc.png
images\pdf_body_no_indent.png
images\no_hl_fo_source.jpg
images\with_hl_fo_src.jpg
images\ctl_g_input_line_number.png
images\no_indent_one_line_too_content.jpg
images\copy_out_that_line.gif
images\ctl_g_input_line_offset.png
images\can_found_err_pos.jpg
images\fo_src_with_indent.gif
images\ctrl_g_line_7594.jpg
images\error_line_7594.jpg
images\ctrl_g_offset_441.jpg
images\coref_in_html.jpg

Compile time: 0 minutes, 3 seconds
80	Topics
624	Local links
147	Internet links
24	Graphics


Created e:\Dev_Root\docbook\dev\books\docbook_dev_note\output\htmlhelp\docbook_dev_note.chm, 2,073,905 bytes
Compression decreased file by 229,045 bytes.

结果还是没用。没有集成css进来。

3.估计是那人说的,要确保集成进来的css(图片等)文件,是在项目子目录中的。

所以重新去拷贝css文件到项目下面:

/css/docbook_crl.css

然后重新编译htmlhelp,使得确保html中是引用的是:

/css/docbook_crl.css

然后重新用hhw制作,把这个子目录下面的css加进来,看看生成的chm,打开是否正常

以及移动位置后,是否还正常。

现在已经是html中正确引用css:

<link rel="stylesheet" type="text/css" href="/css/docbook_crl.css">

然后再去把css放到:

E:\Dev_Root\docbook\dev\books\docbook_dev_note\output\htmlhelp\css\docbook_crl.css

然后再去重新用hhw去编辑添加css,再编译:

log是:

Microsoft HTML Help Compiler 4.74.8702

Compiling e:\Dev_Root\docbook\dev\books\docbook_dev_note\output\htmlhelp\docbook_dev_note_addedSubfolderCss.chm

index.html
pr01.html
pr01s02.html
ch01.html
ch01s02.html
ch01s03.html
ch02.html
ch02s02.html
ch02s03.html
ch02s04.html
ch02s05.html
ch02s06.html
ch02s07.html
ch02s08.html
ch02s09.html
ch03.html
ch04.html
ch04s02.html
ch05.html
ch05s02.html
ch05s03.html
ch06.html
ch06s02.html
ch06s03.html
ch06s04.html
ch06s05.html
ch06s06.html
ch06s07.html
ch06s08.html
ch06s09.html
ch06s10.html
ch06s11.html
ch06s12.html
apa.html
apas02.html
apas03.html
apas04.html
css\docbook_crl.css
toc.hhc
images\docbook_xml_src.gif
images\docbook_multi_format.png
images\docbook_html.png
images\docbook_htmls.png
images\docbook_pdf.gif
images\docbook_txt.png
images\docbook_rtf.png
images\done_docbook_arch.png
images\generated_html_effect.png
images\pdf_with_bookmark.png
images\pdf_with_toc.png
images\pdf_body_no_indent.png
images\no_hl_fo_source.jpg
images\with_hl_fo_src.jpg
images\ctl_g_input_line_number.png
images\no_indent_one_line_too_content.jpg
images\copy_out_that_line.gif
images\ctl_g_input_line_offset.png
images\can_found_err_pos.jpg
images\fo_src_with_indent.gif
images\ctrl_g_line_7594.jpg
images\error_line_7594.jpg
images\ctrl_g_offset_441.jpg
images\coref_in_html.jpg

Compile time: 0 minutes, 3 seconds
80	Topics
624	Local links
147	Internet links
24	Graphics


Created e:\Dev_Root\docbook\dev\books\docbook_dev_note\output\htmlhelp\docbook_dev_note_addedSubfolderCss.chm, 2,074,233 bytes
Compression decreased file by 227,309 bytes.

效果是:

没移动之前:

E:\Dev_Root\docbook\dev\books\docbook_dev_note\output\htmlhelp\docbook_dev_note_addedSubfolderCss.chm

,是正常的:

local open is ok for chm

再去试试,移动chm文件:

E:\tmp\docbook_dev_note_addedSubfolderCss.chm

再去打开看看效果。

结果竟然也可以了:

change chm location then open also ok

那再去把本地的css都再去改名::

E:\Dev_Root\docbook\dev\config\css\docbook_crl__.css

->

docbook_crl222.css

和:

E:\Dev_Root\docbook\dev\books\docbook_dev_note\output\htmlhelp\css\docbook_crl.css

->

docbook_crl_111.css

然后再移动chm到:

E:\to_del\docbook_dev_note_addedSubfolderCss.chm

再打开看看:

结果真的也可以了。

而且,去看看图片,是正常的,

对应的属性中的地址是:

mk:@MSITStore:E:\to_del\docbook_dev_note_addedSubfolderCss.chm::/images/docbook_xml_src.gif

即, 是引用的,当前文件夹下面的images的图片。

如此,就可以实现:

集成css(和原先就集成好的图片)到了chm中

4.不过现在需要去修改自己的makefile,以便实现此工作的自动化处理。

去看看对应的:

E:\Dev_Root\docbook\dev\books\docbook_dev_note\output\htmlhelp\htmlhelp.hhp

中的FILES部分增加了css文件:

[OPTIONS]
Binary TOC=Yes
Compatibility=1.1 or later
Compiled file=docbook_dev_note_addedSubfolderCss.chm
Contents file=toc.hhc
Default Window=Main
Default topic=index.html
Display compile progress=Yes
Full-text search=Yes
Language=0x804 中文(简体,中国)
Title=Docbook开发手记

[WINDOWS]
Main="Docbook开发手记","toc.hhc",,"index.html","index.html",,,,,0x2520,,0x603006,,,,,,,,0


[FILES]
index.html
pr01.html
pr01s02.html
ch01.html
ch01s02.html
ch01s03.html
ch02.html
ch02s02.html
ch02s03.html
ch02s04.html
ch02s05.html
ch02s06.html
ch02s07.html
ch02s08.html
ch02s09.html
ch03.html
ch04.html
ch04s02.html
ch05.html
ch05s02.html
ch05s03.html
ch06.html
ch06s02.html
ch06s03.html
ch06s04.html
ch06s05.html
ch06s06.html
ch06s07.html
ch06s08.html
ch06s09.html
ch06s10.html
ch06s11.html
ch06s12.html
apa.html
apas02.html
apas03.html
apas04.html
css\docbook_crl.css

[INFOTYPES]

所以,如果docbook的htmlhelp不支持css集成参数的配置的话,

实在不行的话,就得去手动写了。

在makefile中,调用shell的脚本,处理此hhp文件,

以便加上csss配置的行:

css\docbook_crl.css

当然,之前先要拷贝此css文件到htmlhelp文件夹中才行。

5.去折腾。

去看了下:

http://docbook.sourceforge.net/release/xsl/1.78.1/doc/html/index.html

中关于htmlhelp方面的配置,是否有集成,设置css的。

有个:

htmlhelp.hhp.tail

去给:

E:\Dev_Root\docbook\dev\config\docbook-xsl-ns-1.78.1\htmlhelp\htmlhelp_crl.xsl

添加:

<xsl:param name="htmlhelp.hhp.tail">css\docbook_crl.css</xsl:param>

试试结果。

 

【总结】

最后是:

makefile中的相关配置为:

#equation/programlisting/... setting
#<xsl:param name="html.stylesheet.type">text/css</xsl:param>
#<xsl:param name="html.stylesheet">css/common_html.css</xsl:param>
#CFG_HTML_CSS=0
CFG_HTML_CSS=1
HTML_STYLESHEET_TYPE = text/css
#CSS_PATH_LOCAL = $(CONFIG_XSL_NS_BASE_CMD)/css
CSS_PATH_LOCAL = $(CONFIG_ROOT_CMD)/css
CSS_PATH_RELEASE = $(ONLINE_RES_DOCBOOK)/css
#CSS_FILENAME=common_html.css
CSS_FILENAME=docbook_crl.css
# current only support single css file
LOCAL_CSS_FILE_FULLPATH=$(CSS_PATH_LOCAL)/$(CSS_FILENAME)
#HTML_STYLESHEET_LOCAL = $(CSS_PATH_LOCAL)/$(CSS_FILENAME)
#HTML_STYLESHEET_LOCAL = file:///$(CSS_PATH_LOCAL)/$(CSS_FILENAME)
HTML_STYLESHEET_LOCAL = file:///$(LOCAL_CSS_FILE_FULLPATH)
HTML_STYLESHEET_RELEASE = $(CSS_PATH_RELEASE)/$(CSS_FILENAME)

#HTMLHELP_STYLESHEET_LOCAL = /css/$(CSS_FILENAME)
HTMLHELP_STYLESHEET_LOCAL = css/$(CSS_FILENAME)

# ================== HTML related ==================
XSLT_FLAGS_COMMON_HTML = $(XSLT_FLAGS_COMMON)

# css settings
ifeq ($(CFG_HTML_CSS), 1)
STRINGPARAM_HTML_STYPLESHEET_TYPE := --stringparam html.stylesheet.type $(HTML_STYLESHEET_TYPE)

STRINGPARAM_HTML_STYPLESHEET_HTML_LOCAL := $(STRINGPARAM_HTML_STYPLESHEET_TYPE)
STRINGPARAM_HTML_STYPLESHEET_HTML_LOCAL += --stringparam html.stylesheet $(HTML_STYLESHEET_LOCAL)

STRINGPARAM_HTML_STYPLESHEET_HTML_RELEASE := $(STRINGPARAM_HTML_STYPLESHEET_TYPE)
STRINGPARAM_HTML_STYPLESHEET_HTML_RELEASE += --stringparam html.stylesheet $(HTML_STYLESHEET_RELEASE)

STRINGPARAM_HTML_STYPLESHEET_CHM_LOCAL := $(STRINGPARAM_HTML_STYPLESHEET_TYPE)
STRINGPARAM_HTML_STYPLESHEET_CHM_LOCAL += --stringparam html.stylesheet $(HTMLHELP_STYLESHEET_LOCAL)

#STRINGPARAM_HTML_STYPLESHEET_CHM_RELEASE

else
STRINGPARAM_HTML_STYPLESHEET_HTML_LOCAL := 
STRINGPARAM_HTML_STYPLESHEET_HTML_RELEASE := 

STRINGPARAM_HTML_STYPLESHEET_CHM_LOCAL :=
#STRINGPARAM_HTML_STYPLESHEET_CHM_RELEASE :=
endif

# callout settings
ifeq ($(CFG_CALLOUT_GRAPHICS), 1)
XSLT_FLAGS_COMMON_HTML += --stringparam callout.graphics.extension $(HTML_CALLOUT_GRAPHICS_EXTENSION)
endif
# admon settings
ifeq ($(CFG_ADMON_GRAPHICS), 1)
XSLT_FLAGS_COMMON_HTML += --stringparam admon.graphics.extension $(HTML_ADMON_GRAPHICS_EXTENSION)
endif
# # css settings
# ifeq ($(CFG_HTML_CSS), 1)
# XSLT_FLAGS_COMMON_HTML += $(STRINGPARAM_HTML_STYPLESHEET_COMMON_HTML)
# endif

XSLT_FLAGS_HTML_COMMON_LOCAL = 
ifeq ($(CFG_CALLOUT_GRAPHICS), 1)
XSLT_FLAGS_HTML_COMMON_LOCAL += --stringparam callout.graphics.path $(CALLOUT_GRAPHICS_PATH_LOCAL)
endif
ifeq ($(CFG_ADMON_GRAPHICS), 1)
XSLT_FLAGS_HTML_COMMON_LOCAL += --stringparam admon.graphics.path $(HTML_ADMON_GRAPHICS_PATH_LOCAL)
endif
# ifeq ($(CFG_HTML_CSS), 1)
# XSLT_FLAGS_HTML_COMMON_LOCAL += --stringparam html.stylesheet $(HTML_STYLESHEET_LOCAL)
# endif

XSLT_FLAGS_HTML_LOCAL  = $(XSLT_FLAGS_COMMON_HTML)
XSLT_FLAGS_HTML_LOCAL += $(XSLT_FLAGS_HTML_COMMON_LOCAL)
XSLT_FLAGS_HTML_LOCAL += $(STRINGPARAM_HTML_STYPLESHEET_HTML_LOCAL)

XSLT_FLAGS_HTML_COMMON_RELEASE = 
ifeq ($(CFG_CALLOUT_GRAPHICS), 1)
XSLT_FLAGS_HTML_COMMON_RELEASE += --stringparam callout.graphics.path $(CALLOUT_GRAPHICS_PATH_RELEASE)
endif
ifeq ($(CFG_ADMON_GRAPHICS), 1)
XSLT_FLAGS_HTML_COMMON_RELEASE += --stringparam admon.graphics.path $(HTML_ADMON_GRAPHICS_PATH_RELEASE)
endif
# ifeq ($(CFG_HTML_CSS), 1)
# XSLT_FLAGS_HTML_COMMON_RELEASE += --stringparam html.stylesheet $(HTML_STYLESHEET_RELEASE)
# endif

XSLT_FLAGS_HTML_RELEASE = $(XSLT_FLAGS_COMMON_HTML)
XSLT_FLAGS_HTML_RELEASE += $(XSLT_FLAGS_HTML_COMMON_RELEASE)
XSLT_FLAGS_HTML_RELEASE += $(STRINGPARAM_HTML_STYPLESHEET_HTML_RELEASE)

#HTML_CSS_FILE = $(CONFIG_XSL_NS_ROOT_CYGWIN)/html/css/common_html.css

# ================== HTMLs related ==================
XSLT_FLAGS_HTMLS = $(XSLT_FLAGS_COMMON_HTML) \
    --stringparam manifest $(PROJECT_NAME).html.manifest

#    --stringparam root.filename $(PROJECT_NAME)
#    --stringparam base.dir $(HTMLS_OUTPUT_BASE_CMD)/html/multi/

XSLT_FLAGS_HTMLS_LOCAL  = $(XSLT_FLAGS_HTMLS)
XSLT_FLAGS_HTMLS_LOCAL += $(XSLT_FLAGS_HTML_COMMON_LOCAL)
XSLT_FLAGS_HTMLS_LOCAL += $(STRINGPARAM_HTML_STYPLESHEET_HTML_LOCAL)
XSLT_FLAGS_HTMLS_LOCAL += --stringparam navig.graphics $(CFG_NAVIG_GRAPHICS)
ifeq ($(CFG_NAVIG_GRAPHICS), 1)
XSLT_FLAGS_HTMLS_LOCAL += --stringparam navig.graphics.extension $(NAVIG_GRAPHICS_EXTENSION)
XSLT_FLAGS_HTMLS_LOCAL += --stringparam navig.graphics.path $(NAVIG_GRAPHICS_PATH_LOCAL)
endif

XSLT_FLAGS_HTMLS_RELEASE  = $(XSLT_FLAGS_HTMLS)
XSLT_FLAGS_HTMLS_RELEASE += $(XSLT_FLAGS_HTML_COMMON_RELEASE)
XSLT_FLAGS_HTMLS_RELEASE += $(STRINGPARAM_HTML_STYPLESHEET_HTML_RELEASE)
XSLT_FLAGS_HTMLS_RELEASE += --stringparam navig.graphics $(CFG_NAVIG_GRAPHICS)
ifeq ($(CFG_NAVIG_GRAPHICS), 1)
XSLT_FLAGS_HTMLS_RELEASE += --stringparam navig.graphics.extension $(NAVIG_GRAPHICS_EXTENSION)
XSLT_FLAGS_HTMLS_RELEASE += --stringparam navig.graphics.path $(NAVIG_GRAPHICS_PATH_RELEASE)
endif


# ================== CHM related ==================
XSLT_FLAGS_CHM = \
    $(XSLT_FLAGS_HTMLS) \
    $(XSLT_FLAGS_HTML_COMMON_LOCAL) \
    $(STRINGPARAM_HTML_STYPLESHEET_CHM_LOCAL) \
    --stringparam htmlhelp.chm $(PROJECT_NAME).chm

################################################################################
# chm
################################################################################
$(OUTPUT_FILE_HTMLHELP):$(MAIN_SRC_FILE) $(SUB_SRC_FILES)
	@echo "=============================== generating ${PROJECT_NAME} chm =============================="
	export XML_CATALOG_FILES="$(XML_CATALOG_FILES)" && \
	export XML_DEBUG_CATALOG=1 && \
	$(XSLT) $(XSLT_FLAGS_CHM) -o $@ $(XSL_NS_FILE_HTMLHELP) $<
	#cp -a $(CSS_DIR) $(OUTPUT_DIR_CHM)/
	#cp -a $(SYS_IMG_SRC_DIR) $(SYS_IMG_DST_DIR)
	cp -a $(IMG_DIR) $(OUTPUT_DIR_CHM)/
	#rm -rf $(SYS_IMG_DST_DIR)

$(OUTPUT_FILE_CHM):$(OUTPUT_FILE_HTMLHELP) $(OUTPUT_DIR_CHM)/htmlhelp.hhp $(OUTPUT_DIR_CHM)/toc.hhc
	mkdir -p $(OUTPUT_DIR_CHM)/css/
	cp $(LOCAL_CSS_FILE_FULLPATH) $(OUTPUT_DIR_CHM)/css/
	-iconv -f UTF-8 -t GB18030 < $(OUTPUT_DIR_CHM)/htmlhelp.hhp > $(OUTPUT_DIR_CHM)/htmlhelp_gb18030.hhp
	-mv $(OUTPUT_DIR_CHM)/htmlhelp_gb18030.hhp $(OUTPUT_DIR_CHM)/htmlhelp.hhp
	-iconv -f UTF-8 -t GB18030 < $(OUTPUT_DIR_CHM)/toc.hhc > $(OUTPUT_DIR_CHM)/toc_gb18030.hhc
	-mv $(OUTPUT_DIR_CHM)/toc_gb18030.hhc $(OUTPUT_DIR_CHM)/toc.hhc
	@# here use '-' to ignore the hhc error
	@# case 1: normal run hhc will return 1 -> makefile consider it error -> will got Error 1
	@# case 2: for office environment, there is no hhc -> will got Error 127
	- hhc $(OUTPUT_DIR_CHM)/htmlhelp.hhp

chm: $(OUTPUT_FILE_CHM)

clean_chm:
	@echo "=============================== cleaning ${PROJECT_NAME} chm =============================="
	rm -rf $(OUTPUT_DIR_CHM)/*

release_chm:$(OUTPUT_FILE_CHM)
	@echo "=============================== release ${PROJECT_NAME} chm =============================="
	- cp -a $(OUTPUT_FILE_CHM) $(RELEASE_DIR_CHM)
	- $(COMPRESS_TOOL) $(COMPRESS_FLAG) $(RELEASE_DIR_CHM)/$(PROJECT_NAME).$(subst release_,,$@).$(COMPRESS_SUF) $(OUTPUT_FILE_CHM)

clean_release_chm:
	@echo "=============================== cleaning ${PROJECT_NAME} chm release =============================="
	rm -f $(RELEASE_DIR_CHM)/*

然后对应的输出,才达到要的效果:

(1)在htmlhelp下创建css文件夹

(2)拷贝E:\Dev_Root\docbook\dev\config\css\docbook_crl.css到htmlhelp/css下

(3)E:\Dev_Root\docbook\dev\books\docbook_dev_note\output\htmlhelp\htmlhelp.hhp最后包含了对应的:css\docbook_crl.css

如此,调用hhc去编译出来的chm,才能是:

不论移动到什么位置,不论是否删除原先的css文件,则都可以使用内置的css,正常显示了。

转载请注明:在路上 » 【已解决】给docbook中生成的htmlhelp即chm文件集成css文件

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.280 seconds, using 22.16MB memory