Skip to content

Commit

Permalink
682 table theme fonts (stevencohn#712)
Browse files Browse the repository at this point in the history
* Fix if-else in AssemblyInfo
* Edit Table Themes
  • Loading branch information
stevencohn authored Nov 7, 2022
1 parent e8424a3 commit 2be3637
Show file tree
Hide file tree
Showing 25 changed files with 1,969 additions and 126 deletions.
4 changes: 2 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

## Is Your Commit Signed?
## IS YOUR COMMIT SIGNED?
Note that this repo requires all commits to be properly signed, [see here](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits) for more info

## Enhancement or Defect Solved by This PR
## Enhancement or Defect Addressed by This PR
What...

## Description of Proposed Changes
Expand Down
3 changes: 2 additions & 1 deletion OneMore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{9D56
ProjectSection(SolutionItems) = preProject
Plugins\Get-MeetingDate-readme.txt = Plugins\Get-MeetingDate-readme.txt
Plugins\Get-MeetingDate.ps1 = Plugins\Get-MeetingDate.ps1
Plugins\Set-RainbowSections.ps1 = Plugins\Set-RainbowSections.ps1
Plugins\Set-RainbowSections-readme.txt = Plugins\Set-RainbowSections-readme.txt
Plugins\Set-RainbowSections.ps1 = Plugins\Set-RainbowSections.ps1
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Templates", "Templates", "{31896922-72FF-4823-80C0-8EC46936AC71}"
Expand All @@ -53,6 +53,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{AD3F5496-C83B-4C86-B78D-EE7C6CCABB8A}"
ProjectSection(SolutionItems) = preProject
.github\FUNDING.yml = .github\FUNDING.yml
.github\pull_request_template.md = .github\pull_request_template.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{5771E974-F302-4CB6-86B8-B57C74C07709}"
Expand Down
31 changes: 15 additions & 16 deletions OneMore/Commands/Styles/ApplyStylesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace River.OneMoreAddIn.Commands
internal class ApplyStylesCommand : Command
{

private const string MediumBlue = "#5B9BD5";

private Page page;
private XNamespace ns;
private readonly Stylizer stylizer;
Expand Down Expand Up @@ -229,13 +231,10 @@ private void ApplyToLists(List<Style> styles)
s.Name.ToLower() == "body" ||
s.Name.ToLower() == "p");

if (style == null)
style ??= new Style
{
style = new Style
{
Color = page.GetPageColor(out _, out _).GetBrightness() < 0.5 ? "#FFFFFF" : "#000000"
};
}
Color = page.GetPageColor(out _, out _).GetBrightness() < 0.5 ? "#FFFFFF" : "#000000"
};

var elements = page.Root.Descendants(ns + "Bullet");
if (elements?.Any() == true)
Expand Down Expand Up @@ -284,18 +283,18 @@ private void ApplyToHyperlinks()
{
foreach (var element in elements)
{
if (element.Parent.Elements(ns + "Meta").Any(m => m.Attribute("name").Value.StartsWith("omfootnote")))
{
continue;
}

var cdata = element.GetCData();

if (cdata.Value.EndsWith("</a>"))
{
var color = (element.Parent.Elements(ns + "Meta")
.Any(m => m.Attribute("name").Value.StartsWith("omfootnote")))
? null
: MediumBlue;

// OneNote applies styles at the OE level for link-only content
// so apply color to CDATA's one:OE
ColorizeElement(element.Parent, "#5B9BD5");
ColorizeElement(element.Parent, color);
}
else
{
Expand All @@ -305,7 +304,7 @@ private void ApplyToHyperlinks()
var a = wrapper.Element("a");
if (a != null)
{
ColorizeElement(a, "#5B9BD5");
ColorizeElement(a, MediumBlue);
}

cdata.ReplaceWith(wrapper.GetInnerXml());
Expand All @@ -321,14 +320,14 @@ private static void ColorizeElement(XElement element, string color)
{
var style = new Style(attr.Value)
{
Color = color
Color = color ?? StyleBase.Automatic
};

attr.Value = style.ToCss();
}
else
else if (color != null)
{
element.Add(new XAttribute("style", "color:#5B9BD5"));
element.Add(new XAttribute("style", $"color:{MediumBlue}"));
}
}
}
Expand Down
78 changes: 76 additions & 2 deletions OneMore/Commands/Tables/ApplyTableThemeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace River.OneMoreAddIn.Commands
{
using River.OneMoreAddIn.Models;
using River.OneMoreAddIn.Styles;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
Expand All @@ -20,7 +22,6 @@ public ApplyTableThemeCommand()
public override async Task Execute(params object[] args)
{
var selectedIndex = (int)args[0];
logger.WriteLine($"apply table theme ({selectedIndex})...");

using var one = new OneNote(out var page, out var ns);
if (!page.ConfirmBodyContext())
Expand Down Expand Up @@ -50,6 +51,7 @@ public override async Task Execute(params object[] args)
TableTheme theme;
if (selectedIndex == int.MaxValue)
{
// this will clear formatting in the table
theme = new TableTheme();
}
else
Expand All @@ -69,6 +71,8 @@ public override async Task Execute(params object[] args)
FillTable(table, theme);
HighlightTable(table, theme);

ApplyFonts(table, theme);

await one.Update(page);
}

Expand Down Expand Up @@ -127,7 +131,7 @@ private void FillTable(Table table, TableTheme theme)
}
else
{
c0 = c1 = "automatic";
c0 = c1 = StyleBase.Automatic;
}

if (!string.IsNullOrEmpty(c0))
Expand Down Expand Up @@ -218,5 +222,75 @@ private void HighlightTable(Table table, TableTheme theme)
theme.TotalLastCell.ToRGBHtml();
}
}

private void ApplyFonts(Table table, TableTheme theme)
{
var minrow = theme.HeaderFont == null ? 0 : 1;
var maxrow = table.RowCount - (theme.TotalFont == null ? 0 : 1);
var mincol = theme.FirstColumnFont == null ? 0 : 1;
var maxcol = table.ColumnCount - (theme.LastColumnFont == null ? 0 : 1);

if (theme.HeaderFont != null)
{
var stylizer = MakeStylizer(theme.HeaderFont);
for (int c = mincol; c < maxcol; c++)
{
stylizer.ApplyStyle(table[0][c].Root);
}
}

if (theme.TotalFont != null)
{
var stylizer = MakeStylizer(theme.TotalFont);
for (int c = mincol; c < maxcol; c++)
{
stylizer.ApplyStyle(table[table.RowCount - 1][c].Root);
}
}

if (theme.FirstColumnFont != null)
{
var stylizer = MakeStylizer(theme.FirstColumnFont);
for (int r = minrow; r < maxrow; r++)
{
stylizer.ApplyStyle(table[r][0].Root);
}
}

if (theme.LastColumnFont != null)
{
var stylizer = MakeStylizer(theme.LastColumnFont);
for (int r = minrow; r < maxrow; r++)
{
stylizer.ApplyStyle(table[r][table.ColumnCount - 1].Root);
}
}

if (theme.DefaultFont != null)
{
var stylizer = MakeStylizer(theme.DefaultFont);
for (int r = minrow; r < maxrow; r++)
{
for (int c = mincol; c < maxcol; c++)
{
stylizer.ApplyStyle(table[r][c].Root);
}
}
}
}


private Stylizer MakeStylizer(TableTheme.ColorFont font)
{
return new Stylizer(new Style
{
FontFamily = font.Font.FontFamily.Name,
FontSize = font.Font.Size.ToString("0.#"),
IsBold = font.Font.Bold,
IsItalic = font.Font.Italic,
IsUnderline = font.Font.Underline,
Color = font.Foreground.IsEmpty ? StyleBase.Automatic : font.Foreground.ToRGBHtml()
});
}
}
}
Loading

0 comments on commit 2be3637

Please sign in to comment.