From 635f7831280e9ea65751ae829edb56effe1d6445 Mon Sep 17 00:00:00 2001 From: Gerald Schmidt Date: Mon, 7 Dec 2009 01:38:20 +0000 Subject: [PATCH] Update for DAISY integration ahead of 1.2.0.7. --- src/playlistrenamer.cpp | 28 ++++- src/playlistrenamer.h | 2 +- src/wrapdaisy.cpp | 53 +++++++-- src/xmlcopyeditorcopy.h | 2 +- src/xmlcopyimg.cpp | 2 +- src/xsl/openlearn2daisyhtml/inline.xsl | 133 +++++++++++++++------- src/xsl/openlearn2daisyhtml/lang.xsl | 10 +- src/xsl/openlearn2daisyhtml/object.xsl | 93 ++++++++------- src/xsl/openlearn2daisyhtml/structure.xsl | 116 ++++++++++++++----- 9 files changed, 308 insertions(+), 131 deletions(-) diff --git a/src/playlistrenamer.cpp b/src/playlistrenamer.cpp index eaa18bc..8657d5e 100644 --- a/src/playlistrenamer.cpp +++ b/src/playlistrenamer.cpp @@ -10,25 +10,39 @@ bool PlayListRenamer::run ( { std::string m3uFile, m3uBuffer; m3uFile = folder + "playlist.m3u"; + if ( !readFile ( m3uFile, m3uBuffer ) ) + { return false; + } std::vector lines; if ( !splitBuffer ( m3uBuffer, lines ) ) + { + wxMessageBox ( _T("can't split buffer") ); return false; + } std::string title, from, to; size_t lineCount = lines.size(); int trackNo = 0; + + wxString random; + random.Printf ( _T("%i"), lineCount ); + wxMessageBox (random ); for ( size_t i = 0; i < lineCount; i++ ) { + wxString line; + line = wxString ( lines[i].c_str(), wxConvUTF8, lines[i].size() ); + wxMessageBox ( line ); + if ( lines[i][0] == '#' ) { - if ( !lines[i].find ( "EXTINF" ) ) + if ( lines[i].find ( "EXTINF" ) == std::string::npos ) continue; //isolate m3u trackname - std::string pattern0 = ".*?,"; + std::string pattern0 = ".+?,"; WrapRegex re0 ( pattern0, true ); int replacements; title = re0.replaceGlobal ( lines[i], &replacements ); @@ -66,6 +80,10 @@ bool PlayListRenamer::run ( from = lines[i]; to = title; + wxString wideFrom, wideTo; + wideFrom = wxString ( from.c_str(), wxConvUTF8, from.size() ); + wideTo = wxString ( to.c_str(), wxConvUTF8, to.size() ); + renameFile ( from, to, folder ); editFiles ( from, to, folder ); @@ -88,8 +106,9 @@ bool PlayListRenamer::readFile ( const std::string& path, std::string& buffer ) return true; } -bool PlayListRenamer::splitBuffer ( const std::string& buffer, std::vector lineVector ) +bool PlayListRenamer::splitBuffer ( const std::string& buffer, std::vector& lineVector ) { + wxMessageBox ( wxString ( buffer.c_str(), wxConvUTF8, buffer.size() ) ); std::string line; lineVector.clear(); size_t bufferSize = buffer.size(); @@ -134,7 +153,8 @@ void PlayListRenamer::renameFile ( const std::string& from, const std::string& t wideFolder = wxString ( folder.c_str(), wxConvUTF8, folder.size() ); wideFrom = wxString ( from.c_str(), wxConvUTF8, from.size() ); wideTo = wxString ( to.c_str(), wxConvUTF8, to.size() ); - wxRenameFile ( wideFolder + wideFrom, wideFolder + wideTo ); + wxMessageBox ( wideFolder + wideFrom, wideFolder + wideTo ); + //wxRenameFile ( wideFolder + wideFrom, wideFolder + wideTo ); } void PlayListRenamer::editFiles ( const std::string& from, const std::string& to, const std::string& folder ) diff --git a/src/playlistrenamer.h b/src/playlistrenamer.h index 7b5a261..87717dc 100644 --- a/src/playlistrenamer.h +++ b/src/playlistrenamer.h @@ -12,7 +12,7 @@ public: bool run ( const std::string& folder ); private: bool readFile ( const std::string& path, std::string& buffer ); - bool splitBuffer ( const std::string& buffer, std::vector lineVector ); + bool splitBuffer ( const std::string& buffer, std::vector& lineVector ); void renameFile ( const std::string& from, const std::string& to, const std::string& folder ); void editFiles ( const std::string& from, const std::string& to, const std::string& folder ); std::string numToString ( int i ); diff --git a/src/wrapdaisy.cpp b/src/wrapdaisy.cpp index 173013f..3009fa8 100755 --- a/src/wrapdaisy.cpp +++ b/src/wrapdaisy.cpp @@ -11,7 +11,9 @@ #include "xmlcopyimg.h" #include "binaryfile.h" #include "replace.h" +#include "wrapregex.h" #include "mp3album.h" +//#include "playlistrenamer.h" #ifdef __WXMSW__ #include @@ -194,6 +196,19 @@ bool WrapDaisy::run ( // prevent MIME type errors in href="www..." attributes Replace::run ( output, "href=\"www", "href=\"http://www", true ); + + // remove em-space + Replace::run ( output, "\xE2\x80\x83", " ", true ); + + // remove blank paragraphs + Replace::run ( output, "

", "", true ); + + int replaceCount; + WrapRegex regexParaWhitespace ( "

\\w+

", true ); + output = regexParaWhitespace.replaceGlobal ( output, &replaceCount ); + + WrapRegex regexContiguousWhitespace ( "[\\t ]+", true, " " ); + output = regexContiguousWhitespace.replaceGlobal ( output, &replaceCount ); // copy images wxString htmlDir, imagesDir, mediaDir; @@ -245,7 +260,7 @@ bool WrapDaisy::run ( while (wxTheApp->Pending()) wxTheApp->Dispatch(); - if ( !pd->Update ( 25, _("Copying images and audio files...") ) ) + if ( !pd->Update ( 25, _("Copying files...") ) ) { error = _ ( "Cancelled" ); return false; @@ -299,7 +314,7 @@ bool WrapDaisy::run ( wxString cmd = baseCmd + xhtml2dtbookScript + _T(" --inputFile=\"") + - canonicalFile + //canonicalFile.wideName() + + canonicalFile + _T("\" --outputFile=\"") + dtbFilePath + _T("\""); @@ -328,7 +343,7 @@ bool WrapDaisy::run ( if ( !error.empty() ) return false; - // #2.5: create EPUB version + // #2.5: create ePub version pd->ProcessPendingEvents(); while (wxTheApp->Pending()) wxTheApp->Dispatch(); @@ -403,7 +418,15 @@ bool WrapDaisy::run ( rtfScript += wxFileName::GetPathSeparator(); rtfScript += _T("DtbookToRtf.taskScript"); - wxString rtfFile = folder + wxFileName::GetPathSeparator() + _T("document.rtf"); + wxString rtfFile, tempRtfFile, docFile, tempDocFile; + rtfFile = folder + wxFileName::GetPathSeparator() + _T("document.rtf"); + tempRtfFile = folder + wxFileName::GetPathSeparator() + _T("html") + + wxFileName::GetPathSeparator() + _T("document.rtf"); + + docFile = rtfFile; + tempDocFile = tempRtfFile; + docFile.Replace ( _T(".rtf"), _T(".doc") ); + tempDocFile.Replace ( _T(".rtf"), _T(".doc") ); cmd = baseCmd + _T("\"") + rtfScript + _T("\" --input=\"") + @@ -451,9 +474,8 @@ bool WrapDaisy::run ( return false; } - - wxString docFile = rtfFile; - docFile.Replace ( _T(".rtf"), _T(".doc") ); + //wxString docFile = rtfFile; + //docFile.Replace ( _T(".rtf"), _T(".doc") ); #ifdef __WXMSW__ wxAutomationObject wordObject, documentObject; @@ -461,17 +483,17 @@ bool WrapDaisy::run ( if ( wordObject.CreateInstance ( _T("Word.Application") ) ) { wxVariant openParams[2]; - openParams[0] = rtfFile; + openParams[0] = rtfFile;//tempRtfFile openParams[1] = false; wordObject.CallMethod(_("documents.open"), 2, openParams); if (!wordObject.GetObject(documentObject, _("ActiveDocument"))) { - error = _("Cannot open ") + rtfFile; + error = _("Cannot open ") + rtfFile;//tempRtfFile; return false; } wxVariant saveAsParams[2]; - saveAsParams[0] = docFile; + saveAsParams[0] = docFile;//tempDocFile;// saveAsParams[1] = (long)0; //wdFormatDocument if ( !documentObject.CallMethod(_("SaveAs"), 2, saveAsParams) ) { @@ -482,9 +504,15 @@ bool WrapDaisy::run ( wordObject.CallMethod(_T("Quit"), 0, NULL ); } #else + //wxCopyFile ( tempRtfFile, tempDocFile ); wxCopyFile ( rtfFile, docFile ); #endif + //wxCopyFile ( tempRtfFile, rtfFile ); + //wxCopyFile ( tempDocFile, docFile ); + //wxRemoveFile ( tempRtfFile ); + //wxRemoveFile ( tempDocFile ); + // #3: convert to full DAISY book pd->ProcessPendingEvents(); while (wxTheApp->Pending()) @@ -629,12 +657,13 @@ bool WrapDaisy::run ( return false; } - //rename mp3 playlists /* + //rename mp3 playlists + albumDir += wxFileName::GetPathSeparator(); PlayListRenamer plr; std::string stdAlbumDir = ( const char *) albumDir.mb_str ( wxConvUTF8 ); plr.run ( stdAlbumDir ); -*/ +*/ //rename mp3 files in //z3986/ wxFileName fn ( dtbFilePath ); diff --git a/src/xmlcopyeditorcopy.h b/src/xmlcopyeditorcopy.h index f8a836b..9540c0e 100755 --- a/src/xmlcopyeditorcopy.h +++ b/src/xmlcopyeditorcopy.h @@ -41,7 +41,7 @@ "License along with this program; if not, write to the Free\n"\ "Software Foundation, Inc., 59 Temple Place, Suite 330,\n"\ "Boston, MA 02111-1307 USA.") -#define ABOUT_VERSION _T("1.2.0.6") +#define ABOUT_VERSION _T("1.2.0.7") #define XMLCE_VAR _T("XMLCE_VAR") #ifdef __WXMSW__ diff --git a/src/xmlcopyimg.cpp b/src/xmlcopyimg.cpp index 6ba6aa5..1dabc10 100644 --- a/src/xmlcopyimg.cpp +++ b/src/xmlcopyimg.cpp @@ -135,7 +135,7 @@ void XMLCALL XmlCopyImg::start ( void *data, { wxString cmd; cmd += IMAGEMAGICK_CONVERT_PATH; - cmd += _T(" -resize 720x1440>"); + cmd += _T(" -resize 720x720>"); cmd += _T(" \""); cmd += wideFile; cmd += _T("\" \""); diff --git a/src/xsl/openlearn2daisyhtml/inline.xsl b/src/xsl/openlearn2daisyhtml/inline.xsl index 7f52034..c2291d7 100644 --- a/src/xsl/openlearn2daisyhtml/inline.xsl +++ b/src/xsl/openlearn2daisyhtml/inline.xsl @@ -36,60 +36,107 @@ - -
-
- Side note -
- - End of side note -
-
-
- -
- - - -
- -
- -
- -
-
- Footnote -
- -
-
- End of footnote -
-
-
- + + + + + + + + + + + + + + + + + + + + + + no alternative text + + + + + + + + +
- + + - + + + + + + + + + + + + no alternative text + + - - -
+ + + + + + + + + + + + + + + + + + + + + + + no alternative text + + + + + + + + + - - -
-
- + + + + + + + + + diff --git a/src/xsl/openlearn2daisyhtml/lang.xsl b/src/xsl/openlearn2daisyhtml/lang.xsl index f963249..c33ce8b 100644 --- a/src/xsl/openlearn2daisyhtml/lang.xsl +++ b/src/xsl/openlearn2daisyhtml/lang.xsl @@ -1,12 +1,20 @@ + - + + + + + + + + diff --git a/src/xsl/openlearn2daisyhtml/object.xsl b/src/xsl/openlearn2daisyhtml/object.xsl index 7d82a3d..bc38c7c 100644 --- a/src/xsl/openlearn2daisyhtml/object.xsl +++ b/src/xsl/openlearn2daisyhtml/object.xsl @@ -19,8 +19,8 @@ -

  -
+

 

@@ -105,24 +105,26 @@

- - - - - - - - - - - - - - no alternative text - - - - +

+ + + + + + + + + + + + + + no alternative text + + + + +

@@ -143,24 +145,26 @@

- - - - - - - - - - - - - - no alternative text - - - - +

+ + + + + + + + + + + + + + no alternative text + + + + +

@@ -396,4 +400,17 @@ End of summary

+ +
+ Side note + + End of side note +
+
+ + + + + +
diff --git a/src/xsl/openlearn2daisyhtml/structure.xsl b/src/xsl/openlearn2daisyhtml/structure.xsl index 601a5b9..3a8dbaf 100644 --- a/src/xsl/openlearn2daisyhtml/structure.xsl +++ b/src/xsl/openlearn2daisyhtml/structure.xsl @@ -1,9 +1,11 @@ +

+
@@ -16,6 +18,11 @@ + +

+ +

+

@@ -126,25 +133,52 @@ - -

- [Audio content] -

-

- .mp3MP3 file - -

- - -

- [PDF content] -

- -
+ + +

+ Audio content +

+

+ .mp3MP3 file + +

+
+ +

+ Java content +

+

+ .jarJava + file +

+
+ +

+ Flash content +

+

+ .swfFlash file + +

+
+ +

+ Movie content +

+

+ .mp4Flash file + +

+
+ +

+ PDF content +

+ + +
+
-

- End of content -

@@ -156,7 +190,8 @@ - +
@@ -176,18 +211,18 @@

- Alternative: + Alternative text:

-

- - Description: - - -

+ +

+ Description: +

+

@@ -246,14 +281,35 @@

-
hours
-
-
minutes
-
+
+ hours
+
+
+ minutes
+
+ + +
+ + + false + + +
+
+
+ + + +

Footnote : +

+
+
+