How Do I Set the Line Width for a Single Stroke in Prawn - prawn

I'm trying to set the width of a stroke line in prawn for a single line. What I'd like to do is something like ...
pdf.stroke_horizontal_line(0, bounds.width, :at => row*spacing, :line_width => 10)
This doesn't work, and so I'm having to get the current line width, save it, set the new line width, draw the line, and then put the original line width back. Not the end of the world, but it seems like this should be built in and I have a feeling I may be missing something.
Any ideas?

Here's what I got from Gregory Brown via the Prawn Google Group (https://groups.google.com/forum/#!topic/prawn-ruby/w80AYnHo2X8) ...
pdf.mask(:line_width) do
pdf.line_width (row % DARK_LINE_SPACING == 0) ? DARK_LINE_WIDTH : pdf.line_width
pdf.stroke_horizontal_line(0, bounds.width, :at => row*spacing)
end
Basically, you'll need to use the undocumented feature mask for this.

Related

Pytesseract OCR is not recognizing small words because of horizontal line

I've just started exploring pytesseract. Here's the issue I'm facing:
I have the following input image.
Now, when I try running OCR on this, I get the following output:
Thanks for signing up. Now you too
can pick your favorite pillows
Option AB
After trying it out on multiple image samples, I can safely conclude the following:
It is not a non-dict word penalty.
It is omitting words which are short. Almost as though it has a min-width that is taking effect, and is veto-ing any line with width lesser than that.
It only happens if the input image has the bounding rectangle around it. If I remove that from the input image I get the correct output.
i.e. on the following image:
I get the following output
Thanks for signing up. Now you too
can pick your favorite pillows
Option
Opon
Option AB
I'm unable to figure out where am I going wrong. Here's the code I'm using:
from PIL import Image
import pytesseract
import argparse
import cv2
image = cv2.imread('testImage.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.threshold(gray, 240, 255, cv2.THRESH_BINARY)[1]
filename = "intermediate.png"
cv2.imwrite(filename, gray)
im = Image.open(filename)
text = pytesseract.image_to_string(im)
print(text)
I've tried tinkering around with some of the config parameters (crunch_del_min_width, language_model_min_compound_length, and a few others) too, but nothing helped.
Solution found here: Pytesseract OCR multiple config options
My code was originally like yours (line 1) and I was encountering the same error. What worked for me was setting psm = 10 in the config param to allow single character recognition.
Code sometimes returning None:
line 1 : text = pytesseract.image_to_string(cropped)
Added code on the next line:
line 2 : text = text if text else pytesseract.image_to_string(cropped, config='--psm 10')
The first line will attempt to extract sentences. If it succeeds, the second line keeps the value the same. However, if it returns None, it will look for single characters (allowing smaller words to be outputted).
Alternatively, if you just wanted to catch small words:
line 1 : text = pytesseract.image_to_string(cropped, config='--psm 10')

Text Wrapping in Cocos2d-x

I am trying to get my text labels to automatically resize if the text is longer than the box they are in. I also want it to support multi-line functionality. I have done some searching online and saw that it used to work something like this:
CCLabelTTF::labelWithString(“This is a sentence longer than a line width.2d-x”, CGSizeMake(**0, 0**), UITextAlignmentCenter, “Thonburi”, 20);
but that seems to no longer be available in cocos so I am not sure what to do.. Right now I have my label set up as follows:
myQuestion = Label::createWithTTF("Testing to see if text wrap will work" ,c_strFontNameBase, 50);
myQuestion->setPosition(boxLabel->getContentSize().width/2, boxLabel->getContentSize().height/2);
boxLabel->addChild(myQuestion, 50);
Is there some way I can use a similar way to the top example to make mine work? This doesn't seem like it should be very hard thing to do but I am finding a lack of documentation on it online...
I believe, you can only make one dimension of the label auto-resizable i.e. either width or height can be auto-resizable. By default when you create label as follows, width of the labels are set to resize automatically with fixed height:
auto label = Label::createWithTTF("Hello World gsdhsgdh gshdghsg yutywe gdgshdgy bnbjh hshhashgy hjnbdnsdhh ghhsgdhg ghghghsd ghhghsd ghghghgsd jkjkhsdjkj ououisdusydsi kkjkxncmxcjh kcxhjxhcjx jkuiushjxchxjch hjhjchxuyuychjc ", "fonts/Marker Felt.ttf", 24);
// position the label on the center of the screen
label->setPosition(Vec2(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - label->getContentSize().height));
// add the label as a child to this layer
this->addChild(label, 1);
But if you want multi-line support i.e. fixed width and resizable height you just need to set dimension of the label with fixed width and zero height as:
label->setDimensions(300, 0);
I hope it will help.

capture 2 texts from the screen and compare them using AutoHotkey

I'm working with AutoHotkey and I need to capture two sentences from my screen and compare them. Anyone knows how to do it?
Thanks a lot!!!
OK, this shows some effort.
When you use mouseClickDrag, you have to be absolutely sure that the text will ALWAYS be at those exact locations, which is very unlikely, think about a menu bar moving the webpage down, or about using F11, doing the opposite, changing the font style/size, just zooming in/out, or making the window smaller, such that the text block becomes smaller in width but longer in length, having another banner add that is smaller or larger, et cetera. If you can use an other method (e.g. Find text and from that position, jump 10 words to the left (^{Left 10}) and then select the next 5 words (+^{Right 5}), would be much more reliable.
#NoEnv
#SingleInstance Force
#installKeybdHook
#Persistent
Return ; Stop here on startup to prevent running the whole script on startup
+Insert:: ; Using the [Shift]+[Insert] Key as the hotkey here.
MouseClickDrag,left, 540, 295, 602, 295 ; HighLight area1
Send, ^c
ClipWait, 2
MyVar1:=ClipBoard ; OR MyVar1 = %ClipBoard%
MouseClickDrag,left, 540, 295, 602, 295 ; HighLight area2
Send, ^c
ClipWait, 2
MyVar2:=ClipBoard ; OR MyVar2 = %ClipBoard%
If (MyVar1 = MyVar2)
{
MsgBox, The values %MyVar1% and %MyVar2% are equal
Send, %MyVar1%
; ClipBoard:=MyVar1 ; OR ClipBoard = %MyVar1% is alternative way (Faster)
; Send, ^v
}
Else
{
MsgBox, The values %MyVar1% and %MyVar2% are NOT equal
Send, %MyVar1% AND %MyVar2%
; ClipBoard = %MyVar1% AND %MyVar2% ; is alternative way (Faster)
; Send, ^v
}
Return
You could add some tests to only execute this when Chrome, FireFox or IE is active, but I have left that out. First chew on this code.

MSChart HowTo Create a Second CursorX to have multiple Cursor by a second Transparant ChartArea?

I am try to introduce a Second CursorX at AxisX Primary if this is possible some how?
I did try to activate a second CursorX at Secondary but that one did not work as expected,
I also readed about Line Annotation and Vertical Line Annotation and created some kind of line but a Second set of CursorX CursorY would be far nicer
I did try to create and as much as empty as possible and Transparant Second ChartArea which i try to overlay on top of the ChartArea1, i noticed InnerPlotPosition and Postion of both ChartArea should stay in track to get a full aligned Overlay, and next the CursorX of second ChartArea should be displayed on top of ChartArea1
This is what i think how it could be done but don't have a clue if it sounda for a good way to create a second CursorX maybe Line Annotation is an easier road to rome
Any help suggestion are welcome
Thanks in advance
Suppose your chart contains multiple chart areas aligned vertically, below code allows you set CursorX in each chart area:
Dim c1 As New Chart
'...here code block to build each chart area ...
'...then use below sample code to align each chart area vertically:
'c1.ChartAreas(i).AlignmentOrientation = AreaAlignmentOrientations.Vertical
'c1.ChartAreas(i).AlignWithChartArea = c1.ChartAreas(0).Name
'below set horizontal cursor (it is a gold vertical bar in each chart area):
For Each area As ChartArea In c1.ChartAreas
area.CursorX.LineColor = Color.Gold
area.CursorX.LineWidth = 3
area.CursorX.IsUserEnabled = True
area.CursorX.IsUserSelectionEnabled = True
area.CursorX.SelectionColor = System.Drawing.Color.PaleGoldenrod
Next

Is there any way to add gridlines to a gRaphael line chart?

I have a line chart that I've created with gRaphael. It has axes and tick marks, but I'd like to have grid lines. Is there built-in way to achieve this or an add on library that can help me?
gRaphael does not have a built-in way to add grid lines, but it is pretty easy to draw them, either by editing the source code or manipulating your graph object after you create it.
I had found an extension called RaphAlytics and used its drawGrid() function in cases where I needed a bounding box with a grid.
You can adapt this function for any gRaphael graph as needed to draw gridlines. On a line chart, I needed to draw horizontal gridlines that were aligned with the left axis marks on a line chart, so I used the function as an example like this:
// Draw horizontal gridlines
for (var i = 0; i < g.axis[1].text.items.length; i++) {
r.path(['M', x, g.axis[1].text.items[i].attrs.y, 'H', w + x]).attr({
stroke : '#EEE'
}).toBack();
}
Here's a working fiddle to illustrate that example: http://jsfiddle.net/KM3BB/1/
I tried doing this yesterday. Short answer: gRaphaël can't do this for you with any linechart options nor axis options, you have to do-it-yourself with Raphaël.
Something like:
var r = Raphael("holder"), txtattr = { font: "12px sans-serif" };
r.path('M 15 200.5 L 310 200.5 M 15 180.5 L 310 200.5');
r.linechart(10, 10, 300, 220, x, [y, y2, y3]);
This means under my linechart draw a path which starts from 15,200.5 and draws a straight line to 310,200.5 moves to 15,180.5 and draws a line to 310,180.5. Don't ask me why but the .5 is important for getting the stroke to actually be 1px wide and solid black. Otherwise it seems to get aliased to 2px wide at 50% opacity. You have to calculate the exact placement in regards to your linechart yourself.
You can also play with the path function in the playground by changing r to paper.
You might also consider looking at Google Chart Tools if your looking for things like defining the exact range of the axis (as opposed to just the min and max of the input).