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;
}
Related
I wrote code to create Presentation Document using open-xml SDK. I follow this sample code. MSDD Sample Code. Now i need to apply margin before starting my text. I've tried below code but didn't get expected result.
slidePart1.Slide = new Slide(
new CommonSlideData(
new ShapeTree(
new P.NonVisualGroupShapeProperties(
new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" },
new P.NonVisualGroupShapeDrawingProperties(),
new ApplicationNonVisualDrawingProperties()),
new GroupShapeProperties(new A.TransformGroup()),
new P.Shape(
new P.NonVisualShapeProperties(
new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "Title 1" },
new P.NonVisualShapeDrawingProperties(new D.ShapeLocks() { NoGrouping = true }),
new ApplicationNonVisualDrawingProperties(new PlaceholderShape())),
new P.ShapeProperties(),
new P.TextBody(
new D.BodyProperties(),
new D.ListStyle(),
new A.Paragraph(new D.EndParagraphRunProperties() { Language = "en-US" }, new D.ParagraphProperties() { LeftMargin = 10 }),
//new A.Paragraph(new A.Run(new A.RunProperties() { Bold = true, Italic = true, Underline = D.TextUnderlineValues.Single }, new A.Text()
//{ Text = text })))))),
new A.Paragraph(textListWithStyle.ToArray()))))),
new ColorMapOverride(new D.MasterColorMapping()));
My generated PPT File looks like:
No left margin applied but in code i applied 10 left margin.
It seems not so easy to add an indented paragraph using Open XML SDK. With Aspose.Slides for .NET, this can be done like this:
// Create a new presentation.
using var presentation = new Presentation();
// Add a text box to the first slide.
var slide = presentation.Slides[0];
var rectangle = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20, 20, 200, 150);
// Create a new paragraph.
var paragraph = new Paragraph();
paragraph.Text = "Some text.";
// Set left margin for the paragraph.
paragraph.ParagraphFormat.MarginLeft = 10;
// Add the paragraph to the text box.
rectangle.TextFrame.Paragraphs.Add(paragraph);
// Save the presentation to PPTX format.
presentation.Save("example.pptx", SaveFormat.Pptx);
This is a paid product, but you can get a temporary license to evaluate all features of this library. I work as a Support Developer at Aspose.
I have seen several questions about doing a custom tooltip for a single line series.
I need a custom tool-tip for each data-point. I would like to add more to the tool-tip than just the dependent value path and the independent value path.
Example I have 2 data points on the same line one with a value(Y-axis)
of 2, date(x-axis) of 4/28/2016, and configuration of A. The other has
a value of 3, date of 4/29/2016, and configuration of B.
How would I also show the configurations? This is all done in code behind because I have a dynamic number of lineseries. So I can't just assign a style to each lineseries in the xaml.
var MyLineSeries = new LineSeries();
lMyLineSeries.DependentValuePath = "Y";
lMyLineSeries.IndependentValuePath = "X";
lMyLineSeries.DataPointStyle = lToolTipDataPointStyle;
This is my code for creating the tool tip style.
var lToolTipDataPointStyle = new Style(typeof(LineDataPoint));
var lTemplate = new ControlTemplate(typeof(LineDataPoint));
var lGridElement = new FrameworkElementFactory(typeof(Border));
//Tooltip
var lStackPanel = new StackPanel();
var lValueContentControl = new ContentControl();
lValueContentControl.SetBinding(ContentControl.ContentProperty, new Binding(myLineSeries.DependentValuePath));
lValueContentControl.ContentStringFormat = "Value: {0}";
var lConfigurationContentControl = new ContentControl();
lConfigurationContentControl.SetBinding(ContentControl.ContentProperty, new Binding())//This is what Idk what to bind to???
lConfigurationContentControl.ContentStringFormat = "Configuration: {0}";
lStackPanel.Children.Add(lValueContentControl);
lStackPanel.Children.Add(lConfigurationContentControl);
lGridElement.SetValue(ToolTipService.ToolTipProperty, lStackPanel);
var lEllipseElement = new FrameworkElementFactory(typeof(Ellipse));
lEllipseElement.SetValue(Ellipse.StrokeThicknessProperty, new TemplateBindingExtension(Border.BorderThicknessProperty));
lEllipseElement.SetValue(Ellipse.StrokeProperty, new TemplateBindingExtension(Border.BorderBrushProperty));
lEllipseElement.SetValue(Ellipse.FillProperty, new TemplateBindingExtension(Grid.BackgroundProperty));
lGridElement.AppendChild(lEllipseElement);
lTemplate.VisualTree = lGridElement;
var lTemplateSetter = new Setter();
lTemplateSetter.Property = LineDataPoint.TemplateProperty;
lTemplateSetter.Value = lTemplate;
lToolTipDataPointStyle.Setters.Add(lTemplateSetter);
return lToolTipDataPointStyle;
I figured it out by using the Tag on the Line series.
myLineSeries.Tag = "Configuration";
var lConfigurationContentControl = new ContentControl();
lConfigurationContentControl.SetBinding(ContentControl.ContentProperty, new Binding(myLineSeries.Tag.ToString()))
lConfigurationContentControl.ContentStringFormat = "Configuration: {0}";
I'm using the DexExpress.Xpf.Map.v15.1 MapControl and trying to create code that will be able to run in a Windows Service (i.e. no front end) to generate maps as images.
I have the following code which creates a map, adds GeoPoints to a PolyLine and then adds that PolyLine to a map. This works fine in my WPF test harness application:
public MapWindow1()
{
InitializeComponent();
var mapControl = new MapControl
{
Name = "TheMap",
ZoomLevel = 4,
CenterPoint = new GeoPoint(47, 5)
};
var imageLayer = new ImageTilesLayer
{
DataProvider = new OpenStreetMapDataProvider()
};
mapControl.Layers.Add(imageLayer);
var vectorLayer = new VectorLayer();
mapControl.Layers.Add(vectorLayer);
var mapItemStorage = new MapItemStorage();
vectorLayer.Data = mapItemStorage;
var polyLineCollection = DbfGenerator.GeneratePolyLineCollection();
polyLineCollection.ForEach(line =>
{
var mapItem = new MapPolyline();
mapItemStorage.Items.Add(mapItem);
mapItem.Points.AddRange(line);
});
mapControl.MouseDoubleClick += mapControl_MouseDoubleClick;
MainGrid.Children.Add(mapControl);
}
This runs and adds the map control to the WPF page without a problem. I've then added double click handler to export the map as an image:
void mapControl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
var m = GenerateMapPng((MapControl) sender);
m.Save(#"C:\0Temp\test.bmp");
}
public Bitmap GenerateMapPng(MapControl map)
{
Bitmap bmp;
// export image from map
using (MemoryStream ms = new MemoryStream())
{
var exportOptions = new ImageExportOptions(ImageFormat.Png);
map.ExportToImage(ms, exportOptions);
ms.Position = 0;
bmp = new Bitmap(System.Drawing.Image.FromStream(ms));
}
return bmp;
}
Again - this works without a problem.
However, If I remove the UI element and run the following code:
public MapWindow1()
{
InitializeComponent();
var mapControl = new MapControl
{
Name = "TheMap",
ZoomLevel = 4,
CenterPoint = new GeoPoint(47, 5)
};
var imageLayer = new ImageTilesLayer
{
DataProvider = new OpenStreetMapDataProvider()
};
mapControl.Layers.Add(imageLayer);
var vectorLayer = new VectorLayer();
mapControl.Layers.Add(vectorLayer);
var mapItemStorage = new MapItemStorage();
vectorLayer.Data = mapItemStorage;
var polyLineCollection = DbfGenerator.GeneratePolyLineCollection();
polyLineCollection.ForEach(line =>
{
var mapItem = new MapPolyline();
mapItemStorage.Items.Add(mapItem);
mapItem.Points.AddRange(line);
});
var m = GenerateMapPng(mapControl);
m.Save(#"C:\0Temp\test.bmp");
}
I get a NullReferenceException on the "map.ExportToImage(ms, exportOptions);" line.
I'm assuming that when the WPF application loads it calls a method to initialise the map, but I can't find anything that I can manually do to the control (Load/Init method) to mimic this.
Is there a way to trick the MapControl in to thinking it is in a WPF page when it isn't?
DevExpress said that this was not possible due to the maps reliance on the UI Thread in WPF
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 ();
}
I'm using a CATextLayer to render an NSAttributedString. When done in this method the color does not render correctly. When done using CTStringAttributes the color works, but the NSAttributedString does not know its own size. This is the code I'm using:
var caTextLayer = new CATextLayer ();
var attributedString = new NSAttributedString
(
"test string",
ForegroundColor = UIColor.Blue.CGColor,
Font = new CTFont ("Arial", 24),
KerningAdjustment = 72f
);
caTextLayer.AttributedString = attributedString;
caTextLayer.Frame = UIScreen.MainScreen.Bounds;
caTextLayer.ContentsScale = UIScreen.MainScreen.Scale;
myViewController.View.Layer.InsertSublayer(layer3, 1);
caTextLayer.SetNeedsDisplay ();
You need to use CTStringAttributes if you are using CoreText layers