New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FB3 format basic support (for QT only) #105
Conversation
(@Frenzie : looks easily mergable, but let's wait a bit for followup stuff if any - as there's no real demand for fb3 on our side.) @pkb : regarding your 4th issue:
We may have fixed that in koreader/crengine#143 (small commit koreader/crengine@3a74635 ). Mostly tested with links, but may work with images src. |
@poire-z, thanks with this patch I'm able to see proper file name in the error message in the log. The image is in a zip file so it seems I shouldn't call DecodeHTMLUrlString() to open it. I just don't know conditions when to call and when not, so i'm going to leave it as is. Don't think it is a big issue. |
@pkb, just retry without DecodeHTMLUrlString() if file can't be opened. Like this: diff --git a/crengine/include/lvtinydom.h b/crengine/include/lvtinydom.h
index 30549a092..e5bd05813 100644
--- a/crengine/include/lvtinydom.h
+++ b/crengine/include/lvtinydom.h
@@ -851,7 +851,7 @@ public:
/// returns object image source
LVImageSourceRef getObjectImageSource();
/// returns object image ref name
- lString16 getObjectImageRefName();
+ lString16 getObjectImageRefName(bool percentDecode = true);
/// returns object image stream
LVStreamRef getObjectImageStream();
/// formats final block
diff --git a/crengine/src/lvtinydom.cpp b/crengine/src/lvtinydom.cpp
index 1f7daa7c7..d96c2c113 100644
--- a/crengine/src/lvtinydom.cpp
+++ b/crengine/src/lvtinydom.cpp
@@ -11035,7 +11035,7 @@ public:
};
/// returns object image ref name
-lString16 ldomNode::getObjectImageRefName()
+lString16 ldomNode::getObjectImageRefName(bool percentDecode)
{
if (!isElement())
return lString16::empty_str;
@@ -11072,7 +11072,8 @@ lString16 ldomNode::getObjectImageRefName()
}
if ( refName.length()<2 )
return lString16::empty_str;
- refName = DecodeHTMLUrlString(refName);
+ if (percentDecode)
+ refName = DecodeHTMLUrlString(refName);
return refName;
}
@@ -11090,11 +11091,18 @@ LVStreamRef ldomNode::getObjectImageStream()
/// returns object image source
LVImageSourceRef ldomNode::getObjectImageSource()
{
- lString16 refName = getObjectImageRefName();
+ lString16 refName = getObjectImageRefName(true);
LVImageSourceRef ref;
if ( refName.empty() )
return ref;
ref = getDocument()->getObjectImageSource( refName );
+ if (ref.isNull()) {
+ // try again without percent decoding (for fb3)
+ refName = getObjectImageRefName(false);
+ if ( refName.empty() )
+ return ref;
+ ref = getDocument()->getObjectImageSource( refName );
+ }
if ( !ref.isNull() ) {
int dx = ref->GetWidth();
int dy = ref->GetHeight(); |
@virxkane thanks for testing, no it is not right, i will make it inline in fb3.css and will apply your patch for DecodeHTMLUrlString() today. |
Tag "spacing": still new paragraphs created. diff --git a/crengine/src/fb3fmt.cpp b/crengine/src/fb3fmt.cpp
index 9d2dcd9d5..e0e3bab8c 100644
--- a/crengine/src/fb3fmt.cpp
+++ b/crengine/src/fb3fmt.cpp
@@ -4,6 +4,7 @@
const lChar16 * const fb3_BodyContentType = L"application/fb3-body+xml";
const lChar16 * const fb3_PropertiesContentType = L"application/vnd.openxmlformats-package.core-properties+xml";
+const lChar16 * const fb3_DescriptionContentType = L"application/fb3-description+xml";
const lChar16 * const fb3_CoverRelationship = L"http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail";
const lChar16 * const fb3_ImageRelationship = L"http://www.fictionbook.org/FictionBook3/relationships/image";
@@ -128,10 +129,24 @@ bool ImportFb3Document( LVStreamRef stream, ldomDocument * doc, LVDocViewCallbac
return false;
}
+ LVStreamRef descStream = arc->OpenStream(context.getContentPath(fb3_DescriptionContentType).c_str(), LVOM_READ );
+ if ( descStream.isNull() ) {
+ CRLog::error("Couldn't read description");
+ return false;
+ }
+
+ ldomDocument * descDoc = LVParseXMLStream( descStream );
+ if ( !descDoc ) {
+ CRLog::error("Couldn't parse description doc");
+ return false;
+ }
+
lString16 author = propertiesDoc->textFromXPath( cs16("coreProperties/creator") );
lString16 title = doc->textFromXPath( cs16("coreProperties/title") );
+ lString16 language = descDoc->textFromXPath( cs16("fb3-description/lang") );
doc_props->setString(DOC_PROP_TITLE, title);
doc_props->setString(DOC_PROP_AUTHORS, author );
+ doc_props->setString(DOC_PROP_LANGUAGE, language);
CRLog::info("Author: %s Title: %s", author.c_str(), title.c_str());
delete propertiesDoc; |
@virxkane thanks, now spacing should be inline, but it looks like we have a glitch with letter-spacing |
@pkb Can you fix this glitches? |
Don't know. I will take a look, if it will not require much efforts I will :). |
…ns of a paragaraf
@pkb looks good. |
Skip elements among siblings that are not list items. By @pkb from buggins/coolreader#105
Skip elements among siblings that are not list items. By @pkb from buggins/coolreader#105
Open issues