context: /* 
   * Copyright 2009 Alexander Curtis <alex@logicmill.com>
   * This file is part of GEDmill - A family history website creator
   * 
   * GEDmill is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * GEDmill is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with GEDmill.  If not, see <http://www.gnu.org/licenses/>.
   */
  
  using System;
  using System.Globalization;
  using System.IO;
  using GDModel;
  using GEDmill.Model;
  using GKCore.Logging;
  
  namespace GEDmill.HTML
  {
      /// <summary>
      /// Creates the CSS stylesheet file
      /// </summary>
      public class CreatorStylesheet : Creator
      {
          private static readonly ILogger fLogger = LogManager.GetLogger(CConfig.LOG_FILE, CConfig.LOG_LEVEL, typeof(CreatorStylesheet).Name);
  
          // Name of the CSS file we are creating
          private string fCssFilename;
  
          // Name of the background image, to use in the CSS background-image attribute.
          private string fBackgroundImageFilename;
  
  
          public CreatorStylesheet(GDMTree tree, IProgressCallback progress, string sW3cfile, string sCssFilename, string sBackgroundImageFilename) : base(tree, progress, sW3cfile)
          {
              fCssFilename = sCssFilename;
              fBackgroundImageFilename = sBackgroundImageFilename;
          }
  
          public void Create()
          {
              fLogger.WriteInfo("CCreatorStylesheet::Create()");
  
              DateTime dtNow = DateTime.Now;
              String date = dtNow.ToString("r", DateTimeFormatInfo.InvariantInfo);
  
              StreamWriter sw = null;
              FileStream fs = null;
              try {
                  if (File.Exists(fCssFilename)) {
                      // Delete any current file
                      File.SetAttributes(fCssFilename, FileAttributes.Normal);
                      File.Delete(fCssFilename);
                  }
                  fs = new FileStream(string.Concat(CConfig.Instance.OutputFolder, "\\", CConfig.Instance.StylesheetFilename, ".css"), FileMode.Create);
                  sw = new StreamWriter(fs);
  
                  sw.WriteLine(string.Concat("/* CSS file generated by ", CConfig.SoftwareName, " on ", date, " */"));
                  sw.WriteLine("BODY {");
                  sw.WriteLine("  background-color: #f1f4e9;");
                  if (fBackgroundImageFilename != "") {
                      sw.WriteLine(string.Concat("  background-image: url(", fBackgroundImageFilename, ");"));
                  }
                  sw.WriteLine("  color: #000000;");
                  sw.WriteLine("  text-align: left;");
                  sw.WriteLine("  font-family: Verdana, Arial, Helvetica, sans-serif;   ");
                  sw.WriteLine("  font-size:8pt;");
                  sw.WriteLine("}");
  
                  sw.WriteLine("IMG {");
                  sw.WriteLine("  border: none;");
                  sw.WriteLine("}");
  
                  sw.WriteLine("H1 {");
                  sw.WriteLine("  margin:10px 0 4px 0; ");
                  sw.WriteLine("  text-align: left;");
                  sw.WriteLine("  font-family: 'Times New Roman', serif; ");
                  sw.WriteLine("  font-size:26pt;");
                  sw.WriteLine("  font-weight: bold;");
                  sw.WriteLine("}");
                  sw.WriteLine("#summary {");
                  sw.WriteLine("  margin-bottom:40px;");
                  sw.WriteLine("}");
                  sw.WriteLine("#parents H1 {");
                  sw.WriteLine("  font-size:14pt;");
                  sw.WriteLine("}");
                  sw.WriteLine("#parents P {");
                  sw.WriteLine("  margin:4px 4px 4px 11px;");
                  sw.WriteLine("}");
                  sw.WriteLine("#parents {");
                  sw.WriteLine("  margin-bottom:25px;");
                  sw.WriteLine("}");
                  sw.WriteLine("#events H1 {");
                  sw.WriteLine("  font-size:14pt;");
                  sw.WriteLine("}");
                  sw.WriteLine("#facts H1 {");
                  sw.WriteLine("  font-size:14pt;");
                  sw.WriteLine("}");
                  sw.WriteLine("#notes H1 {");
                  sw.WriteLine("  font-size:14pt;");
                  sw.WriteLine("}");
                  sw.WriteLine("#citations H1 {");
                  sw.WriteLine("  font-size:14pt;");
                  sw.WriteLine("}");
                  sw.WriteLine("#citations {");
                  sw.WriteLine("  font-family:  Verdana, Arial, Helvetica, sans-serif; ");
                  sw.WriteLine("  text-align: left;");
                  sw.WriteLine("  font-size:10pt;");
                  sw.WriteLine("  margin-top: 22px;");
                  sw.WriteLine("}");
                  sw.WriteLine("#text H1 {");
                  sw.WriteLine("  font-size:14pt;");
                  sw.WriteLine("}");
                  sw.WriteLine("#references H1 {");
                  sw.WriteLine("  font-size:14pt;");
                  sw.WriteLine("}");
                  sw.WriteLine("H2 {");
                  sw.WriteLine("  margin:0 0 4px 0; ");
                  sw.WriteLine("  text-align: left;");
                  sw.WriteLine("  font-family: Verdana, Arial, Helvetica, sans-serif; ");
                  sw.WriteLine("  font-size:12pt;");
                  sw.WriteLine("  font-weight: normal;");
                  sw.WriteLine("}");
                  sw.WriteLine("H3 {");
                  sw.WriteLine("  margin:0 0 4px 0; ");
                  sw.WriteLine("  text-align: left;");
                  sw.WriteLine("  font-family: Verdana, Arial, Helvetica, sans-serif; ");
                  sw.WriteLine("  font-size:10pt;");
                  sw.WriteLine("  font-weight: normal;");
                  sw.WriteLine("}");
  
                  sw.WriteLine("P {");
                  sw.WriteLine("  margin:0; ");
                  sw.WriteLine("  text-align:left; ");
                  sw.WriteLine("  font-family: Verdana, Arial, Helvetica, sans-serif; ");
                  sw.WriteLine("  font-size:10pt;");
                  sw.WriteLine("}");
  
                  sw.WriteLine("A {");
                  sw.WriteLine("  text-decoration: none;");
                  sw.WriteLine("}");
  
                  sw.WriteLine("A:link {");
                  sw.WriteLine("  color:#1344e9;");
                  sw.WriteLine("  background-color: inherit;");
                  sw.WriteLine("}");
  
                  sw.WriteLine("A:visited {");
                  sw.WriteLine("  color:#0c2d9a;");
                  sw.WriteLine("  background-color: inherit;");
                  sw.WriteLine("}");
  
                  sw.WriteLine("A:hover {");
                  sw.WriteLine("  color:#0000ff;");
                  sw.WriteLine("  background-color: inherit;");
                  sw.WriteLine("}");
  
                  sw.WriteLine("A:active {");
                  sw.WriteLine("  color:#0c2d9a;");
                  sw.WriteLine("  background-color: inherit;");
                  sw.WriteLine("}");
  
                  sw.WriteLine("A.email {");
                  sw.WriteLine("  font-family: 'Courier New',monospace;");
                  sw.WriteLine("}");
  
                  sw.WriteLine("UL {");
                  sw.WriteLine("  padding-top: 0;");
                  sw.WriteLine("  margin-top: 0;");
                  sw.WriteLine("  border-top: 0;");
                  sw.WriteLine("  text-align: left;");
                  sw.WriteLine("  list-style-type: none;");
                  sw.WriteLine("}");
  
                  sw.WriteLine("DIV#cover H1 {");
                  sw.WriteLine("  text-align:center;");
                  sw.WriteLine("  padding-bottom:38px;");
                  sw.WriteLine("}");
  
                  sw.WriteLine("DIV#cover P {");
                  sw.WriteLine("  text-align:center;");
                  sw.WriteLine("  padding-bottom:28px;");
                  sw.WriteLine("}");
  
                  sw.WriteLine("DIV#cover DIV#links P {");
                  sw.WriteLine("  font-size:12pt;");
                  sw.WriteLine("}");
  
                  sw.WriteLine("DIV#page {");
                  sw.WriteLine("  width:800px; ");
                  sw.WriteLine("  margin:0 auto;");
                  sw.WriteLine("  position:relative;");
                  sw.WriteLine("}");
  
                  sw.WriteLine("DIV#header {");
                  sw.WriteLine("  width:800px;");
                  sw.WriteLine("  margin:0 auto;");
  
                  sw.WriteLine("}");
                  sw.WriteLine("#header ul {");
                  sw.WriteLine("  padding: 0;");
                  sw.WriteLine("  margin: 0;");
  
                  sw.WriteLine("}");
                  sw.WriteLine("#header li {");
                  sw.WriteLine("  display:inline;");
                  sw.WriteLine("  font-size:14px;");
                  sw.WriteLine("  padding:2px 4px 2px 6px;");
                  sw.WriteLine("  line-height:20px;");
                  sw.WriteLine("}");
  
                  // For multiple images we like to keep a constant margin down the rhs to accomodate them (IE). Otherwise we just let images float and text spread around them.
                  if (CConfig.Instance.AllowMultipleImages) {
                      sw.WriteLine("DIV#main {");
                      int nMainWidth = (760 - (int)CConfig.Instance.MaxImageWidth);
  
gt:                     if (nMainWidth < 0) {