R3GUI - How to set the size of an 'area' - rebol

I've tried:
hgroup [label "Note" 64 AFV_Note: area 100x50]
That produces the correct width but the height is still too tall.
I also tried:
hgroup [label "Note" 64 AFV_Note: area options [init-size: 100x50]]
That results in an error; probably not an option for 'area'.

Does this help at all?
https://github.com/gchiu/RSOChat/blob/master/rsochat.r3#L811
chat-area: area "" 600x90 options [min-hint: 750x50 detab: true]

Related

SceneKit repeat texture

For some reason, using the following material on an SCNBox keeps resulting in a stretched texture. Any idea where I'm missing something?
material.diffuse.contents = [SKTexture textureWithImageNamed:#"arrowtexture.jpg"];
material.diffuse.wrapS = SCNWrapModeRepeat;
material.diffuse.wrapT = SCNWrapModeRepeat;
You can control SKTexture's stretch this way:
material.diffuse.contentsTransform = SCNMatrix4MakeScale(3, 1, 1);

Image width & height reversed in visual Studio vb.net

When I view a photograph taken with a digital camera the height is 4000 and the width is 6016, if I take the picture by turning the camera 90 Deg. the height is 6016 and the width is 4000. All is good, if I examine the properties of the image with file explorer(Windows 10) it looks correct for either picture. If I view the picture in Photoshop or picture viewer all looks correct as far as orientation. In my app I use exif to get the width and height it always shows width as 6016 and height as 4000. if I get an image via code:
dim orgimage as bitmap = new bitmap("C:/image/picture.jpg")
the width is always 6016 and the height is always 4000, if I change the 4000 to 3999 via Photoshop the image width and height are correct in my app. Is this a limitation of Visual Studios Visual Basic?
The reason for the difference is that the other applications are manually applying the correction for Exif.Image.Orientation (tag 274).
Just inspect this tag and rotate the bitmap accordingly.
Public Function OrientateImage(img As Image) As Boolean
Const EXIF_ORIENTATION = 274
Dim orientationTag = img.PropertyItems.FirstOrDefault(Function(x) x.Id = EXIF_ORIENTATION)
If orientationTag IsNot Nothing Then
Dim orientation As Short = BitConverter.ToInt16(orientationTag.Value, 0)
Select Case orientation
Case 3
img.RotateFlip(RotateFlipType.Rotate180FlipNone)
Case 6
img.RotateFlip(RotateFlipType.Rotate90FlipNone)
Case 8
img.RotateFlip(RotateFlipType.Rotate270FlipNone)
Case Else
Return False
End Select
End If
Return True
End Function
If you check the orientation property it might help answering/helping your issue with width and height being same when reading photo from Camera output.
Please let us know your findings.
Dim orgimage As bitmap = New Bitmap("C:/image/picture.jpg", True)
Dim otherImage As bitmap = New Bitmap("C:/image/picture2.jpg", True)
'Orientation
Dim exifprop As Integer = orgimage.GetPropertyItem(274).Value(0)
Dim exifprop2 As Integer = otherImage.GetPropertyItem(274).Value(0)
'1 = Horizontal (normal)
'2 = Mirror horizontal
'3 = Rotate 180
'4 = Mirror vertical
'5 = Mirror horizontal and rotate 270 CW
'6 = Rotate 90 CW
'7 = Mirror horizontal and rotate 90 CW
'8 = Rotate 270 CW
EXIF tags,
PropertyItem.Id 274

Photoshop Automation of alignment of text layer with image

I have never scripted in photoshop before, so I am wondering if this is possible. The following is currently done manually for over than 300 files. The next time round is for 600 files, therefore I am looking into automating it.
Steps:
Make Image Size to 54pixels Hight and 500px Width -- Found that this is doable.
Align Image Left.
Create a text layer and insert text -- Found that this is doable.
Align Text layer 1px to the right of the image.
Trim empty space.
Would appreciate any help and pointers. Thanks.
This script will get you started: Note that in your request you didn't mention what what the original image was going to be and shrinking it to 500 x 54 is going to stretch it one way or another. Step 2, Align the image left, was omitted as you didn't mention what you are aligning this image to. I suspect you are dealing with a large image and what to shrink it down (as long as it's not smaller than 500 x 54) and work from there. I've also omitted stage 4 as I've hard coded the position of the text to be 1 px from the right hand edge (and it vertically centered with Arial font size 18)
Anhyoo.. you should be able to alter the script to your needs.
// set the source document
srcDoc = app.activeDocument;
//set preference units
var originalRulerPref = app.preferences.rulerUnits;
var originalTypePref = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.POINTS;
app.preferences.typeUnits = TypeUnits.POINTS;
// resize image (ignoring the original aspect ratio)
var w = 500;
var h = 54;
var resizeRes = 72;
var resizeMethod = ResampleMethod.BICUBIC;
srcDoc.resizeImage(w, h, resizeRes, resizeMethod)
//create the text
var textStr = "Some text";
createText("Arial-BoldMT", 18.0, 0,0,0, textStr, w-1, 34)
srcDoc.activeLayer.textItem.justification = Justification.RIGHT
//set preference units back to normal
app.preferences.rulerUnits = originalRulerPref;
app.preferences.typeUnits = originalTypePref;
//trim image to transparent width
app.activeDocument.trim(TrimType.TRANSPARENT, true, true, true, true);
// function CREATE TEXT(typeface, size, R, G, B, text content, text X pos, text Y pos)
// --------------------------------------------------------
function createText(fface, size, colR, colG, colB, content, tX, tY)
{
// Add a new layer in the new document
var artLayerRef = srcDoc.artLayers.add()
// Specify that the layer is a text layer
artLayerRef.kind = LayerKind.TEXT
//This section defines the color of the hello world text
textColor = new SolidColor();
textColor.rgb.red = colR;
textColor.rgb.green = colG;
textColor.rgb.blue = colB;
//Get a reference to the text item so that we can add the text and format it a bit
textItemRef = artLayerRef.textItem
textItemRef.font = fface;
textItemRef.contents = content;
textItemRef.color = textColor;
textItemRef.size = size
textItemRef.position = new Array(tX, tY) //pixels from the left, pixels from the top
}
Everything you listed is doable in a script. I suggest you start by reading 'Adobe Intro To Scripting' in your ExtendScript Toolkit program files directory (e.g. C:\Program Files (x86)\Adobe\Adobe Utilities - CS6\ExtendScript Toolkit CS6\SDK\English)

How to add background/fill color to a bounding_box in Prawn

Is it possible to add a background color to a bounding_box in Prawn?
bounding_box([100, cursor], width: 80, height: 20) do
pad_top(7) { text "THIS IS TEXT", size: 8, align: :center }
stroke_bounds
end
Ive tried adding this to the bounding_box block
background_color: "CCCCCC"
Ive tried adding this inside the block
fill_color "CCCCCC"
background_color "CCCCCC"
Nothing seems to work with a bounding_box
Here the code
bounding_box([200,cursor], :width => 350, :height => 80) do
stroke_color 'FFFFFF'
stroke_bounds
stroke do
stroke_color 'FFFF00'
fill_color '36DA5C'
fill_and_stroke_rounded_rectangle [cursor-80,cursor], 350, 80, 10
fill_color '000000'
end
end
This was discussed 2008 [1] (apparently didn't lead anywhere though), i don't see it mentioned anywhere in the manual [2] either.
As to how it's done: After putting all content into your bounding box, you can obtain the resulting width and height from the bounding box. With that information you can use primitve rectangle drawing to fill it. Afterwards you will have to redraw the content, because by now you will have painted right over it with your rectangle fill.
Hopefully (probably?) there's a better way too, one where you don't need to draw your actual content twice; Make sure to share it with everyone when you come across it!
All the stuff I mentioned in the quick how-to above is beautifully documented in the manual [2]; Good luck!
[1] https://groups.google.com/forum/#!msg/prawn-ruby/6XW54cGy0GA/RdXwL0Zo_Z8J
[2] http://prawn.majesticseacreature.com/manual.pdf
EDITTED Completely
Still needs some work but try this out
module Prawn
module Graphics
def fill_and_stroke_bounding_box(options={},&block)
current_settings = {fill_color: fill_color,
stroke_color: stroke_color,
line_width: self.line_width }
fill_color options[:fill_color] || fill_color
stroke_color options[:stroke][:color] || stroke_color if options[:stroke]
self.line_width options[:stroke][:width] || self.line_width if options[:stroke]
rectangle options[:position], options[:width], options[:height]
options[:stroke] ? fill_and_stroke : fill
box_options = convert_box_options(options)
options[:revert_before_block] ? revert(current_settings) : check_fill_visiblity(options[:text_color])
fill_color options[:text_color] || fill_color
bounding_box(box_options[:position],box_options[:options]) do
if block_given?
block.call
end
end
revert(current_settings) unless options[:skip_revert]
end
def revert(settings={})
fill_color settings[:fill_color]
stroke_color settings[:stroke_color]
self.line_width settings[:line_width]
end
def convert_box_options(options={})
converted_options = {position: options.delete(:position)}
if options.delete(:stroke)
resize_box(options)
reposition_box(converted_options)
end
converted_options.merge({options: options})
end
def resize_box(options ={})
[:width,:height].each do |param|
options[param] -= (self.line_width * 2)
end
end
def reposition_box(options)
options[:position][0] += self.line_width
options[:position][1] -= self.line_width
end
def check_fill_visiblity(text_color)
text_color ||= fill_color
warn "[WARNING] Text Will Not be visible without text_color set or revert_before_block" if text_color == fill_color
end
end
end
Then you can call it like this
fill_and_stroke_bounding_box(position:[0,cursor],
stroke:{color: "7CFC00",width: 2.mm},
text_color: "668B8B"
fill_color:"FFFFFF",
width: 19.cm, height: 100
) do
The only options that are required are position,height, and width
(bounding_box does not require a height but since you are placing it inside a rectangle you must specify a height.
Although it is recommended the text_color or revert_before_block are also set otherwise the text inside the block will be invisible.
options includes all bounding_box options including use of a block as well as the following new options stroke:{:color,:width} which lets you set the outside stroke for the rectangle. fill_color: set the color of the rectangle. text_color the color of the text inside the block. revert_before_block will set the colors back before it executes the block because fill_color controls the text_color in Prawn. You can use this option in place of text_color if the correct color is already set.skip_revert this will discard the options of fill_color,stroke_color, and self.line_width that were set prior to calling this method. This extension will also warn if the text_color is the same as the fill_color.
Hope this helps someone out.
Here's how I did it.
bounding_box([0, y_position], width: 200, height: 50) do
fill_color 'CCCCCC'
fill { rectangle [0, 50], 200, 50 }
text 'Hello', align: :center, valign: :center
end
Just to add another option to Willing's answer...should somebody find this and want to use it with grid.
def widget
grid([2,2], [3,2]).bounding_box do
stroke do
fill_color '36DA5C'
fill_and_stroke_rounded_rectangle [cursor-bounds.height,cursor], bounds.width, bounds.height, 5
fill_color '000000'
end
text "This is text inside the box"
end
end

PdfSharp: Text height/positioning problem

Whether I use XTextFormatter or not, I get the same error about the LayoutRectangle having to have a height of 0 or something like this.
new PdfSharp.Drawing.Layout.XTextFormatter(_gfx).DrawString(text
, new PdfSharp.Drawing.XFont(fontName, fontSize, (PdfSharp.Drawing.XFontStyle)fontStyle)
, new PdfSharp.Drawing.XSolidBrush(PdfSharp.Drawing.XColor.FromArgb(foreColour))
, new PdfSharp.Drawing.XRect(new PdfSharp.Drawing.XPoint(xPos, yPos), new PdfSharp.Drawing.XPoint(xLimit, yLimit))
, PdfSharp.Drawing.XStringFormats.Default);
fontStyle is of type System.Drawing.FontStyle
foreColour is of type System.Drawing.Color
I have already predefined _gfx from a PdfPage with Orientation = Landscape, Size = Letter
xPos and yPos are parameters of type double, the same with xLimit and yLimit.
I get the runtime error that the
LayoutRectangle must have a height of
zero (0)...
Per definition a rectangle is meant to have a height, otherwise call it a line! I don't get it!...
I tried with the XGraphics.DrawString() method directly, and I get the same error. It seems that I can't use the LayoutRectangle but have to manage that the text fit within the desired area manually.
var textFont = new PdfSharp.Drawing.XFont(fontName, fontSize, (PdfSharp.Drawing.XFontStyle)fontStyle);
while (xPos + _gfx.MeasureString(text, textFont).Width > xLimit)
textFont = new PdfSharp.Drawing.XFont(fontName, --fontSize, (PdfSharp.Drawing.XFontStyle)fontStyle);
while (yPos + _gfx.MeasureString(text, textFont).Height > yLimit && fontSize > 0)
textFont = new PdfSharp.Drawing.XFont(fontName, --fontSize, (PdfSharp.Drawing.XFontStyle)fontStyle);
_gfx.DrawString(text
, textFont
, new PdfSharp.Drawing.XSolidBrush(PdfSharp.Drawing.XColor.FromArgb(foreColour))
, new PdfSharp.Drawing.XPoint(xPos, yPos));
Though the yPos variable value is the exact same value!
*yPos = Page.Height * .4093, either 40,93% of the page's height.*
Herewith an example of what I try to do:
"Hello World!" "Hello
World!"
And here is what I get:
"Hello World!"
"Hello World!"
And because of different printing area limits and size of the font and the different font style, I can't just write these into one simple sentence including the correct number of spaces.
Quoting error messages exactly helps others to help you.
The error message reads:
DrawString: With XLineAlignment.BaseLine the height of the layout rectangle must be 0.
The text will be aligned at a line, therefore height must be 0. Yes, that's a line.
Use a different alignment if you specify a rectangle.
The TextLayout sample shows how to format text.
The Graphics sample also shows how to layout text (single lines of text, no automatic line breaks; the technique shown in the TextLayout sample handles line breaks automatically using the XTextFormatter class).
While trying to figure out how text positioning works with PdfSharp, I noticed that the DrawString() method writes on top of the Y coordinate that we specify.
If I wish to write at (0, 100)(x, y), this points to the lower-left corner while I thought this was the top-left corner coordinates. As a result, the text string Y coordinate that I should have specified is 100 + string.Height * .6.
PdfDocument pdfDoc = new PdfDocument();
PdfPage pdfPage = new pdfPage();
pdfPage.Size = PageSize.Letter;
pdfPage.Orientation = Orientation.Landscape;
pdfDoc.Pages.Add(pdfPage);
double posX = 0;
double posY = pdfPage.Height * .4093;
string helloString = "Hello"
string worldString = "World!"
XFont helloFont = new XFont("Helvetica", 25, XFontStyle.Regular);
XFont worldFont = new XFont("Helvetica", 270, XFontStyle.Bold);
using(var pdfGfx = XGraphics.FromPdfPage(pdfPage)) { // assuming the default Point UOM
XSize helloStringSize = pdfGfx.MeasureString(helloString, helloFont);
XSize worldStringSize = pdfGfx.MeasureString(worldString, worldFont);
pdfGfx.DrawString(helloString
, helloFont
, XBrushes.Black
, posX
, posY + helloStringSize.Height * .6
, XStringFormats.Default);
pdfGfx.DrawString(worldString
, worldFont
, XBrushes.Black
, pdfPage.Width * .3978
, posY + (worldStringSize.Height + helloStringSize.Height) * .6
, XStringFormats.Default);
}
You'll perhaps wonder why I only add 60% of the string size when I want to get my string written below my Y coordinate? That is because the full height of the font includes somekind of leap on top. So, the computing result will not be what is expected. On the other hand, you don't have to care about a leap if you need one. In my particular case, I don't require leap, so I must take it off the string's height.
If you feel like my explanation needs more accurate details, please feel free to either add them as comments or keep me informed so that I may include them.
Thanks!