Pango and X11, font description mismatch and display issues - c

Being relatively new to X11, I've been trying to make font rendering painless in my C example program. After giving up on making Xtf work reliabily, pangocairo seemed like the next best choice. I have encountered however an issue: pango doesn't always recognize the font description from a string. The following call does create a valid PangoFontDescription that will show text to a cairo x11 surface, however using any other font family that is not Sans or Serif won't display anything.
desc = pango_font_description_from_string ("Sans Bold 27");
The following one doesn't work no matter what sizes or weights are set up.
desc = pango_font_description_from_string ("Fixed 14");
What bugs me the most, the utility pango-view will create a perfectly working output of all descriptions given, even though they won't work in my pangocairo example.
pango-view --no-display --output out.png --text 'Test' --font 'Fixed 14'
Creating a new empty PangoFontDescription and setting up family, size and weight separately has the same exact issue as above with pango_font_description_from_string.
I'm really wondering what the issue could be, and the pango documentation hasn't really been helpful on this regard.

Related

Trying to center text from proportional font on TTGO T5 ESP32 in C

I created a font binary file from a TTF file and I can place it on the TFT screen on the TTGO T5 T-Display just fine. Looks great! I have been looking for 2 days for how to center this information on screen. I cannot find the format of the .vlw file or the format of what I included in the sketch to print from (converted by online site from .vlw format). And I can't find a routine to do it for me.
I am using the TFT_eSPI and it does not contain a getTextBounds routine. There is one in the Adafruit_GFX library and I included that but it not available any way I have tried. And I can't read it enough to fix it for what I need. Too deep for me at this time, especially since I don't know the data file format. I have been programming for decades but can't make this stuff up!
So, simple question with a complex answer, it seems. How to center a proportional font (invoked by name (not one of the numbered default fonts) on TTGO TFT screen using ESP32.
This makes my brain hurt. Help, please...

PDFSharp TextFormatter.DrawString() with fractional font sizes in PDFSharp gives shortened lines

I'm using WPF, and I have a RichTextBox in my user interface, which I convert to a PDF file. I take the RichTextBox.Document FlowDocument from the RichTextBox and translate it to a PdfSharp.Pdf.PdfPage.
This has been working pretty good (after finding some help for wordwrap on SO), but I found that I need to scale the PDF, so after I get the font from the FlowDoc, I multiply it by a scale factor, in my case 0.88.
This appeared to work great, but on closer inspection, I found that a few lines were terminating early.
// these lines use font info from the FlowDoc. To simplify, I've
// hard-coded the font size.
// this works fine:
var thisRunXFont = new XFont(thisRun.FontFamily.Source, 14, xRunFontStyle);
// this causes problems:
var thisRunXFont = new XFont(thisRun.FontFamily.Source, 12.32, xRunFontStyle);
Has anyone else seen this kind of trouble? I do go on to use MeasureString() to get the enclosing paragraph -- but forcing the rectangle to be wider does not change the behavior.

SceneKit – access destination color in shader modifier for blending

Is there a way to access last fragment color (destination color) in Metal shader modifier similar to gl_LastFragData in GLES?
My goal is to perform custom blending using shader modifiers (SceneKit's SCNBlendModes do not suffice in my situation). Currently I'm using SCNTechnique with 3 passes (render the destination, render the source, combine) to achieve this and that seems like a major overkill to me + it is really hard to have several blending groups without introducing new passes.
SCNProgram does not seem like an option for several reasons (I'm using PBR, tessellation/subdivision; I'd rather stick with using techniques for now I guess).
I've tried using #extension GL_EXT_shader_framebuffer_fetch : require as suggested in this answer, but it doesn't work even for GLSL shader modifiers (I'm using Xcode 9.0 and iOS 11).
I've also stumbled upon this wonderful gist that has SceneKit's default metal shader implementation, but it seems that blending is not performed there. Which makes me wonder if that is the reason why I can't find any destination color reference: blending happens somewhere else.
Is SCNProgram is the only way besides the SCNTechnique atrocity?
P.S:
The only mention of gl_LastFragData in the context of Metal that I've found is in chapter 4.8 Programmable Blending of Metal Shading Language Specification which would be helpful if I could somehow access the [[color(0)]] or something similar in shader modifier (if that's even possible).
I just wanted to check that that you hadn't overlooked the fragment entry point?
In the documentation it says: "Use this entry point to change the color of a fragment after all other shading has been performed."
I'm not sure if this is exactly what you mean by accessing the "last fragment color" but thought it might be worth mentioning.
https://developer.apple.com/documentation/scenekit/scnshadermodifierentrypoint/1523342-fragment

How to detect text region in image?

Given an image (i.e. newspaper, scanned newspaper, magazine etc), how do I detect the region containing text? I only need to know the region and remove it, don't need to do text recognition.
The purpose is I want to remove these text areas so that it will speed up my feature extraction procedure as these text areas are meaningless for my application. Anyone know how to do this?
BTW, it will be good if this can be done in Matlab!
Best!
You can use Stroke Width Transform (SWT) to highlight text regions.
Using my mex implementation posted here, you can
img = imread('http://i.stack.imgur.com/Eyepc.jpg');
[swt swtcc] = SWT( img, 0, 10 );
Playing with internal parameters of the edge-map extraction and image filtering in SWT.m can help you tweak the resulting mask to your needs.
To get this result:
I used these parameters for the edge map computation in SWT.m:
edgeMap = single( edge( img, 'canny', [0.05 0.25] ) );
Text detection in natural images is an active area of research in computer vision community. U can refer to ICDAR papers. But in your case I think it should be simple enough. As you have text from newspaper or magazines, it should be of fixed size and horizontally oriented.
So, you can apply scanning window of a fixed size, say 32x32. Train it on ICDAR 2003 training dataset for positive windows having text in it. U can use a small feature set of color and gradients and train an SVM which would give a positive or negative result for a window having text or not.
For reference go to http://crypto.stanford.edu/~dwu4/ICDAR2011.pdf . For code, you can try their homepages
This example in the Computer Vision System Toolbox in Matlab shows how to detect text using MSER regions.
If your image is well binarized and you know the usual size of the text you could use the HorizontalRunLengthSmoothing and VerticalRunLengthSmoothing algorithms. They are implemented in the open source library Aforge.Net but it should be easy to reimplement them in Matlab.
The intersection of the result image from these algorithm will give you a good indication that the region contains text, it is not perfect but it is fast.

How would I overlay text onto an image using imagick in either C or Go?

I'm actually using the Go bindings for imagick. Online there aren't really any docs specifically for this but that's okay I can read the C docs and in some cases even the PHP ones; they are all fairly similar.
I would like to use AnnotateImage method, which does currently work:
c.magickWand.ReadImage("example.jpg")
c.magickWand.SetImageMatte(false)
c.drawingWand.SetFont(c.font)
//c.drawingWand.SetFontSize(c.fontSize)
c.pixelWand.SetColor("black")
c.drawingWand.SetFillColor(c.pixelWand)
c.drawingWand.SetGravity(imagick.GRAVITY_CENTER)
c.magickWand.AnnotateImage(c.drawingWand, 0, 0, 0, "This is my text!")
c.magickWand.WriteImage(c.newImageName)
So my code so far looks a bit like the above ^
This is all Go, but method names are pretty much the same in C, and in some cases PHP. The above actually works fine. It will put the text in the centre of the image, but I don't want to specify the font size, and I don't want the text in the centre of the image.
Ideally I would like the text to be towards the bottom of the image, and for imagick to choose the best font size based on the size it has to work with. I know it is somehow possible, I've been close, however I can't get to the bottom of this.

Resources