コード例 #1
0
        //NB: make sure the <base> is set correctly, 'cause you don't know where this method will
        //save the file before navigating to it.
        public void Navigate(XmlDocument dom, XmlDocument editDom = null)
        {
            if (InvokeRequired)
            {
                Invoke(new Action <XmlDocument, XmlDocument>(Navigate), dom, editDom);
                return;
            }

            _rootDom     = dom;        //.CloneNode(true); //clone because we want to modify it a bit
            _pageEditDom = editDom ?? dom;

            /*	This doesn't work for the 1st book shown, or when you change book sizes.
             * But it's still worth doing, becuase without it, we have this annoying re-zoom every time we look at different page.
             */
            XmlElement body = (XmlElement)_rootDom.GetElementsByTagName("body")[0];

            if (ScaleToFullWidthOfPage)
            {
                var scale = GetScaleToShowWholeWidthOfPage();
                if (scale > 0f)
                {
                    body.SetAttribute("style", GetZoomCSS(scale));
                }
            }
            XmlHtmlConverter.MakeXmlishTagsSafeForInterpretationAsHtml(dom);
            SetNewTempFile(TempFileUtils.CreateHtm5FromXml(dom));
            _url = _tempHtmlFile.Path.ToLocalhost();
            UpdateDisplay();
        }
コード例 #2
0
        /// <summary>
        /// Returns true if it make some attempt at an image, false if navigation is currently suppressed.
        /// </summary>
        /// <param name="order"></param>
        /// <param name="browser"></param>
        /// <param name="thumbnail"></param>
        /// <returns></returns>
        private bool CreateThumbNail(ThumbnailOrder order, GeckoWebBrowser browser, out Image thumbnail)
        {
            // runs on threadpool thread
            thumbnail = null;
            using (var temp = TempFileUtils.CreateHtm5FromXml(order.Document))
            {
                order.Done  = false;
                browser.Tag = order;
                if (!OpenTempFileInBrowser(browser, temp.Path))
                {
                    return(false);
                }

                var browserSize = SetWidthAndHeight(browser);
                if (browserSize.Height == 0)          //happens when we run into the as-yet-unreproduced-or-fixed bl-254
                {
                    return(false);                    // will try again later
                }
                try
                {
                    Logger.WriteMinorEvent("HtmlThumNailer ({2}): browser.GetBitmap({0},{1})", browserSize.Width,
                                           (uint)browserSize.Height,
                                           Thread.CurrentThread.ManagedThreadId);
                    //BUG (April 2013) found that the initial call to GetBitMap always had a zero width, leading to an exception which
                    //the user doesn't see and then all is well. So at the moment, we avoid the exception, and just leave with
                    //the placeholder thumbnail.
                    if (browserSize.Width == 0 || browserSize.Height == 0)
                    {
                        var paperSizeName = GetPaperSizeName(order.Document);
                        throw new ApplicationException("Problem getting thumbnail browser for document with Paper Size: " +
                                                       paperSizeName);
                    }
                    using (Image fullsizeImage = CreateImage(browser))
                    {
                        if (_disposed)
                        {
                            return(false);
                        }
                        thumbnail = MakeThumbNail(fullsizeImage, order.Options);
                        return(true);
                    }
                }
                catch (Exception error)
                {
                    Logger.WriteEvent("HtmlThumbNailer ({0}) got {1}", Thread.CurrentThread.ManagedThreadId, error.Message);
                    Logger.WriteEvent("Disposing of all browsers in hopes of getting a fresh start on life");
                    foreach (var browserCacheForDifferentPaperSize in _browserCacheForDifferentPaperSizes)
                    {
                        try
                        {
                            Logger.WriteEvent("Disposing of browser {0}", browserCacheForDifferentPaperSize.Key);
                            browserCacheForDifferentPaperSize.Value.Dispose();
                        }
                        catch (Exception e2)
                        {
                            Logger.WriteEvent(
                                "While trying to dispose of thumbnailer browsers as a result of an exception, go another: " + e2.Message);
                        }
                    }
                    _browserCacheForDifferentPaperSizes.Clear();
#if DEBUG
                    _syncControl.Invoke((Action)(() => Debug.Fail(error.Message)));
#endif
                }
            }
            return(false);
        }