AppleScript - what are bounds? - macos

I am AppleScripting Adobe Illustrator CS3. Here is (part of) my code:
tell application "Adobe Illustrator"
tell newDocument
make new rectangle with properties {bounds:{200.0, 400.0, 300.0, 200.0}}
end tell
end tell
I copied the make new rectangle part from page 153 of this, from Adobe's website.
But what are the bounds??? When I run the script, they don't match up with the co-ordinates of the rectangle:
How do I convert from co-ordinates to bounds? My canvas size is 1920 by 1080.

Well, as it says in the reference on p.153, the bounds are as follows:
left-most horizontal
top vertical
right-most horizontal
bottom vertical
bound of the rectangle, measured from the bottom left corner (0, 0). The X and Y coordinates you see will be the coordinates of the rectangle's center point. However, the width and height in your screenshot are strange: when running your code (with bounds:{200, 400, 300, 200}), I obtained a rectangle having its center at X=250, Y=300, and dimensions of W=100, H=200, as expected.

Related

How do I create two new Safari windows in different positions?

I'm trying to write a script which opens two Safari windows with different bounds, at different positions on the desktop, like so:
The {pixels wide, pixels high} labels are more accurate than the actual proportions of the boxes. The problem I'm having is that I can set the bounds of the window on the left exactly how I want - as it's the first one the script generates - but when I try to specify the bounds of the second window on the right, its position is tied to the position of the first window, and it's either constrained within the bounds of the first window or - if I tell it to "spawn" outside the bounds of the first window - doesn't appear at all.
# Desktop: {1280, 800}
tell application "Safari"
activate
make new document with properties {URL:"https://www.google.com"}
set bounds of front window to {25, 25, 550, 750}
make new document with properties {URL:"https://www.google.com"}
set bounds of front window to {25, 25, 700, 750}
end tell
As you'll see, the script currently creates both windows at the same {25, 25} co-ordinate for now as this is the closest functional version I have to what I want.
How can I set the bounds of the second, right-hand window to appear as shown in the image regardless of the bounds of the first window on the left?
The value of the bounds property is returned as a four item list of integers representing the bounding area of the window on the screen:
List item 1: {x1, y1, x2, y2}
The distance in pixels from the left side of the screen to the left side of the window.
List item 2: {x1, y1, x2, y2}
The distance in pixels from the top of the screen to the top of the window.
List item 3: {x1, y1, x2, y2}
The distance in pixels from the left side of the screen to the right side of the window.
List item 4: {x1, y1, x2, y2}
The distance in pixels from the top of the screen to the bottom of the window.
The bounds for the first window with a width of 550 and height of 750 with a 25 pixel offset would be:
{25, 25, 575, 775}
The bounds for the second window with a width of 700 and height of 750 and no space between it and the first window would be:
{575, 25, 1275, 775}
This will give you the two windows of the sizes show in your diagram, however the spacing is not exactly as shown.
tell application "Safari"
activate
make new document with properties {URL:"https://www.google.com"}
set bounds of front window to {25, 25, 575, 775}
make new document with properties {URL:"https://www.google.com"}
set bounds of front window to {575, 25, 1275, 775}
end tell

texture not applied properly with Three.js

I work with Forge Autodesk, and I want to apply a texture to some rectangle object. In fact I just needed some plan, but I was given a rectangle. So I want to apply my image on the main face of the rectangle.
const mytex = THREE.ImageUtils.loadTexture(mytexture)
// Repeat image through object
mytex.wrapS = THREE.RepeatWrapping //ClampToEdgeWrapping //MirroredRepeatWrapping //RepeatWrapping
mytex.wrapT = THREE.RepeatWrapping //ClampToEdgeWrapping //MirroredRepeatWrapping //RepeatWrapping
mytex.mapping = THREE.UVMapping
mytex.repeat.set (0.05, 0.05)
console.log("applied texture")
But I get this problem : a part of my image appears on the right upper side (upper and right corners are cut, so not on the rectangle), but the left and bottom sides are stretched across the rest of the rectangle face.
I would like to adapt my image so that its dimension fit the rectangle's dimensions, and not just repeat it.
I read this and this. I think my code is correctly written, but I may be missing a parameter or set the wrong one... The 2 images I am testing are 676x676 and 1024x484 pixels. I cannot access the rectangle dimensions from my function (I don't think so).
I tried to just repeat the image too but it does not work either...
Any idea ?

Image with absolute position to position in pdf itext

So I have an image and I set its position absolute (jsf). Then the user can change the position with the drag/drop functions from primefaces. The new coordinates (left/top) are then stored in the mysql database. When the page is reloaded, the image is again absolutely positioned with the coordinates from the db.
For example the image coordinates are (the page is scrollable): left:68px; top: 826.5px
--> In java I use itext and I want to place the image with the absolute values ​​from the database. I know that the 0/0 coordinates of the PDF document are bottom left.
I want to use image.setAbsolutePosition() but how does the coordinates match???
They right coordinates for the pdf would be: x about 135 and y about 700 but how this fit together with the coordinates on the screen 68px/826.5px? I have already calculate around a lot but do not understand it...
I also scale the images: the original with/height on screen: 35x35
and I use: image.scaleAbsolute(25, 25);
So how does this work? thx :)
If you have an image whose top left corner is at {x,y} in a top-left coordinate system and you want to place it in a coordinate system that uses bottom-left for the origin and bottom-left for placement then you need to know both the height of the image and the height of the document. The {x} won't change but the new {y} should be Document.Height - {original y} - Image.Height}.
The image below shows an image that's at {50,50} in a top-left system. Once we add it to a document we need to know the document's height (800px) so that we can map. We also need to know the image's height (75px).

libgdx: Rotate a texture when drawing it with spritebatch

Im trying to rotate textures when I draw them. I figured it would make more sense to do this than to rotate the images 90 degrees in paint.net and save them in different files. I looked thought the api documentation for spritebatch drawing arguments but I just dont understand. There are a bunch of arguments such as srcX, srcY, originX and so on. Also i would like to know how to do the same for texture regions. Heres a link to the api documentation page:http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/SpriteBatch.html
Thank you!
again from the documentation, but copied here for ease of use and so I can explain a little better.
x - the x-coordinate in screen space
y - the y-coordinate in screen space
these two values represent the location to draw your texture in screen space (game space). Pretty self explanatory.
originX - the x-coordinate of the scaling and rotation origin relative to the screen space coordinates
originY - the y-coordinate of the scaling and rotation origin relative to the screen space coordinates
these two values represent the location where rotations (and scaling) happen from with respect to the screen space. So for instance, if you give the value 0, 0 here, the rotation and scaling will happen around one of the corners of your texture (the bottom left I believe), whereas if you give the center (width/2, height/2), the rotation and scaling would happen around the center of your texture (this is probably what you want for any "normal" rotations)
width - the width in pixels
height - the height in pixels
the dimensions for drawing your texture on screen.
scaleX - the scale of the rectangle around originX/originY in x
scaleY - the scale of the rectangle around originX/originY in y
values representing the scale of your rectangle, where values between 0 and 1 will shrink the rectangle, and values greater than 1 will expand the rectangle. Note that this is with respect to the origin you gave earlier, which means that if this is not the center the image may look distorted.
rotation - the angle of counter clockwise rotation of the rectangle around originX/originY
the angle to rotate the image by. Again, this is around the origin given earlier, so the rotation may not appear "correct" if the origin is not the center of the image
srcX - the x-coordinate in texel space
srcY - the y-coordinate in texel space
these two values are the starting location of the actual region of the image file (.png, .jpg, whatever) that you wish to use, in pixels. Basically the start of your image.
srcWidth - the source with in texels
srcHeight - the source height in texels
similarly, these two values are the width and height of the actual region of the image file you are using, in pixels.
flipX - whether to flip the sprite horizontally
flipY - whether to flip the sprite vertically
Finally, these two booleans are used to flip the image either horizontally or vertically.
Now you may notice that the similar method for drawing TextureRegions has no srcX, srcY, srcWidth, or srcHeight. This is because those are the values you give to a texture region when you create it from a texture.
Essentially what that means is that the command
//with TextureRegions
SpriteBatch.draw(textureRegion, x, y, originX, originY, width, height, scaleX, scaleY, rotation);
is equivalent to
//with Textures from TextureRegions
SpriteBatch.draw(textureRegion.getTexture(), x, y, originX, originY, width, height, scaleX, scaleY, rotation, textureRegion.getRegionX(), textureRegion.getRegionY(), textureRegion.getRegionWidth(), textureRegion.getRegionHeight(), false, false);

Pixels in Direct2D

The dark gray lines are supposed to be black and 1 pixel wide:
pRT->DrawLine(Point2F(100, 120), Point2F(300, 120), blackbrush, 1);
The light gray lines are supposed to be black and 0.5 pixel wide:
pRT->DrawLine(Point2F(120, 130), Point2F(280, 130), blackbrush, 0.5);
Instead, they are both 2 pixels wide. If I ask for 2 pixels wide, the line is black, but naturally 2 pixels wide.
The render target has the same size as the client area of the window. I would like pixel accuracy like in GDI, one coordinate = one pixel and pure colors...
Thanks.
Direct2D is rendering correctly. When you give it a pixel coordinate such as (100, 120), that refers to the top and left corner of the pixel element that spans from pixel coordinates (100, 120) to (101, 121) (top/left are inclusive, right/bottom are exclusive). Since it's a straight horizontal line you are effectively getting a filled rectangle from (99.5, 119.5) - (300.5, 120.5). Since the edges of this spill into adjacent pixels, that's why you're getting "2 pixel width" lines at the "wrong" brightness. You must think in terms of pixel coordinates (points with no area) and pixel elements (physical points on the screen with an area of 1x1, or just 1 of course).
If you want to draw a straight line from that covers the pixels (100, 120) to (300, 120), you should either use SemMike's suggestion of using aliased rendering (which is great for straight lines!), or you can use half-pixel offsets (because strokeWidth=1; for other strokeWidths, adjust by strokeWidth/2). Drawing from (100.5, 120.5) - (299.5, 120.5) with a stroke width of 1.0 will get you what you're looking for. That stroke extends around the pixel coordinates you specify, so you will get the "filled rectangle" over the pixel elements (100, 120) - (300, 121). And again, that's an exclusive range, so 'y=121' isn't actually filled, neither is x=300.
If you're wondering why this doesn't happen with something like GDI, it's because it doesn't do antialiased rendering, so everything always snaps to pixel elements. If you're wondering why this doesn't happen with WPF while using Shapes, it's because it uses layout rounding (UseLayoutRounding) and pixel snapping. Direct2D does not provide those services because it's a relatively low-level API.
You can play around with pRenderTarget->DrawLine(Point2F(100-0.5, 120-0.5), Point2F(300-0.5, 120-0.5), blackbrush, 1), but it becomes rapidly tricky. The simplest is:
pRenderTarget->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
Hope it helps somebody...

Resources