/// <summary> /// Check for either "Device16x9Portrait" or "Device16x9Landscape" layout. /// Complain to the user if another layout is currently chosen. /// </summary> /// <remarks> /// See https://issues.bloomlibrary.org/youtrack/issue/BL-5274. /// </remarks> public static void CheckBookLayout(Bloom.Book.Book book, WebSocketProgress progress) { var layout = book.GetLayout(); var desiredLayoutSize = "Device16x9"; if (layout.SizeAndOrientation.PageSizeName != desiredLayoutSize) { // The progress object has been initialized to use an id prefix. So we'll access L10NSharp explicitly here. We also want to make the string blue, // which requires a special argument. // var msgFormat = L10NSharp.LocalizationManager.GetString("Common.Note", // "Note", "A heading shown above some messages."); // progress.MessageWithoutLocalizing(msgFormat, MessageKind.Note); var msgFormat = L10NSharp.LocalizationManager.GetString("PublishTab.Android.WrongLayout.Message", "The layout of this book is currently \"{0}\". Bloom Reader will display it using \"{1}\", so text might not fit. To see if anything needs adjusting, go back to the Edit Tab and change the layout to \"{1}\".", "{0} and {1} are book layout tags."); var desiredLayout = desiredLayoutSize + layout.SizeAndOrientation.OrientationName; var msg = String.Format(msgFormat, layout.SizeAndOrientation.ToString(), desiredLayout, Environment.NewLine); progress.MessageWithoutLocalizing(msg, MessageKind.Note); } }
/// <summary> /// Remove image elements that are invisible due to the book's layout orientation. /// </summary> /// <remarks> /// This code is temporary for Version4.5. Version4.6 extensively refactors the /// electronic publishing code to combine ePUB and BloomReader preparation as much /// as possible. /// </remarks> private static void RemoveInvisibleImageElements(Bloom.Book.Book book) { var isLandscape = book.GetLayout().SizeAndOrientation.IsLandScape; foreach (var img in book.RawDom.SafeSelectNodes("//img").Cast <XmlElement>().ToArray()) { var src = img.Attributes["src"]?.Value; if (string.IsNullOrEmpty(src)) { continue; } var classes = img.Attributes["class"]?.Value; if (string.IsNullOrEmpty(classes)) { continue; } if (isLandscape && classes.Contains("portraitOnly") || !isLandscape && classes.Contains("landscapeOnly")) { // Remove this img element since it shouldn't be displayed. img.ParentNode.RemoveChild(img); } } }