Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 02-10-2023, 01:52 PM   #31
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,911
Karma: 6120478
Join Date: Nov 2009
Device: many
Actually, by stealing some code from PageEdit (which marks the id of any injected dark mode code) and borrowing liberally from its GetCleanHTML routine) we could just grab the current contents of the PreviewWindow processed html, then use gumbo to clean it of Dark mode crap we injected (but keep any mathml stuff), so we could effectively create a printable PreviewWindow.

In Utility.cpp we would have to modify our DARK_STYLE to set an id attribute to make it easy to remove. Based on PageEdit's version this would look something like:

Code:
static const QString DARK_STYLE =
    "<style id=\"Sigil_Injected\">:root { background-color: %1; color: %2; } ::-webkit-scrollbar { display: none; }</style>"
    "<link rel=\"stylesheet\" type=\"text/css\" href=\"%3\" />";
And we could create a routine to remove that injected code and the following css dark mode links by doing something like:

Code:
static const QStringList DARKCSSLINKS = QStringList() << "qrc:///dark/mac_dark_scrollbar.css" 
                                                      << "qrc:///dark/win_dark_scrollbar.css" 
                                                      << "qrc:///dark/lin_dark_scrollbar.css";

QString PreviewWindow::GetHtmlWithNoDarkMode() 
{
    QString text = m_Preview->GetHtml();

    // now remove any leftovers and make sure it is well formed
    GumboInterface gi = GumboInterface(text, "any_version");

    QList<GumboNode*> nodes;
    QList<GumboTag> tags;

    // remove any added AddDarkCSS (style node has id="Sigil_Injected")
    tags = QList<GumboTag>() << GUMBO_TAG_STYLE;
    nodes = gi.get_all_nodes_with_tags(tags);
    foreach(GumboNode * node, nodes) {
        GumboAttribute* attr = gumbo_get_attribute(&node->v.element.attributes, "id");
        if (attr && QString::fromUtf8(attr->value) == "Sigil_Injected") {
            // qDebug() << "removing Sigil_Injected dark style";
            gumbo_remove_from_parent(node);
            gumbo_destroy_node(node);
            break;
        }
    }
    // then the associated scrollbar stylesheet link
    tags = QList<GumboTag>() << GUMBO_TAG_LINK;
    nodes = gi.get_all_nodes_with_tags(tags);
    foreach(GumboNode * node, nodes) {
        GumboAttribute* attr = gumbo_get_attribute(&node->v.element.attributes, "href");
        if (attr) {
            QString attrval = QString::fromUtf8(attr->value);
            if (DARKCSSLINKS.contains(attrval) ) {
                // qDebug() << "removing dark css links";
                gumbo_remove_from_parent(node);
                gumbo_destroy_node(node);
                break;
            }
        }
    }

    text = gi.getxhtml();
    return text;
}
Then we could create a second hidden ViewEditors/ViewPreview (call it maybe "PrintablePreview") and use its CustomSetDocument to load it with our just cleaned html and to set its base location so that links work. The equivalent of:

m_PrintablePreview->CustomSetDocument(m_FilePath, text);

Something close to that should work as it does with PageEdit.

Last edited by KevinH; 02-10-2023 at 02:17 PM.
KevinH is offline   Reply With Quote
Old 02-10-2023, 02:02 PM   #32
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,709
Karma: 205039118
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
I was looking at the same possibility. It doesn't look like it would be difficult to strip the injected darkmode stuff. They'd still be looking at the possibility of printing background colors from the epub's css itself, but that's what the warning is for.

We probably wouldn't even have to worry about cleaning the scrollbar stuff; it's not going to be seen/printed anyway (at least I don't _think_ the print preview would use the dark scrollbar). But it wouldn't hurt to be thorough.

Last edited by DiapDealer; 02-10-2023 at 02:06 PM.
DiapDealer is online now   Reply With Quote
Advert
Old 02-10-2023, 02:14 PM   #33
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,911
Karma: 6120478
Join Date: Nov 2009
Device: many
Good point. We could also choose to strip out the usercss but if we leave that in, that might be a way for the user to overide some silly epub backgrounds to allow it to be more easily printable.

So we can use your current webviewprinter for printing Image and AV tabs and then create a second specialized version that uses our ViewPreview widget to create the PrintablePreview.

That second version is where the clean out darkmode code could be and so we just grab the latest html and fileurl fromPreview Window and pass them to this specialized second version to do all the work.

That should help keep PreviewWindow from getting much more complex except for the new icon and handling routine.

Last edited by KevinH; 02-10-2023 at 02:18 PM.
KevinH is offline   Reply With Quote
Old 02-15-2023, 11:02 AM   #34
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,911
Karma: 6120478
Join Date: Nov 2009
Device: many
So PrintPreview and Printing is now working for ImageTabs and for the PreviewWindow (Preview) in Sigil master. This will entail one more round of translation updates so I hope to push a new base.ts tonight.

I can not see adding any Print capability to AVTabs as audio can not be printed and video would only show an empty/first frame statically.

Last edited by KevinH; 02-15-2023 at 11:04 AM.
KevinH is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
table in reader doesn't look like preview in Sigil gib65 Sigil 11 11-15-2013 05:32 PM
Print Preview Problem townsend Sigil 3 05-11-2013 05:11 PM
preview vs print preview isalherbo Sigil 7 04-23-2013 03:52 PM
Print Preview problems illustrata Sigil 5 10-25-2011 02:50 PM
eBook viewer Print Preview settings not saved Agama Calibre 3 08-22-2010 08:04 PM


All times are GMT -4. The time now is 09:32 PM.


MobileRead.com is a privately owned, operated and funded community.