Ejemplo n.º 1
0
        private void NavigateToPercent(BookLocation location)
        {
            var navScript = $"scrollToPercent({location.ScrollPercent});\n";

            uiAllUpPosition.UpdatePosition(location.HtmlIndex, location.HtmlPercent);
            if (CurrHtmlIndex == location.HtmlIndex)
            {
                // Great! just scroll to the place!
                Logger.Log($"Main EBOOK: navigate to SAME html");
                var task = uiHtml.InvokeScriptAsync("scrollToPercent", new List <string>()
                {
                    location.ScrollPercent.ToString()
                });
                DoUserNavigateToAsNeeded();
                return;
            }
            else
            {
                if (Logger.LogExtraTiming)
                {
                    Logger.Log($"Main EBOOK: navigate to other html (htmlindex={location.HtmlIndex})");
                }
                var foundIndex = location.HtmlIndex;
                var foundHtml  = EpubWizard.FindHtmlByIndex(EpubBook, foundIndex);
                if (Logger.LogExtraTiming)
                {
                    Logger.Log($"Main EBOOK: navigate to other html {foundIndex}=len {foundHtml?.Length}");
                }

                var html = HtmlFixup.FixupHtmlAll(foundHtml);
                DeferredNavigation = navScript;
                CurrHtml           = html;
                CurrHtmlIndex      = foundIndex;
                CurrHtmlFileName   = location.HtmlFileName;

                Logger.Log($"Main EBOOK: about to navigate with deferred navigation {DeferredNavigation}");
                uiHtml.NavigateToString(html);
            }
            SavePositionEZ();
        }
Ejemplo n.º 2
0
        private void NavigateToLocation(BookLocation location)
        {
            // Gutenberg: just a location which we have to figure out
            // BAEN: HtmlFileName and (for sub-chapters) a Location, too.
            // Location might have just an id in it
            // OR it might have just an HtmlFileName
            // USPS: the location is an XHTML file that's encoded: Additional%20Resources.xhtml instead of Additional Resources.html
            //
            // OR an id+HtmlIndex.
            // We actually don't need the index!

            if (!string.IsNullOrEmpty(location.HtmlFileName))
            {
                // Jump to percent 0.0 after finding the html by name.
                // navScript is either to an id or just to the top
                var navScript = string.IsNullOrEmpty(location.Location) ? $"scrollToPercent(0.0)" : $"scrollToId('{location.Location}')";
                var(foundHtml, foundIndex, foundHtmlFileName) = EpubWizard.FindHtmlContainingHtmlFileName(EpubBook, location.HtmlFileName);
                if (foundHtml == null)
                {
                    App.Error($"ERROR: unable to navigate to htmlFileName={location.HtmlFileName}");
                    return; // nuts; can't find it.
                }

                // If we're jumping to the current spot, meh, don't bother to optimize.
                // Maybe the user wants to do the full amount of code because of "issues"

                var html = HtmlFixup.FixupHtmlAll(foundHtml);
                DeferredNavigation = navScript;
                uiHtml.NavigateToString(html);

                CurrHtml         = html;
                CurrHtmlIndex    = foundIndex;
                CurrHtmlFileName = foundHtmlFileName;

                return;
            }
            else
            {
                string id = location.Location;

                // Find the html with the tag
                // FAIL: BAEN books only navigate by html name. The name will be found in the TOC because there are links!
                // FAIL: Gutenberg John Thorndyke Cases searching for the shoes.png. The long id @public@vhost@g@gutenberg@html@files@13882@13882-h@[email protected]
                // is found in the first HTML but only because that HTML includes a list of illustrations which point to an HTML file that includes the
                // shoes.png file (but that html file has a name that starts with the png but then adds on .wrap-0.html.html.
                // The code here used to just see if the current HTML includes the id at all; the better code checks to make sure it's a proper href.
                if (CurrHtml != null && EpubWizard.HtmlStringIdIndexOf(CurrHtml, id, true) >= 0 && CurrHtml.Contains("scrollToId"))
                {
                    var task = uiHtml.InvokeScriptAsync("scrollToId", new List <string>()
                    {
                        id
                    });
                    DoUserNavigateToAsNeeded();
                    return;
                }

                var idList = EpubWizard.GetIdVariants(id);
                var(foundHtml, foundIndex, foundHtmlFileName, foundId) = EpubWizard.FindHtmlContainingId(EpubBook, idList, location.HtmlIndex);
                if (foundHtml == null)
                {
                    App.Error($"ERROR: unable to navigate to {id}");
                    return; // nuts; can't find it.
                }
                var navScript = $"scrollToId('{foundId}')";
                var html      = HtmlFixup.FixupHtmlAll(foundHtml);
                DeferredNavigation = navScript;
                uiHtml.NavigateToString(html);

                CurrHtml         = html;
                CurrHtmlIndex    = foundIndex;
                CurrHtmlFileName = foundHtmlFileName;
            }
            SavePositionEZ();
        }