PDFNet Resize annot Swift - ios

Have anyone worked using PDFNet where the annot needs to be resized?
For simplicity, currently i set the text of the annot using
annot.setContents(text)
annot.refreshAppearance()
pdfView.update()
However, if the text is too long where it exceeds the annot's width, it cant be resized and the text will be trimmed as the annot's width isnt wide enough. I checked the documentation and it seems there is a resize function, however the parameter it is taking isn't clear. Anyone with knowledge on this, thanks in advance

How are you creating the (free-text) annotations? If you are using a PTToolManager and creating the annotations with PTFreeTextCreate tool class, then you can enable auto-resize for free-text annotations with toolManager.isAutoResizeFreeTextEnabled = true
Using the PTDocumentController class for viewing and annotating documents is highly recommended if possible, otherwise a PTPDFViewCtrl and PTToolManager should be used.
The PTAnnot.resize() function is used to set the PDF page rect of the annotation, preserving (ie. scaling) the annotation's appearance to fill its new rect.
Auto-resizing a free-text annotation without a PTToolManager would require calculating (yourself) the size of the text. The PTToolManager API approach is recommended.

Related

Control image size with slider

I want to use a UISlider to control the size of an image. As you slide the slider one way the UIImage above should grow and as you slide the other way it should shrink. The ratio should stay the same. The math should be something like slider value = width, and height = (height/width ratio) * slider value. The way I think this could be done would be by making a variable and setting that variable to the image size and then making that variable = the slider value but I am not experienced with this sort of programming and do not know where to start. I found this question but I am not sure how to implement its code. Any point in the right direction, even just a conceptual explanation so I know how to write the code, is appreciated. NOTE- I did find this answer on changing the size, so now I just need to figure out how to link that to a slider.
EDIT- Now that the code is done and working, if anyone want s to see it in action my repo is here.
I know you specified UIImage in your question, but if you're trying to adjust the size of an image displayed on screen, you would do this by modifying the image view that contains the image. In this case you would want to modify the transform property of the image view.
Start by setting the sliders min value to 0.5 and max to 1.5, and linking its value changed control event to an IBAction set up to look something like this. It will expand and contract an image view from the image view's center.
- (IBAction)sliderValueChanged:(UISlider *)sender
{
[_myImageView setTransform:CGAffineTransformMakeScale(sender.value, sender.value)];
}
Additionally, the first post your linked to if for Microsoft WPF and the code couldn't be directly converted without knowing the both relevant API's. Then the second link you provided does show how to directly change the resolution of a UIImage.
You could do something similar to what I've done above with the image view, as in reading the sliders value and formulaically setting the image's size, but I don't recommend that. The slider value changed method will be called very frequently, and may cause performance issues doing this. If you provide more details on what you're trying to do, I may be able to offer different suggestions.

setting extent using setExtent in blackberry

I want to make use of the setExtent() method in blackberry.
Every time i use setExtent(), it allocates the space from the zero, zero coordinate to any custom field that i paint by extending the Field class.
I want when I draw any custom field from (100,100), then it should allocate space from (100,100) and not from (0,0).
my code looks like:
protected void layout(int width,int height)
{
setExtent(100,100);
}
Please help me out with any solutions.
What you appear to be trying to do actually doesn't sound like a very good idea. 100 pixels is a useful measure on one device, but 100 pixels on a 9300 is over 1/3 of the height of the screen, but on a 9800 is no where near that. I would strongly recommend that you do not use fixed pixel sizes for any Blackberry development.
That said, if you want to Field to start at position 100,100, you should use setPositionChild for that Field in the Field's Manager.
Before you start leaping off attempting this, I would recommend that you review the following:
http://supportforums.blackberry.com/t5/Java-Development/How-to-Extend-Manager/ta-p/446749
and
http://supportforums.blackberry.com/t5/Java-Development/Create-a-custom-layout-manager-for-a-screen/ta-p/442990
But perhaps the best options might be to explain what you are trying to achieve and we might be able to suggest an alternative.

how to specify image dimension/size when doing a drawAtPoint?

I have some images and I want to draw them using drawAtPoint ( I am using a table of 100s of cells and doing the draw as recommended for making the scrolling faster). Now, these images are kind of random (their size can be anything.. ) and I need to specify the dimension I want to fit in.
Can anyone kindly tell me what to do ?
Thanks.
Assuming I understand what you want to do use:
- (void)drawInRect:(CGRect)rect;
See http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImage_Class/Reference/Reference.html
When using drawAtPoint you cannot specify the dimensions, it will draw the entire image in the current graphics context.

jquery Image slider without define width?

I have used the coin slider.But the coin slider is restricted by the width.I need to run my application in various screen size like 1280*768,800*600.is there any image slider in jquery without restrict width of image?Please help me.
Thanks in advance.
Most image sliders are designed for being placed within a container of a certain width, so that they fit within a specific slot in a layout. Given that the size of the screen/window(you don't specify) is irrelevant to that, it seems like what you're looking for is a gallery that adapts to the size of the entire window, rather than fit within a specific size.
You should probably widen your search to JS galleries in general, which might have that option or even function that way in the first place. As initial suggestions, have a look at the full-screen example for Galleria, or maybe the Supersized plugin

iOS: How do you measure the width and height of a string using Quartz?

Before I ask my questions, this is from Apple's documentation re: how to determine the width of a string using Quartz:
If text measurements are important to your application, it is possible
to calculate them using Quartz 2D functions. However, you might first
consider using ATSUI, whose strength is in text layout and
measurement. ATSUI has several functions that obtain text metrics. Not
only can you obtain after-layout text metrics, but in the rare cases
you need them, you can obtain before-layout text metrics. Unlike
Quartz, for which you must perform the calculations yourself, ATSUI
computes the measurements for you. For example, you can obtain the
image bounding rectangle for text by calling the ATSUI function
ATSUMeasureTextImage.
If you decide that Quartz text suits your needs better than ATSUI (or
Cocoa), you can follow these steps to measure the width of text before
Quartz draws it:
Call the function CGContextGetTextPosition to obtain the current text position.
Set the text drawing mode to kCGTextInvisible using the function CGContextSetTextDrawingMode.
Draw the text by calling the function CGContextShowText to draw the text at the current text position.
Determine the final text position by calling the function CGContextGetTextPosition.
Subtract the starting position from the ending position to determine the width of the text.
Here are my questions:
Is this really the best way to determine the width of a string using Core Graphics? It seems flimsy and since my text co-exists with 2D graphical elements, I'd like to use the same context for all rendering. I was hoping there would be some compact method, like:
CGContextGetTextWidthAndHeight(context, text);
I read that ATSUI is outdated and going to be replaced by Core Text. Is that true and if so, is it in iOS?
On the iPhone SDK, there's a family of methods on NSString that provide what you want.
As of iOS 7.0, these methods are:
- boundingRectWithSize:options:attributes:context:
- sizeWithAttributes:
On older versions of iOS we had these, now deprecated:
– sizeWithFont:
– sizeWithFont:forWidth:lineBreakMode:
– sizeWithFont:constrainedToSize:
– sizeWithFont:constrainedToSize:lineBreakMode:
– sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:
When performing drawing operations on threads other than the UI thread, you must use the technique you described. This is especially important to note when using things like CATiledLayer, which performs it's rendering asynchronously on background threads, or when drawing custom graphics in the background for any other reason.
I agree with PGB when you're doing "simple" graphics and you are guaranteed to be running on the main thread. However, sizeWithFont is doing the same thing as the technique you described - it's simply doing it for you using UIGraphicsGetCurrentContext().

Resources