Showing Font Selection Dialog in GTK# - c#

In MY gtk# Application im trying to show the font selection dialog.Im trying to use the following code,but the FontSelectionDialog constructor need some arguments also does the control execution wait for a font to be selected to set the string font
Can someone guide me?
Gtk.FontSelectionDialog fs = new FontSelectionDialog()
fs.Show ();
font=fs.FontName;

Updated according to additional question
This should help:
FontSelectionDialog dialog = null;
try {
dialog = new FontSelectionDialog("Choose a font");
dialog.Run ();
var name = dialog.FontName;
var pattern = #"^(?<fontName>.*)\s(?<fontSize>\d+(?:\.\d+)?)$";
var regex = new Regex(pattern);
var match = regex.Match(name);
if(match.Success)
{
var fontName = match.Groups["fontName"].Value;
var fontSize = float.Parse(match.Groups["fontSize"].Value);
var font = new System.Drawing.Font(fontName, fontSize);
}
} finally {
if (dialog != null)
dialog.Destroy ();
}

Related

uwp InkCanvas save stokes as svg

I am trying to save InkCanvas , InkStorkes as a SVG. I found a previous question that works for Wpf,but I have been unable to get it to work with uwp. Wpf InkCanvas save stokes as svg
. I made some changes to it, but I am running into issues with GetGrometry and XamlWriter.
var svg = new SvgDocument();
var colorServer = new SvgColourServer(System.Drawing.Color.Black);
var group = new SvgGroup { Fill = colorServer, Stroke = colorServer };
svg.Children.Add(group);
foreach (var stroke in inkCanvas.InkPresenter.StrokeContainer.GetStrokes())
{
var geometry = stroke.GetGeometry(stroke.DrawingAttributes).GetOutlinedPath‌​Geometry();
var s = XamlWriter.Save(geometry);
if (s.IsNotNullOrEmpty())
{
var element = XElement.Parse(s);
var data = element.Attribute("Figures")?.Value;
if (data.IsNotNullOrEmpty())
{
group.Children.Add(new SvgPath
{
PathData = SvgPathBuilder.Parse(data),
Fill = colorServer,
Stroke = colorServer
});
}
}
}
I implemented an approach from the comments Xavier Xie - MSFT.
The main idea was to use own implementation of ICanvasPathReceiver interface - here is CanvasGeometryToSvgPathReader class:
var svgDocument = new CanvasSvgDocument(canvasDevice);
foreach (var stroke in InkCanvas.InkPresenter.StrokeContainer.GetStrokes())
{
var canvasGeometry = CanvasGeometry.CreateInk(drawingSession, new[] {stroke});
var pathReceiver = new CanvasGeometryToSvgPathReader();
canvasGeometry.SendPathTo(pathReceiver);
var element = svgDocument.Root.CreateAndAppendNamedChildElement("path");
element.SetStringAttribute("d", pathReceiver.Path);
element.SetColorAttribute("fill", stroke.DrawingAttributes.Color);
}
As result ballpoint pen renders fine, highlighter worse and pencil doesn't render.
Full source code: https://github.com/ycherkes/InkToSvg

Apply style on Content Control in a Word Document using OpenXML

I'm trying to generate Word documents using OpenXML SDK and Word Document Generator. I need to apply my custom style on ContentControls (Repeating Section).
For Recursive Placeholders, I use
foreach (var item in list)
{
var datacontext = new OpenXmlElementDataContext()
{
Element = openXmlElementDataContext.Element,
DataContext = item.Value
};
var clonedElement = CloneElementAndSetContentInPlaceholders(datacontext);
SetContentOfContentControl(clonedElement, item.Value);
}
openXmlElementDataContext.Element.Remove();
I need to apply my style on this element. How to I can do ?
I try to see generated code with "Open XML SDK 2.5 Productivity Tool for Microsoft Office" to inspire me:
var moduleDatacontext = new OpenXmlElementDataContext()
{
Element = openXmlElementDataContext.Element,
DataContext = module.Valeur
};
var moduleClonedElement = CloneElementAndSetContentInPlaceholders(moduleDatacontext);
var sdtProperties1 = new SdtProperties();
var styleId1 = new StyleId() { Val = "FormationTitre2" };
ParagraphMarkRunProperties paragraphMarkRunProperties1 = new ParagraphMarkRunProperties();
RunFonts runFonts1 = new RunFonts() { ComplexScriptTheme = ThemeFontValues.MinorHighAnsi };
paragraphMarkRunProperties1.Append(runFonts1);
sdtProperties1.Append(styleId1);
sdtProperties1.Append(paragraphMarkRunProperties1);
Run run1 = new Run() { RsidRunProperties = "00C463E5" };
RunProperties runProperties1 = new RunProperties();
RunFonts runFonts2 = new RunFonts() { ComplexScriptTheme = ThemeFontValues.MinorHighAnsi };
runProperties1.Append(runFonts2);
run1.Append(runProperties1);
moduleClonedElement.Append(sdtProperties1);
moduleClonedElement.Append(run1);
When I open the generated document, I have this error :
We're sorry. We can't open "...docx" because we found a problem with its contents.
I validate the document and I can see 15 errors:
Full Size
I've found the solution. I search first paragraph and apply my custom style on it.
// clone element
var clonedElement = CloneElementAndSetContentInPlaceholders(datacontext);
// search the first created paragraph on my clonedElement
Paragraph p = clonedElement.Descendants<Paragraph>().FirstOrDefault();
if (p != null)
p.PrependChild<ParagraphProperties>(new ParagraphProperties());
// get the paragraph properties
ParagraphProperties pPr = p.Elements<ParagraphProperties>().First();
// apply style
pPr.ParagraphStyleId = new ParagraphStyleId { Val = "FormationTitre2" };
// set content of content control
SetContentOfContentControl(clonedElement, item.Value);

RadDock's SplitContainer does not fill the Windows

I have the following code to create RadDock programmatically:
public void CreateDock(Control parent)
{
RadDock dock = new RadDock();
DocumentContainer docContainerLeft = new DocumentContainer();
docContainerLeft.SizeInfo.SizeMode = Telerik.WinControls.UI.Docking.SplitPanelSizeMode.Fill;
DocumentTabStrip leftDocStrip = new DocumentTabStrip();
DocumentWindow leftDoc = new DocumentWindow("Left");
leftDocStrip.Controls.Add(leftDoc);
docContainerLeft.Controls.Add(leftDocStrip);
DocumentContainer docContainerRight = new DocumentContainer();
docContainerRight.SizeInfo.SizeMode = Telerik.WinControls.UI.Docking.SplitPanelSizeMode.Fill;
DocumentTabStrip rightDocStrip = new DocumentTabStrip();
DocumentWindow rightDoc = new DocumentWindow("Right");
rightDocStrip.Controls.Add(rightDoc);
docContainerRight.Controls.Add(rightDocStrip);
RadSplitContainer middleSplitter = new RadSplitContainer(Orientation.Vertical);
middleSplitter.Dock = DockStyle.Fill;
middleSplitter.SizeInfo.SizeMode = SplitPanelSizeMode.Fill;
middleSplitter.Controls.Add(docContainerLeft);
middleSplitter.Controls.Add(docContainerRight);
dock.Controls.Add(middleSplitter);
ToolWindow transferWindow = new ToolWindow();
transferWindow.Text = "Transfer Queue";
transferWindow.DockState = DockState.Docked;
dock.DockWindow(transferWindow, DockPosition.Bottom);
dock.Dock = DockStyle.Fill;
parent.Controls.Add(dock);
}
I'm trying to make the middleSplitter to fit the window. However there is always an unwanted area at the bottom. I have a picture of it here but SO does not allow me to post an image.
My question is: How to avoid the unwanted area and make the Splitter fill the window?
The DockWindow method of RadDock might be of help in this case. Here is how you can achieve the desired look:
DocumentWindow middleDoc = new DocumentWindow("Middle");
dock.AddDocument(middleDoc);
DocumentWindow leftDoc = new DocumentWindow("Left");
dock.DockWindow(leftDoc, middleDoc, DockPosition.Top);
DocumentWindow rightDoc = new DocumentWindow("Right");
dock.DockWindow(rightDoc, leftDoc, DockPosition.Right);
ToolWindow transferWindow = new ToolWindow();
transferWindow.Text = "Transfer Queue";
transferWindow.DockState = DockState.Docked;
dock.DockWindow(transferWindow, DockPosition.Bottom);
More information and examples are available in the Telerik UI for WinForms documentation

Font rendering with custom font widths using Xamarin.iOS

I'm using Xamarin.iOS and need to render text strings that have a custom amount of spacing between each gylph. I am currently building a NSMutableAttributedString in which I am passing my font and paragraphstyple information. I been able to display the text string but I need to be able to set a custom amount of spacing between each gylph. Is there a dictionary element that I can add to allow me to configure this value in iOS? Below is the method I am using to build the attributedstring.
public NSMutableAttributedString Build()
{
// Create a new attributed string from text
var atts = new NSMutableAttributedString(String);
var attRange = new NSRange(0, atts.Length);
var attsDic = new NSMutableDictionary();
var fontObject = new NSObject(Font.Handle);
attsDic.Add((NSString)"NSFont", fontObject);
var alignmentSettings = new CTParagraphStyleSettings()
{
Alignment = CTTextAlignment.Left,
};
var paragraphStyle = new CTParagraphStyle(alignmentSettings);
var psObject = new NSObject(paragraphStyle.Handle);
attsDic.Add((NSString)"NSParagraphStyle", psObject);
atts.SetAttributes(attsDic, attRange);
return atts;
}

print preview and print in wpf

I have a WPF Form ,I need to print it ,i use DocumentViewer to print. but when I want to Print it or Preview , I only See the first page while i have more than one page
private void Print(object sender, RoutedEventArgs e)
{
PrintSettings printSettings = PrintSettings.Default;
UIElement container = this.Content as UIElement;
ScrollViewer containerPanel = Helper.FindVisualChildren<ScrollViewer>(container).FirstOrDefault();
var origParentDirection = containerPanel.FlowDirection;
var origDirection = (containerPanel.Content as FrameworkElement).FlowDirection;
if (containerPanel != null && containerPanel.FlowDirection == FlowDirection.RightToLeft)
{
containerPanel.FlowDirection = FlowDirection.LeftToRight;
(containerPanel.Content as FrameworkElement).FlowDirection = FlowDirection.RightToLeft;
}
var window = new Window();
string tempFileName = System.IO.Path.GetTempFileName();
System.IO.File.Delete(tempFileName);
using (XpsDocument xpsDocument = new XpsDocument(tempFileName, FileAccess.ReadWrite, System.IO.Packaging.CompressionOption.Fast))
{
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
(containerPanel.Content as FrameworkElement).Margin = new Thickness(20);
writer.Write((containerPanel.Content as FrameworkElement), printSettings.PrintTicket);
var doc = xpsDocument.GetFixedDocumentSequence();
doc.PrintTicket = printSettings.PrintTicket;
window.FlowDirection = System.Windows.FlowDirection.RightToLeft;
window.Content = new DocumentViewer { Document = doc };
window.Margin = new Thickness(10);
window.ShowDialog();
}
(containerPanel.Content as FrameworkElement).FlowDirection = origDirection;
containerPanel.FlowDirection = origParentDirection;
}
user1780436, I am currently looking for a similar answer. You are trying to print a panel, correct?
I am finding that scaling the element is the biggest problem. Which brings another issue with scaling what you want to print and not the actual visible element. You will have to copy the element to a new element.
public class Copy<T>
{
public static T DeepCopy<T>(T element)
{
string xaml = XamlWriter.Save(element);
StringReader xamlString = new StringReader(xaml);
XmlTextReader xmlTextReader = new XmlTextReader(xamlString);
var DeepCopyobject = (T)XamlReader.Load(xmlTextReader);
return DeepCopyobject;
}
}
or
myNewElement = XamlReader.Parse(XamlWriter.Save(myOldElement.DataContext)) as ElementType
I have found this answer repeatedly on multiple sites to copy/clone an element, but I have had issues with string xaml = XamlWriter.Save(element); causing stackoverflows.
I am currently using.
myNewElement = new ElementType() { DataContext = myOldElement.DataContext }
Either one you use there becomes the issue of changing the size of the Element. This is what I am looking for.
I tried a rendering pass, but that just pointed out that in my situation to use a copied/cloned element. Although while writing this I did get some of it to work, but gives me a black image, note I am trying to scale a Chart.
myNewElement.Width = newWidth;
myNewElement.Height = newHeight;
myNewElement.Measure(new System.Windows.Size(newWidth, newHeight));
myNewElement.Arrange(new Rect(0, 0, newWidth, newHeight));
I tried a layout pass, and didn't get it.
I am going to keep working on mine and I will post anything new I find. Please do the same if you find the answer.
Edit - Here is what I did. My problem and solution

Categories

Resources