public static GetConfigurationsFromConfigurationOptionsString ( string contents ) : List |
||
contents | string | |
return | List |
public static IEnumerable <Layout> GetLayoutChoices(HtmlDom dom, IFileLocator fileLocator) { //here we walk through all the stylesheets, looking for one with the special style which tells us which page/orientations it supports foreach (XmlElement link in dom.SafeSelectNodes("//link[@rel='stylesheet']")) { var fileName = link.GetStringAttribute("href"); if (fileName.ToLowerInvariant().Contains("mode") || fileName.ToLowerInvariant().Contains("page") || fileName.ToLowerInvariant().Contains("matter") || fileName.ToLowerInvariant().Contains("languagedisplay") || fileName.ToLowerInvariant().Contains("origami")) { continue; } fileName = fileName.Replace("file://", "").Replace("%5C", "/").Replace("%20", " "); var path = fileLocator.LocateFile(fileName); if (string.IsNullOrEmpty(path)) { // We're looking for a block of json that is typically found in Basic Book.css or a comparable place for // a book based on some other template. Caling code is prepared for not finding this block. // It seems safe to ignore a reference to some missing style sheet. NonFatalProblem.Report(ModalIf.None, PassiveIf.Alpha, "Could not find " + fileName + " while looking for size choices"); continue; } var contents = RobustFile.ReadAllText(path); var start = contents.IndexOf("STARTLAYOUTS"); if (start < 0) { continue; //yield break; // continue;//move on to the next stylesheet } start += "STARTLAYOUTS".Length; var end = contents.IndexOf("ENDLAYOUTS", start); var s = contents.Substring(start, end - start); IEnumerable <Layout> layouts = null; try { layouts = Layout.GetConfigurationsFromConfigurationOptionsString(s); } catch (Exception e) { throw new ApplicationException("Problem parsing the 'layouts' comment of " + fileName + ". The contents were\r\n" + s, e); } foreach (var p in layouts) { yield return(p); } yield break; } //default to A5Portrait yield return(new Layout { SizeAndOrientation = FromString("A5Portrait") }); }
public static IEnumerable <Layout> GetLayoutChoices(HtmlDom dom, IFileLocator fileLocator) { //here we walk through all the stylesheets, looking for one with the special style which tells us which page/orientations it supports foreach (XmlElement link in dom.SafeSelectNodes("//link[@rel='stylesheet']")) { var fileName = link.GetStringAttribute("href"); if (fileName.ToLower().Contains("mode") || fileName.ToLower().Contains("page") || fileName.ToLower().Contains("matter") || fileName.ToLower().Contains("languagedisplay")) { continue; } fileName = fileName.Replace("file://", "").Replace("%5C", "/"); fileName = fileName.Replace("file://", "").Replace("%20", " "); var path = fileLocator.LocateFile(fileName); if (string.IsNullOrEmpty(path)) { throw new ApplicationException("Could not locate " + fileName); } var contents = File.ReadAllText(path); var start = contents.IndexOf("STARTLAYOUTS"); if (start < 0) { continue; //yield break; // continue;//move on to the next stylesheet } start += "STARTLAYOUTS".Length; var end = contents.IndexOf("ENDLAYOUTS", start); var s = contents.Substring(start, end - start); IEnumerable <Layout> layouts = null; try { layouts = Layout.GetConfigurationsFromConfigurationOptionsString(s); } catch (Exception e) { throw new ApplicationException("Problem parsing the 'layouts' comment of " + fileName + ". The contents were\r\n" + s, e); } foreach (var p in layouts) { yield return(p); } yield break; } //default to A5Portrait yield return(new Layout { SizeAndOrientation = FromString("A5Portrait") }); }
public static IEnumerable <Layout> GetLayoutChoices(HtmlDom dom, IFileLocator fileLocator) { //here we walk through all the stylesheets, looking for one with the special comment which tells us which page/orientations it supports foreach (XmlElement link in dom.SafeSelectNodes("//link[@rel='stylesheet']")) { var fileName = link.GetStringAttribute("href"); if (fileName.ToLowerInvariant().Contains("mode") || fileName.ToLowerInvariant().Contains("page") || fileName.ToLowerInvariant().Contains("matter") || fileName.ToLowerInvariant().Contains("languagedisplay") || fileName.ToLowerInvariant().Contains("origami") || fileName.ToLowerInvariant().Contains("defaultlangstyles") || fileName.ToLowerInvariant().Contains("customcollectionstyles") || // Ignore this obsolete styles file as well. See https://issues.bloomlibrary.org/youtrack/issue/BL-9128. fileName.ToLowerInvariant().EndsWith(Book.kOldCollectionStyles.ToLowerInvariant(), StringComparison.InvariantCulture)) { continue; } fileName = fileName.Replace("file://", "").Replace("%5C", "/").Replace("%20", " "); fileName = fileName.Replace("\\", "/"); var path = fileLocator.LocateFile(fileName); if (string.IsNullOrEmpty(path) && fileName.StartsWith("../")) { path = fileLocator.LocateFile(fileName.Substring(3)); } if (string.IsNullOrEmpty(path)) { // We're looking for a block of json that is typically found in Basic Book.css or a comparable place for // a book based on some other template. Calling code is prepared for not finding this block. // It seems safe to ignore a reference to some missing style sheet. if (fileName.ToLowerInvariant().Contains("branding") || fileName.ToLowerInvariant().Contains("readerstyles")) { continue; // these don't contain page size info, anyhow. } NonFatalProblem.Report(ModalIf.None, PassiveIf.Alpha, "Could not find " + fileName + " while looking for size choices"); continue; } var contents = RobustFile.ReadAllText(path); var start = contents.IndexOf("STARTLAYOUTS", StringComparison.InvariantCulture); if (start < 0) { continue; //move on to the next stylesheet } start += "STARTLAYOUTS".Length; var end = contents.IndexOf("ENDLAYOUTS", start, StringComparison.InvariantCulture); var s = contents.Substring(start, end - start); IEnumerable <Layout> layouts = null; try { layouts = Layout.GetConfigurationsFromConfigurationOptionsString(s); } catch (Exception e) { throw new ApplicationException("Problem parsing the 'layouts' comment of " + fileName + ". The contents were\r\n" + s, e); } foreach (var p in layouts) { yield return(p); } yield break; } // default set of Layouts (These used to be given in 'Basic Book.less'.) // See https://silbloom.myjetbrains.com/youtrack/issue/BL-6125. yield return(new Layout { SizeAndOrientation = FromString("A5Portrait") }); yield return(new Layout { SizeAndOrientation = FromString("A5Landscape") }); yield return(new Layout { SizeAndOrientation = FromString("A6Portrait") }); yield return(new Layout { SizeAndOrientation = FromString("A6Landscape") }); yield return(new Layout { SizeAndOrientation = FromString("A4Portrait") }); yield return(new Layout { SizeAndOrientation = FromString("A4Landscape") }); yield return(new Layout { SizeAndOrientation = FromString("A4Landscape"), Style = "SideBySide" }); yield return(new Layout { SizeAndOrientation = FromString("A4Landscape"), Style = "SplitAcrossPages" }); // does this work anywhere? yield return(new Layout { SizeAndOrientation = FromString("A3Portrait") }); yield return(new Layout { SizeAndOrientation = FromString("A3Landscape") }); yield return(new Layout { SizeAndOrientation = FromString("B5Portrait") }); yield return(new Layout { SizeAndOrientation = FromString("LetterPortrait") }); yield return(new Layout { SizeAndOrientation = FromString("LetterLandscape") }); yield return(new Layout { SizeAndOrientation = FromString("LegalPortrait") }); yield return(new Layout { SizeAndOrientation = FromString("LegalLandscape") }); yield return(new Layout { SizeAndOrientation = FromString("HalfLetterPortrait") }); yield return(new Layout { SizeAndOrientation = FromString("HalfLetterLandscape") }); yield return(new Layout { SizeAndOrientation = FromString("QuarterLetterPortrait") }); yield return(new Layout { SizeAndOrientation = FromString("QuarterLetterLandscape") }); yield return(new Layout { SizeAndOrientation = FromString("Device16x9Portrait") }); yield return(new Layout { SizeAndOrientation = FromString("Device16x9Landscape") }); yield return(new Layout { SizeAndOrientation = FromString("Cm13Landscape") }); // actually square, but acts more like landscape than portrait yield return(new Layout { SizeAndOrientation = FromString("USComicPortrait") }); }