How to set the width of Underline in attributed text - ios6

I am using UITextView and adding attributed text to it. I want to set underline to the text according to the font size, but i was only able to set the size 1. If any one have any idea regarding this please tell.
The code i am using is:-
NSDictionary* dict = nil;
dict = #{NSForegroundColorAttributeName:[UIColor blackColor],
NSBackgroundColorAttributeName: [UIColor clearColor],
NSUnderlineStyleAttributeName: #1
};
TextView.attributedText = [[NSAttributedString alloc]initWithString:#"String to be underline" attributes:dict];

Related

How to Create Emboss and engrave text on OpenCASCADE

I am searching an API for creating emboss text on my AIS_Shape , If there is no API any better way to do that ?,I am thinking of creating text extrude and doing cut operation with AIS_Shape , can we extrude Text ?
OCCT doesn't provide direct tool defining an emboss text - so you are right, you have to do that using a general Boolean operation.
A general idea can be found within standard samples coming with Draw Harness - take a look onto "Modeling" -> "OCCT Tutorial bottle sample" sample (source $env(CSF_OCCTSamplesPath)/tcl/bottle.tcl):
Tools to use:
Font_BRepFont to load a font and convert a glyph into a planar TopoDS_Shape.
Font_BRepTextBuilder to format a text using Font_BRepFont.
BRepPrimAPI_MakePrism to define a solid from text.
BRepAlgoAPI_Cut to perform a Boolean operation between text solid and another shape.
Here is a pseudo-code:
// text2brep
const double aFontHeight = 20.0;
Font_BRepFont aFont (Font_NOF_SANS_SERIF, Font_FontAspect_Bold, aFontHeight);
Font_BRepTextBuilder aBuilder;
TopoDS_Shape aTextShape2d = aBuilder.Perform (aFont, "OpenCASCADE");
// prism
const double anExtrusion = 5.0;
BRepPrimAPI_MakePrism aPrismTool (aTextShape2d, gp_Vec (0,0,1) * anExtrusion);
TopoDS_Shape aTextShape3d = aPrismTool->Shape();
//aTextShape3d.SetLocation(); // move where needed
// bopcut
TopoDS_Shape theMainShape; // defined elsewhere
BRepAlgoAPI_Cut aCutTool (theMainShape, aTextShape3d);
if (!aCutTool.IsDone()) { error }
TopoDS_Shape aResult = aCutTool.Shape();

How to read Word Paragraph Line by Line in C#?

I am trying to read word content line by line. But I am facing an issue. When trying to read paragraph. If paragraph content is multi line. I am getting single line internally. Can any one please help me on this.
Expected Output:
Line 1 - > TERM BHFKGBHFGFKJHGKJSHFKG ABC1 IOUTOYTIUYRUYTIREYTU B08
Line 2 - > NBHFBHDFGJDSBHKHDGFJGJGDJK 3993 JBHKJSFGSDKFJDGFJKDSBF3993
Line 3 - > JHBJKFHKJGDGFSFGB08 HGHGGFGFDGJFFFDSGFABC1 JJBVHGHDFTERM
Line 4 - > TERMBHFKGBHFGFKJHGKJSHFKG ABC1IOUTOYTIUYRUYTIREYTU B08NBHFBHDFGJDSBHKHDGFJGJGDJK
Line 5 - > 39931234567890987654321
Actual Output:
Single Line -> TERM BHFKGBHFGFKJHGKJSHFKG ABC1 IOUTOYTIUYRUYTIREYTU B08 NBHFBHDFGJDSBHKHDGFJGJGDJK 3993 JBHKJSFGSDKFJDGFJKDSBF3993 JHBJKFHKJGDGFSFGB08 HGHGGFGFDGJFFFDSGFABC1 JJBVHGHDFTERM
TERMBHFKGBHFGFKJHGKJSHFKG ABC1IOUTOYTIUYRUYTIREYTU B08NBHFBHDFGJDSBHKHDGFJGJGDJK
39931234567890987654321
Below is my code sample:
OpenXml:
using (WordprocessingDocument doc = WordprocessingDocument.Open(fs, false))
{
var bodyText = doc.MainDocumentPart.Document.Body;
if (bodyText.ChildElements.Count > 0)
{
foreach (var items in bodyText)
{
if (items is Paragraph)
{
var par = items.InnerText;
}
}
}
}
Office.Interop
object nullobj = System.Reflection.Missing.Value;
Word.Application app = new Word.Application();
Word.Document doc = app.Documents.Open(FilePath, ref nullobj, FileAccess.Read,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj);
foreach (Word.Paragraph paragraph in doc.Paragraphs)
{
var line = paragraph.Range.Text;
}
It is not possible to determine individual lines in the closed file. Lines are dynamically generated when a document is opened in Word and where a line "breaks" depends on many factors - it's not necessarily the same from system profile to system profile. So it's necessary to use the interop, not Open XML to pick up where lines break on the screen.
What's more, the Word object model does not provide "Line" objects for this very reason - there is no "line", only a visual representation of how the page will print, given the current printer driver and version of Windows.
The only part of the Word object model that recognizes "lines" is Selection, as this works solely with what's displayed on the screen.
The following code demonstrates how this can be done.
First, since Selection is being worked with and this is visible on-screen, ScreenUpdating is disabled in order to reduce screen flicker and speed up processing. (Note that working with selections is generally much slower than other object model processing.)
Using ComputeStatistics the number of lines in a paragraph is determined. An array (you can also use a list or anything else) to contain the lines is instantiated. The paragraph range is "collapsed" to its starting point and visually selected.
Now the lines in the paragraph are looped, based on the number of lines. The selection is extended (MoveEnd method) by one line (again, moving by lines is only available to a selection) and the selected text written to the array (or whatever).
Finally, screen updating is turned back on.
wdApp.ScreenUpdating = false;
foreach (Word.Paragraph para in doc.Paragraphs)
{
Word.Range rng = para.Range;
int lNumLines = rng.ComputeStatistics(Word.WdStatistic.wdStatisticLines);
string[] aLines = new String[lNumLines];
rng.Collapse(Word.WdCollapseDirection.wdCollapseStart);
rng.Select();
for (int i = 0; i < lNumLines; i++)
{
wdApp.Selection.MoveEnd(Unit: Word.WdUnits.wdLine, Count: 1);
aLines[i] = wdApp.Selection.Text;
wdApp.Selection.Collapse(Word.WdCollapseDirection.wdCollapseEnd);
}
for (int i = 0; i < aLines.Length; i++)
{
Debug.Print(aLines[i]);
}
}
wdApp.ScreenUpdating = true;
In Word, a paragraph is a sinle line of text. Change the size of the print area (e.g. change the margins and/or page size) or the font/point size and the text reflows accordingly. Moerover, since Word uses the active printer driver to optimise the page layout, what exists on a given line in one computer may not exist on the same line on another computer.
Depending on your requirements, though, you could employ Word's predefined '\Line' bookmark to navigate between lines or the Rectangle.Lines property.

How to display text on GTK label using two different fonts?

I have a GTK label and I am displaying text on it in Arial Rounded Mt Bold by using following code:
PangoFontDescription *df;
df = pango_font_description_new ();
pango_font_description_set_family(df,"Arial Rounded Mt Bold");
pango_font_description_set_size(df,fontsize*PANGO_SCALE);
gtk_widget_modify_font(Message_Label, df);
gtk_label_set_text(GTK_LABEL(Label), "Hello World");
pango_font_description_free (df);
Now this Hello World is displayed in Arial Rounded Mt Bold. But what if I want to display Hello in Arial Rounded Mt Bold and World in some other font for example Arial. Is this possible in GTK label. I am doing it in C. Any advice or any useful links. Thanks.
gtk_widget_modify_font() is deprecated and won't let you do what you want.
You can use a PangoAttrList, which combines attributes (including the individual components of a PangoFontDescriptor) over ranges of text. For instance:
PangoAttrList *attrlist;
PangoAttribute *attr;
PangoFontDescription *df;
attrlist = pango_attr_list_new();
// First, let's set up the base attributes.
// This part is copied from your code (and slightly bugfixed and reformatted):
df = pango_font_description_new();
pango_font_description_set_family(df, "Arial Rounded MT");
pango_font_description_set_size(df, fontsize * PANGO_SCALE);
pango_font_description_set_weight(df, PANGO_WEIGHT_BOLD);
// You can also use pango_font_description_new_from_string() and pass in a string like "Arial Rounded MT Bold (whatever fontsize is)".
// But here's where things change:
attr = pango_attr_font_desc_new(df);
// This is not documented, but pango_attr_font_desc_new() makes a copy of df, so let's release ours:
pango_font_description_free(df);
// Pango and GTK+ use UTF-8, so our string is indexed between 0 and 11.
// Note that the end_index is exclusive!
attr->start_index = 0;
attr->end_index = 11;
pango_attr_list_insert(attrlist, attr);
// And pango_attr_list_insert() takes ownership of attr, so we don't free it ourselves.
// As an alternative to all that, you can have each component of the PangoFontDescriptor be its own attribute; see the PangoAttribute documentation page.
// And now the attribute for the word "World".
attr = pango_attr_family_new("Arial");
// "World" starts at 6 and ends at 11.
attr->start_index = 6;
attr->end_index = 11;
pango_attr_list_insert(attrlist, attr);
// And finally, give the GtkLabel our attribute list.
gtk_label_set_attributes(GTK_LABEL(Label), attrlist);
// And (IIRC this is not documented either) gtk_label_set_attributes() takes a reference on the attribute list, so we can remove ours.
pango_attr_list_unref(attrlist);
You can also use gtk_label_set_markup() to use an HTML-like markup language to set both text and styles in one go:
gtk_label_set_markup(GTK_LABEL(Label),
"<span face=\"Arial Rounded MT\" size=\"(whatever fontsize * PANGO_SCALE is)\" weight=\"bold\">Hello <span face=\"Arial\">World</span></span>");
// Or even...
gtk_label_set_markup(GTK_LABEL(Label),
"<span font=\"Arial Rounded MT Bold (whatever fontsize is)\">Hello <span face=\"Arial\">World</span></span>");

How to change DefaultFontSize for a gembox spreadsheet?

Can anyone give me an example on how to change the font size for a sheet using Gembox software? I was able to change for a cell though but I want to change in entire sheet.
GemBoxHelp
UPDATE 2020-03-27
In latest versions of GemBox.Spreadsheet there are some additional API that simplify this task.
For instance, to set a default font size for the whole Excel file, you can use the following:
var file = ExcelFile.Load("In.xlsx");
file.Styles.Normal.Font.Size = 18 * 20;
file.Save("Out.xlsx");
Or if you want to explicitly specify the font size on each cell in the sheet, you can use the following:
var file = ExcelFile.Load("In.xlsx");
var sheet = file.Worksheets[0];
sheet.Cells.Style.Font.Size = 18 * 20;
file.Save("Out.xlsx");
ORIGINAL
If you have cells that do not have any font related settings (like color, name, size, etc.) applied to them directly then you can just change the cell style's font size, for example:
var file = ExcelFile.Load("In.xlsx");
int size = (int)LengthUnitConverter.Convert(18, LengthUnit.Point, LengthUnit.Twip);
file.Styles[BuiltInCellStyleName.Normal].Font.Size = size;
file.Save("Out.xlsx");
But in a case you do have some directly applied font settings then you will need to iterate through all the allocated cells and apply new size on them:
var file = ExcelFile.Load("In.xlsx");
var sheet = file.Worksheets.ActiveWorksheet;
int size = (int)LengthUnitConverter.Convert(18, LengthUnit.Point, LengthUnit.Twip);
foreach (var row in sheet.Rows)
foreach (var cell in row.AllocatedCells)
cell.Style.Font.Size = size;
file.Save("Out.xlsx");
The above refers to the current latest version 3.7, but in the next version 3.9, which we are currently working on, this task is simplified like the following:
sheet.Cells.Style.Font.Size = size;

MKMapView setRegion not exact

Starting Situation
iOS6, Apple Maps. I have two annotations on a MKMapView. The coordinates of the two annotations have the same values for the latitude component, but different longitudes.
What I want
I now want to zoom the map so that one annotation is exactly on the left edge of the mapView's frame, and the other annotation on the right edge of the frame. For that I tried MKMapView's setRegion and setVisibleMapRect methods.
The Problem
The problem is that those methods seem to snap to certain zoom levels and therefore not setting the region as exactly as I need it. I saw a lot of questions on Stack Overflow that point out, that this behavior is normal in iOS5 and below. But since Apple Maps are using vector graphics, the view is not bound to certain zoom levels to display imagery in proper resolution.
Tested in...
I tested on iPhone 4, 4S, 5, iPad 3 and iPad Mini (all with iOS6.1), and in the Simulator on iOS6.1.
My question
So why is setRegion and setVisibleMapRect snapping to certain zoom levels and does not adjust the exact region to the values I pass it?
Sample Code
in view did appear I define 4 different Locations as iVars, and set up the map view:
// define coords
_coord1 = CLLocationCoordinate2DMake(46.0, 13.0);
_coord2 = CLLocationCoordinate2DMake(46.0, 13.1);
_coord3 = CLLocationCoordinate2DMake(46.0, 13.2);
_coord4 = CLLocationCoordinate2DMake(46.0, 13.3);
// define frame for map in landscape mode
CGRect mainScreen = [[UIScreen mainScreen] bounds];
CGRect newSRect = mainScreen;
newSRect.size.width = mainScreen.size.height;
newSRect.size.height = mainScreen.size.width;
// setup map view
customMapView = [[MKMapView alloc] initWithFrame:newSRect];
[customMapView setDelegate:self];
[customMapView setShowsUserLocation:NO];
[self.view addSubview:customMapView];
Then I add 3 buttons. Those trigger all the same method addAnnotationsWithCoord1:coord2. The first button passes _coord1 and _coord2, the second button passes _coord1 and _coord3 and the third button passes _coord1 and _coord4. The method looks like so (TapAnnotation is my subclass of MKAnnotation):
-(void)addAnnotationsWithCoord1:(CLLocationCoordinate2D)coord1 coord2:(CLLocationCoordinate2D)coord2{
// Make 2 new annotations with the passed coordinates
TapAnnotation *annot1 = [[TapAnnotation alloc] initWithNumber:0 coordinate:coord1];
TapAnnotation *annot2 = [[TapAnnotation alloc] initWithNumber:0 coordinate:coord2];
// Remove all existing annotations
for(id<MKAnnotation> annotation in customMapView.annotations){
[customMapView removeAnnotation:annotation];
}
// Add annotations to map
[customMapView addAnnotation:annot1];
[customMapView addAnnotation:annot2];
}
After that I determine the SouthWest and NorthEast points that will determine the rect which is containing my 2 annotations.
// get northEast and southWest
CLLocationCoordinate2D northEast;
CLLocationCoordinate2D southWest;
northEast.latitude = MAX(coord1.latitude, coord2.latitude);
northEast.longitude = MAX(coord1.longitude, coord2.longitude);
southWest.latitude = MIN(coord1.latitude, coord2.latitude);
southWest.longitude = MIN(coord1.longitude, coord2.longitude);
Then I calculate the center point between the two coordinates and set the center coordinate of the map to it (remember, since all coordinates have same latitudes the following calculation should be correct):
// determine center coordinate and set to map
double centerLon = ((coord1.longitude + coord2.longitude) / 2.0f);
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(southWest.latitude, centerLon);
[customMapView setCenterCoordinate:center animated:NO];
Now I try to set the region of the map so that it fits like I want:
CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:southWest.latitude longitude:southWest.longitude];
CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:northEast.latitude longitude:northEast.longitude];
CLLocationDistance meterSpanLong = [loc1 distanceFromLocation:loc2];
CLLocationDistance meterSpanLat = 0.1;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(center, meterSpanLat, meterSpanLong);
[customMapView setRegion:region animated:NO];
This does not behave as expected, so I try this:
MKCoordinateSpan span = MKCoordinateSpanMake(0.01, northEast.longitude-southWest.longitude);
MKCoordinateRegion region = MKCoordinateRegionMake(center, span);
[customMapView setRegion:region animated:NO];
This still not behaves as expected, so I try it with setVisibleMapRect:
MKMapPoint westPoint = MKMapPointForCoordinate(southWest);
MKMapPoint eastPoint = MKMapPointForCoordinate(northEast);
MKMapRect mapRect = MKMapRectMake(westPoint.x, westPoint.y,eastPoint.x-westPoint.x,1);
[customMapView setVisibleMapRect:mapRect animated:NO];
And still, it does not behave like I want. As a verification, I calculate the point distance from the left annotation to the left edge of the mapView's frame:
// log the distance from the soutwest point to the left edge of the mapFrame
CGPoint tappedWestPoint = [customMapView convertCoordinate:southWest toPointToView:customMapView];
NSLog(#"distance: %f", tappedWestPoint.x);
For _coord1 and _coord2 it shows: 138
For _coord1 and _coord3 it shows: 138
For _coord1 and _coord4 it shows: 65
So why do I get these values? If anything works as expected, these should all be 0.
Thanks for any help, struggling with this problem for a week now.
Read the docs on setRegion:
When setting this property, the map may adjust the new region value so that it fits the visible area of the map precisely. This is normal and is done to ensure that the value in this property always reflects the visible portion of the map. However, it does mean that if you get the value of this property right after setting it, the returned value may not match the value you set. (You can use the regionThatFits: method to determine the region that will actually be set by the map.)
You will have to figure out the math yourself if you want a precise zoom.

Resources