C# 클래스 Bloom.Publish.EpubMaker

This class handles the process of creating an ePUB out of a bloom book. The process has two stages, corresponding to the way our UI displays a preview and then allows the user to save. We 'stage' the ePUB by generating all the files into a temporary folder. Then, if the user says to save, we actually zip them into an ePUB.
상속: IDisposable
파일 보기 프로젝트 열기: BloomBooks/BloomDesktop 1 사용 예제들

Private Properties

프로퍼티 타입 설명
AddAudioOverlay void
AddFontFace void
ConvertStyleFromPxToPercent bool
CopyFile void
CopyFileToEpub string
CopyImages void
CopyStyleSheets void
EmbedFonts void
FixChangedFileNames void
FixIllegalIds void
FixPictureSizes void
GetEpubFriendlyHtmlDomForPage Bloom.Book.HtmlDom
GetIdOfFile string
GetMediaType string
GetOrCreateCompressedAudioIfWavExists string
GetOverlayName string
HasClass bool
IsCompressedAudioForIdMissing bool
MakeCompressedAudio string
MakeCssLinksAppropriateForEpub void
MakeManifest void
MakeNavPage void
MakePageFile Bloom.Book.HtmlDom
MakeSpine void
RemoveBloomUiElements void
RemoveRegularStylesheets void
RemoveScripts void
RemoveSpuriousLinks void
RemoveUnwantedContent void
ToValidXmlId string

공개 메소드들

메소드 설명
Dispose ( ) : void
EnsureEditableDivsHaveIds ( XmlElement pageElt ) : void
EpubMaker ( BookThumbNailer thumbNailer, NavigationIsolator _isolator ) : NAudio.Wave
FinishEpub ( string destinationEpubPath ) : void

Finish publishing an ePUB that has been staged, by zipping it into the desired final file.

GetFontsUsed ( string bookPath, bool includeFallbackFonts ) : IEnumerable

First step of embedding fonts: determine what are used in the document. Eventually we may load each page into a DOM and use JavaScript to ask each bit of text what actual font and face it is using. For now we examine the stylesheets and collect the font families they mention.

RemoveTempIds ( XmlElement pageElt ) : void
SaveEpub ( string destinationEpubPath ) : void
StageEpub ( bool publishWithoutAudio = false ) : void

Generate all the files we will zip into the ePUB for the current book into the StagingFolder. It is required that the parent of the StagingFolder is a temporary folder into which we can copy the Readium stuff. This folder is deleted when the EpubMaker is disposed.

비공개 메소드들

메소드 설명
AddAudioOverlay ( HtmlDom pageDom, string pageDocName ) : void

Create an audio overlay for the page if appropriate. We are looking for the page to contain spans with IDs. For each such ID X, we look for a file _storage.FolderPath/audio/X.mp{3,4}. If we find at least one such file, we create pageDocName_overlay.smil with appropriate contents to tell the reader how to read all such spans aloud.

AddFontFace ( StringBuilder sb, string name, string weight, string style, string path ) : void
ConvertStyleFromPxToPercent ( string stylename, double pageWidthMm, double multiplier, string &imgStyle ) : bool
CopyFile ( string srcPath, string dstPath ) : void

This supports testing without actually copying files.

CopyFileToEpub ( string srcPath ) : string
CopyImages ( HtmlDom pageDom ) : void
CopyStyleSheets ( HtmlDom pageDom ) : void
EmbedFonts ( ) : void

Try to embed the fonts we need.

FixChangedFileNames ( HtmlDom pageDom ) : void
FixIllegalIds ( HtmlDom pageDom ) : void
FixPictureSizes ( HtmlDom pageDom ) : void

Typically pictures are given an absolute size in px, which looks right given the current absolute size of the page it is on. For an ePUB, a percent size will work better. We calculate it based on the page sizes and margins in BasePage.less and commonMixins.less. The page size definitions are unlikely to change, but change might be needed here if there is a change to the main .marginBox rule in basePage.less. To partly accommodate origami pages, we adjust for parent divs with an explict style setting the percent width.

GetEpubFriendlyHtmlDomForPage ( XmlElement page ) : HtmlDom
GetIdOfFile ( string item ) : string

Since file names often start with numbers, which ePUB validation won't allow for element IDs, stick an 'f' in front. Generally clean up file name to make a valid ID as similar as possible.

GetMediaType ( string item ) : string
GetOrCreateCompressedAudioIfWavExists ( string id ) : string
GetOverlayName ( string pageDocName ) : string
HasClass ( XmlElement elt, string className ) : bool
IsCompressedAudioForIdMissing ( string id ) : bool
MakeCompressedAudio ( string wavPath ) : string

Make a compressed audio file for the specified .wav file. (Or return null if it can't be done becaus we don't have a LAME package installed.)

MakeCssLinksAppropriateForEpub ( HtmlDom dom ) : void
MakeManifest ( string coverPageImageFile ) : void
MakeNavPage ( ) : void
MakePageFile ( XmlElement pageElement, int pageIndex, int firstContentPageIndex ) : HtmlDom
MakeSpine ( System.Xml.Linq.XNamespace opf, System.Xml.Linq.XElement rootElt, string manifestPath ) : void
RemoveBloomUiElements ( HtmlDom pageDom ) : void

Remove anything that has class bloom-ui

RemoveRegularStylesheets ( HtmlDom pageDom ) : void
RemoveScripts ( HtmlDom pageDom ) : void

We don't need to make scriptable books, and if our html contains scripts (which probably won't work on most readers) we have to add various attributes. Also our scripts are external refs, which would have to be fixed.

RemoveSpuriousLinks ( HtmlDom pageDom ) : void

Clean up any dangling pointers and similar spurious data.

RemoveUnwantedContent ( HtmlDom pageDom ) : void

Remove stuff that we don't want displayed. Some e-readers don't obey display:none. Also, not shipping it saves space.

ToValidXmlId ( string item ) : string

Given a filename, attempt to make a valid XML ID that is as similar as possible. - if it's OK don't change it - if it contains spaces remove them - if it starts with an invalid character add an initial 'f' - change other invalid characters to underlines We do this because ePUB technically uses XHTML and therefore follows XML rules. I doubt most readers care but validators do and we would like our ebooks to validate.

메소드 상세

Dispose() 공개 메소드

public Dispose ( ) : void
리턴 void

EnsureEditableDivsHaveIds() 공개 메소드

public EnsureEditableDivsHaveIds ( XmlElement pageElt ) : void
pageElt System.Xml.XmlElement
리턴 void

EpubMaker() 공개 메소드

public EpubMaker ( BookThumbNailer thumbNailer, NavigationIsolator _isolator ) : NAudio.Wave
thumbNailer BookThumbNailer
_isolator NavigationIsolator
리턴 NAudio.Wave

FinishEpub() 공개 메소드

Finish publishing an ePUB that has been staged, by zipping it into the desired final file.
public FinishEpub ( string destinationEpubPath ) : void
destinationEpubPath string
리턴 void

GetFontsUsed() 공개 정적인 메소드

First step of embedding fonts: determine what are used in the document. Eventually we may load each page into a DOM and use JavaScript to ask each bit of text what actual font and face it is using. For now we examine the stylesheets and collect the font families they mention.
public static GetFontsUsed ( string bookPath, bool includeFallbackFonts ) : IEnumerable
bookPath string
includeFallbackFonts bool
리턴 IEnumerable

RemoveTempIds() 공개 메소드

public RemoveTempIds ( XmlElement pageElt ) : void
pageElt System.Xml.XmlElement
리턴 void

SaveEpub() 공개 메소드

public SaveEpub ( string destinationEpubPath ) : void
destinationEpubPath string
리턴 void

StageEpub() 공개 메소드

Generate all the files we will zip into the ePUB for the current book into the StagingFolder. It is required that the parent of the StagingFolder is a temporary folder into which we can copy the Readium stuff. This folder is deleted when the EpubMaker is disposed.
public StageEpub ( bool publishWithoutAudio = false ) : void
publishWithoutAudio bool
리턴 void