We are making statistical software. Everywhere we need to put formula such as ax2+bx+c How to make ax2 means x square 2. I want to display 2 on upper side of x. Same with πc I want to display c at suffix.
Do you have a fixed list of formulas that users can choose but cannot edit? Then generate an image for each formula, store them in your application, and display them in a PictureBox.
If you expect users to be able to type in arbitrary formulas and render them interactively, you will have to implement a visual formula editor control. These controls take markup such as MathML or TeX and render them as graphics. Several are described in the link I provided, but I do not know of any such .Net controls for WinForms.
for the "upper" 2 and 3 there are symbols: a², a³ (even on a german keyboard but you will find them in your symboltable in windows too) - the lower c will be harder - I would consider using pictures for those more complex formulas (if you need dynamic formulas it you might have to create them with Graphics in code)
Related
I have a dozen of code editors written in Left-to-Right layout (for LTR languages).
I'm thinking if I could change C# coordinate system so that x = 0 being at the right rather than left, then I would not change any code written to render LTR.
Is this possible in .NET? Thanks
I'm probably missing something obvious but I don't see how changing a coordinate axis is going to help you in this case.
If you are not after proper support for RTL languages then realigning all text controls to have the text Right Aligned would be sufficient.
But editable controls where user input is expected would also need to output the text in reverse order. The caret would need to move along the X axis toward the -ve side. To support this you would probably need to do some code changes in the controls internals.
Personally, I've never seen a RTL controls that would simply flip an axis to switch from LTR mode.
My two cents.
I'm writing a WinForms .NET program that needs to lay some text out on a page (with a few basic geometric/vector graphics). Is there an equivalent of OS X's Core Graphics and/or Core Text? So far, I am just using a PrintDocument and using the Graphics object provided by the PrintPageEventArgs to draw text on the page, but there's very little control over things such as interword spacing, interline spacing etc. and a lot of stuff has to be done manually.
I feel like I'm missing something; is there a better way for typesetting text on a page? I don't mind using 3rd party solutions as long as they are free for personal use.
This will be used for typesetting a small variety of documents, including one-page brochures/fliers (where most text is variable but images are static), award certificates (where most text and images are static but some text is variable), timetables, etc.
WinForms
When you use WinForms it is close to impossible to do proper type setting and yes, almost everything must be done manually. There are a couple of reasons for this:
You don't get detailed glyph information
The text measurement is horrible inaccurate, both the GDI+ and the GDI based version.
Windows Presentation Foundation
If you use WPF this is an entirely different matter as you get detailed geometrical information about each glyph.
However, you can interleave the two, a bit messy, but possible. Although, I do not recommend it as the graphics and bitmaps are not directly interchangeable which can result in slow performance.
If you want to look at the possibility you need to import the System.Windows.Media into your project to access the typeface and glyph capability of WPF.
You will meet a couple of other challenges as well:
The font lists between WinForm and WPF are not identical (more font and font types with WPF).
You cannot just use a WPF glyph and draw it to a WinForm bitmap.
The values from the glyph are, as expected, in em so they need to be converted to pixels based on point size.
However, you can get this (not limited to) information:
All details (too many to list here):
http://msdn.microsoft.com/en-us/library/system.windows.media.glyphtypeface.aspx
Conclusion
But if you stick with GDI+ and WinForms the best approach you can take is probably to use the GDI based TextMetrics class.
You will in any case experience possibly padding issues, you cannot set char spacing and so forth.
You will have to calculate baseline for each typeface and size by using top + ascent:
FontFamily ff = myFont.FontFamily;
float lineSpace = ff.GetLineSpacing(myFont.Style);
float ascent = ff.GetCellAscent(myFont.Style);
float baseline = myFont.GetHeight(ev.Graphics) * ascent / lineSpace;
PointF renderPt = new PointF(pt.X, pt.Y - baseline));
ev.Graphics.DrawString("My baselined text", myFont, textBrush, renderPt);
I do not know of any third-party library that can do this within the WinForm environment, I believe for the reasons mentioned here and the pain it would cause.
In conclusion I can only recommend you to take a look at Windows Presentation Foundation/WPF for a better ground to achieve proper type setting as you will get stuck in a lot of compromises using WinForms for this (I made a font viewer which is where I came across WPF as I wanted to show glyphs and detailed information about it including black-box and so forth - that was painful enough).
UPDATE:
WebBrowser as type-setting engine
A possible work-around of this is to use the WebBrowser control to do the setting. It's not an actual hack, but a bit hack-ish as it establish a initially unnecessary dependency on the IE browser on the user's computer.
However, this can turn out to be flexible when it comes to type setting as you have the same simple controls over text as with any HTML page.
To get a result you attach the HTML with styles and attributes for the text. You can even combine it with images and so forth (obviously).
The control can be for example on another hidden form not visible to the user.
After dropping in the WebControl on the form or creating it manually setting HTML is done in a single step:
WebBrowser1.DocumentText = "<span style='font-size:24px;'>Type-setting</span> <span style='font-family:sans-serif;font-size:18px;font-style:italic;'>using the browser component.</span>";
Next step is to grab what you render as HTML as an image which can be done as this:
using mshtml;
using System.Drawing;
using System.Runtime.InteropServices;
[ComImport, InterfaceType((short)1), Guid("3050F669-98B5-11CF-BB82-00AA00BDCE0B")]
private interface IHTMLElementRenderFixed
{
void DrawToDC(IntPtr hdc);
void SetDocumentPrinter(string bstrPrinterName, IntPtr hdc);
}
public Bitmap GetImage(string id)
{
HtmlElement e = webBrowser1.Document.GetElementById(id);
IHTMLImgElement img = (IHTMLImgElement)e.DomElement;
IHTMLElementRenderFixed render = (IHTMLElementRenderFixed)img;
Bitmap bmp = new Bitmap(e.OffsetRectangle.Width, e.OffsetRectangle.Height);
Graphics g = Graphics.FromImage(bmp);
IntPtr hdc = g.GetHdc();
render.DrawToDC(hdc);
g.ReleaseHdc(hdc);
return bmp;
}
From: Saving images from a WebBrowser Control
Now you can place the bitmap on to your normal page. ..Or just use the control directly on the form with reduced interactive capability (right-click menu could easily become a problem if not).
Not knowing the exact usage that this is for, this may or may not be a suitable solution but it gives some powerful options and can be in place of a third-party solution.
Components
Looking high and low it seem that this area is not so much targeted. I could find one component that comes close but the pattern continues: one will be hitting a nail with a sledgehammer. It ends up in the same category as the WebBrowser work-around.
This component is really a full fledged editor but by disabling most of it it can perhaps be used to simply display formatted text/graphics with type setting sort of at hand:
http://www.textcontrol.com/en_US/products/dotnet/overview/
Another possibility is to use a PDF component to set up the content and use a component to render the PDF as graphics (commercial):
http://www.dynamicpdf.com/Generate-PDF-.NET.aspx
http://www.dynamicpdf.com/Rasterizer-PDF-.NET.aspx
Non-commercial:
http://www.pdfsharp.net/?AspxAutoDetectCookieSupport=1
Using GhostScript to get image:
http://www.codeproject.com/Articles/32274/How-To-Convert-PDF-to-Image-Using-Ghostscript-API
The obvious static alternative
..and corky perhaps, but in any case I'll include it as simplicity sometimes works best -
If it is not a absolute requirement to be able to create these pages dynamically, generate all the text and graphics in Illustrator/Photoshop/inDesign etc. and save the result as images to be displayed.
In order to lay down text: there are several possibilities:
A simple label, that lets you simple text manipulation (like font, placement, color, etc.)
A rich text document that you may change the properties of the control to suite your needs, keep in mind that this one may present some simple images, etc.
An image -> that you may create dynamically, with the graphics object, with the onpaint event. this is not recomended, as its a very low level approach, but as you know as low level as you get, the more power you gain.
Combination of many controls, in a custom control you create, that you hold the information you want to draw / write in local members -> then keeping cont to when you change something, then set a flag (_needToBeRepainted = true;), and then on repainting, if(_needToBeRepainted) draw everything.
please let me know if you need further assistance solving this one.
I have the following needs. There are some number of forms, i.e blanks - for example the ones used in surveys. The ones which aren't filled with information, I will call image templates from now on. Apart from the image templates, I have also many images, which are essentially the image templates filled with information. For example, there is a survey and there are two blanks for filling - these are the image templates. Many people have filled the blanks with their personal information and these are the images.
The image templates are scanned in a perfect shape. But many of the scanned images are tilted or not properly aligned, or maybe scaled. So I have the following requirement - every image must be recognized to which image template it belongs. After it is recognized, it must be properly skewed, aligned and scaled to the image template.
I know this is a complex task and that's why I need a library, preferably a C# one. I have found AForge, but till now I have only seen a suitable method for skewing. Essentially I need a library which takes as input an image template and an image, and sets a flag if the image does not match to the image template. But if it matchs it must return the appropriate skew angle, alignment and scaling.
If you have any ideas or used such a library, I will appreciate it greatly.
Wish you all the best,
Petar
The problem seems to be an image registration problem coupled with some template matching problem.
image registration
Depending on how the scanned document may be distorted (scale factor, rotation, skew...) one can register images using simple rigid transform (i.e. translation + rotation, only two corresponding points are needed) to more complex one such as non rigid transform (more corresponding point are needed). The corresponding points can be manually given but ideally should be automatically detected.
ITK library includes several methods for image registration
template matching problem
Once your images are aligned, the comparison between an image and possible templates database could be achieved by first extracting characteristic features in the image and comparing them to your template database. This is very general and should be refined with respect to the image used.
There is other way that combine both image registration and template matching
the Bag Of Features approach which consists in extracting interesting points (robust to several types of image deformation) from the image, the points generate a signature that characterizes the image, the image comparison being in fact a signature comparison.
I used to work for a company, Accusoft Pegasus, which has some interesting forms recognition software. I've not seen their FormFix tool in action in a few years, but it should be able to do what you are needing.
I'm creating a newspaper authoring system. Today I'm using Aspose.Words library to generate newspaper using Docx format as output, based on a lot of other documents as input.
The basic idea is to load a lot of articles documents into a List, then generate a final docx with newspaper.
We need to get the total height of a text (with images and tables) inside columns. As libraries like Aspose.Words deal with Docx format like DOM, there isn't way to know how text will be arranged inside columns. Then I can't know the real height.
We've worked in our own way to get this height. I'm using MeasureString() function from System.Drawing.Graphics namespace. It returns width and height used by string and I can estimate how many lines (and points or inches) it will use inside a column.
But it is very poor and we need a more decent solution. We are thinking to use OpenXML SDK to get this Height, can we?
Aspose.Words doesn't support a way to know it and all Render classes are private to the library.
Can you think a new way to get this height?
Thank you,
Daniel Koch
This property isn't exposed in Open XML or the SDK (or VBA/VSTO for that matter). How exactly the height is calculated is not in any documentation. Possibly the way you are doing it is a way to proceed.
Another possible way is to put your TextColumns in a Table Column/Cell and grab that height (but if it is two text columns in the cell and the first one "fills" the cell top to bottom and the second one doesn't, you'll still have the issue of not being able to calculate the size of the second one).
I have almost the same problem that you have.. But in my case I'm dealing with Questions inside an Test Exam..
Well nowadays, we are using RTF to build the questions and a RichTextBox the measure the height.. Just like that (http://blogs.technet.com/david_bennett/archive/2005/04/06/403402.aspx)..
And I wanna to migrate to DOCX.. But still no luck on how to measure the question with tables and images.. :-(
Right now I'm studying the Document Members (http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word._document_members.aspx), to try to do with Word Automation..
Regards,
Bruno
Thank all for answer.
I finished it changing Aspose.Words to PDFLib. Now I can control pages, columns or anything using Postscript Points.
We keep Aspose.Words only to content import, but it isn't indicate to print newsletter.
I am searching for graphic libraries that can draw seismic data; which is a large number of curves drawn vertically and gives you a shape like this:
alt text http://img237.imageshack.us/my.php?image=seismicdataxb2.png
and I need it to do be able to:
1) select each curve with mouse and return a value that tells me which curve that I have selected.
2) label the scale with more than one value.
thanx in advance.
Have you thought about creating a WPF application? This probably gives you what you need.
Sorry, old question I know; but INT sell a series of visualization libraries (including .NET) for this type of thing:
http://www.int.com/
Their C++ libraries are also cross-platform: I used to work for a company that used them in X Windows and MS Windows. This was a big deal in those days (circa. 2000).