Delphi POS printing receipt text alignment [closed] - delphi

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
How can I print to POS printer if the output format should be like this?
paper size 3 inches
line 1 = ITEM DESCRIPTION
line 2 = QTY UNIT x UNIT PRICE_ _ _ _ _ _ _ TOTAL PRICE
Total PRICE is right align
sample format
BOND PAPER
1 REAM x 100.00 --------------- 100.00
BOND PAPER 2
2 REAM X 100.00 --------------- 200.00
BOND PAPER 3
1 REAM X 1,354.00 ----------- 1,354.00

POS printers typically use fixed width fonts, so right aligning the value of TotalPrice is simply a matter of calculating the amount of Padding to insert into the line after the ItemDescription.
In your example, you are using a 38 character line, so if the length of ItemDescription is 15 characters long, and the length of the TotalPrice is 6 characters long, then Padding needs to be 38 - (ItemDescription + TotalPrice) = 38 - (15 + 6) = 17 characters long. But since you seem to add a space immediately after ItemDescription and before TotalPrice your Padding needs to subtract these 2 additional characters... so, in that case Padding needs to be 15 characters long.
Applying this to your last line:
Length(ItemDescription) = 17
Length(TotalPrice) = 8
Padding = 38 - (17 + 8 + 2) = 11
So the final line that you will send to your fixed width font POS will be:
PrintLine = Concat(ItemDescription,' ',StringOfChar('-',Padding),' ', TotalPrice)
This should always right align TotalPrice for the given fixed width character paper size (change the 38 to whatever the number of characters your POS printer is rated at), and all long as the total length of ItemDescription, TotalPrice and your single character spaces does not exceed the total character width of the printer (you should probably check this before calculating Padding).

Related

Calculate the output size in convolution layer [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 1 year ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
How do I calculate the output size in a convolution layer?
For example, I have a 2D convolution layer that takes a 3x128x128 input and has 40 filters of size 5x5.
you can use this formula [(W−K+2P)/S]+1.
W is the input volume - in your case 128
K is the Kernel size - in your case 5
P is the padding - in your case 0 i believe
S is the stride - which you have not provided.
So, we input into the formula:
Output_Shape = (128-5+0)/1+1
Output_Shape = (124,124,40)
NOTE: Stride defaults to 1 if not provided and the 40 in (124, 124, 40) is the number of filters provided by the user.
You can find it in two ways:
simple method: input_size - (filter_size - 1)
W - (K-1)
Here W = Input size
K = Filter size
S = Stride
P = Padding
But the second method is the standard to find the output size.
Second method: (((W - K + 2P)/S) + 1)
Here W = Input size
K = Filter size
S = Stride
P = Padding
Let me start simple; since you have square matrices for both input and filter let me get one dimension. Then you can apply the same for other dimension(s). Imagine your are building fences between trees, if there are N trees, you have to build N-1 fences. Now apply that analogy to convolution layers.
Your output size will be: input size - filter size + 1
Because your filter can only have n-1 steps as fences I mentioned.
Let's calculate your output with that idea.
128 - 5 + 1 = 124
Same for other dimension too. So now you have a 124 x 124 image.
That is for one filter.
If you apply this 40 times you will have another dimension: 124 x 124 x 40
Here is a great guide if you want to know more about advanced convolution arithmetic: https://arxiv.org/pdf/1603.07285.pdf
Formula : n[i]=(n[i-1]−f[i]+2p[i])/s[i]+1
where,
n[i-1]=128
f[i]=5
p[i]=0
s[i]=1
so,
n[i]=(128-5+0)/1+1 =124
so the size of the output layer is: 124x124x40
Where '40' is the number of filters
(124*124*3)*40 = 1845120 width = 124 height = 124 depth = 3 no. of filters = 40 stride = 1 padding = 0

How to get the accurate font size(height) in pdf

I have a sample pdf (attached), and it includes a text object and a rectangle object that have almost the same height. Then I checked the content of the pdf by using itextrup as below:
1 1 1 RG
1 1 1 rg
0.12 0 0 0.12 16 50 cm
q
0 0 m
2926 0 l
2926 5759 l
0 5759 l
0 0 l
W
n
Q
1 1 1 RG
1 1 1 rg
q
0 0 m
2926 0 l
2926 5759 l
0 5759 l
0 0 l
W
n
/F1 205.252 Tf
BT
0 0 0 RG
0 0 0 rg
/DeviceGray CS
/OC /oc1 BDC
0 -1 1 0 1648 5330 Tm
0 Tc
100 Tz
(Hello World) Tj
ET
Q
q
0 0 m
2926 0 l
2926 5759 l
0 5759 l
0 0 l
W
n
0 0 0 RG
0 0 0 rg
/DeviceGray CS
6 w
1 j
1 J
1649 5324 m
1649 4277 l
1800 4277 l
1800 5324 l
1649 5324 l
S
EMC
Q
Obviously the user space matrix is determined by [0.12 0 0 0.12 16 50], and the height for the rectangle is (1800-1649)*0.12*1=18.12, and for the font size I use 205.252*0.12=24.63024. Since the two values are not close, my problem is how to get the height/size of the font?
sample.pdf
OK - I took a look at your file and you're basically hosed. That's the scientific answer, now let me clarify :)
Bad PDF!
The PDF you have up there as a sample contains a font that is not embedded. That "/F1 Tf" command you have there points to the font "ArialMT" in the resources dict for that page. Because the font has not been embedded, you only have two options:
Try to find the actual font on the system and extract the necessary information from there.
Live with the information in the PDF. Let's start with that.
Font Descriptor
Here is an image from pdfToolbox examining the font in the PDF file (caution: I'm associated with this tool):
I've cut off some of the "Widths" table, but other than that this is all of the information you have in the PDF document for this font. And this means you can access the widths for each glyph, but you don't have access to the heights of each glyph. The only information you have regarding heights is the font bounding box which is the union of all glyph bounding boxes. In other words, the font bounding box is guaranteed to be big enough to contain any glyph from the font (both horizontally and vertically).
System Information
You don't say why you need this information so it becomes a little harder to advise further. But if you can't get the information from the PDF, you're only option is to live with the inaccurate information from the PDF or to turn to the system your code is running on to get you more.
If you have the ArialMT font installed, you could basically try to find the font file and then parse the TrueType font file to find the bounding boxes for each glyph. I've done that, it's not funny.
Or you can see if your system can't provide you with the information in a better way. Many operating systems / languages have text calls that can get accurate measurements for you. If not, you can brute force it by rendering the text you want in black on a white image and then examining the pixels to see where you hit and thus how big the largest glyph in your text string was.
Wasteful though that last option sounds, it's probably the quickest and easiest to implement and it - depending on your needs - may actually be the best option all around.
I have a sample pdf (attached), and it includes a text object and a rectangle object that have almost the same height.
Indeed, your PDF is displayed like this:
But looking at this one quickly realizes that the glyphs in your text "Hello World" do not extend beneath the base line like a 'g', 'j' or some other glyphs would:
(The base line is the line through the glyph origins)
Since the two values are not close, my problem is how to get the height/size of the font
Obviously the space required for such descenders beneath the base line must also be part of the font size.
Thus, it is completely correct and not a problem that the height of the box (18.12) is considerably smaller than the font size (24.63024).
BTW, this corresponds with the specification which describes a font size of 1 to be arranged so that the nominal height of tightly spaced lines of text is 1 unit, cf. section 9.2.2 "Basics of Showing Text" of ISO 32000-1. Tightly spaced lines obviously need to include not only glyph parts above the base line but also those below. Additionally it furthermore includes a small gap between such lines as even tightly spaced lines are not expected to touch each other.

Want to set label value on TeeChart InnerTick VC++

I wanted to set label text value on TeeChart InnerTick using VC++. like we have below example (I wanted to set AAAA,BBBB,CCCC,DDDD values).
// Sorry i was not able to attach image.
Below mention chart we have created using CGraph. to get co-ordinates we are using SDKInfo property. i wanted to know that how can we get all these x axis,y axis values using TeeChart. Is there any API to get these co ordinates ?
1
X axis max (your data units)
2
X axis min (your data units)
3
Y axis max (your data units)
4
Y axis min (your data units)
5
X axis length (Graphics Server view units)
6
Y axis length (Graphics Server view units)
7
X origin (Graphics Server view units)
8
Y origin (Graphics Server view units)
9
Label font size (percentage of system font)
|
|
| AAAA BBBB CCC DDDD
|__________|____________________|___________________|__________________|________
| | | |
111 222 333 444
Thanks,
I'm not sure about what exact TeeChart version are you using so this answer may be a bit vague.
All binary installations of TeeChart come with a program we call "Features Demo". This program includes examples showing how to use the majority of features supported.
One of the examples is the "Custom Labels", you should find it under "All Features\Welcome !\Axes\Labels\Custom Labels" in the program.
Also, to convert axis values to screen pixels, all TeeChart versions provide "Calc*" functions for it. Ie, to convert the value 10 in the bottom axis to pixels, in TeeChart ActiveX:
XPix = tChart1.Axis.Bottom.CalcXPosValue(10);
Just note these functions need the chart to be drawn once so the internal properties have been initialized and the calculations can be correctly done.

Align vertex data

I've read this post about vertex alignement and I'm not sure to understand everything.
The article say that I need to add an offset after each attributs to have aligned data (By the way, the article talk about 4 bytes but in his picture, they add two bytes).
In my situation, I've got something like that:
Position : 3 floats (3 * 4 bytes = 12)
Colors : 4 unsigned char (4 * 1 bytes = 4)
Uvs : 2 shorts (2 * 2 bytes = 4)
So, I've just to add 4 bytes for each attributs?
Thanks!
The article recommends 4-byte alignment per attribute. In the example, they use an attribute with 3 Shorts is used, which is 6 byte total, so the follwoing attribute will not be aligned to 4-byte-boundaries. Hence, they add two padding bytes.
In your case, all attributes are multiples of 4 bytes already, so you don't habe to add any padding to get 4-byte alignment.

How can I know the line number of editfield of blackberry

I would like to know the line number in EditField while I am typing some text in this component.
Get the width of the edit field. (int returned) (e.g. 320 px)
Get the font width of your current text. Font class have getAdvance() method that accepts the string parameter (int returned) (e.g. 650 px)
if string width > edit field width you can divide string width and edit width and on the other step get the modulo of it. (here you will get 2 as division and 10 will be yr modulo. That means you have filled two lines + in third line you are having characters that can be fit into 10 px.
I hope it will solve your problem, but be careful if you use any long words, the module had never been tested with long words but I fear about result's accuracy with long words.

Resources