Font Anti-Aliasing on iPad SDK - antialiasing

I'm using a custom pixel font on the iPad SDK, and I'm trying to find a way to disable font anti-aliasing for UIFont. Pixel fonts usually work best when they don't have Anti-aliasing. I disable it easily in Photoshop when I create static resources, but this time I need a dynamic output with the custom font.
Any ideas if this is even possible?
Thanks.

Something like this might work if you are subclassing a UILabel or similar:
-(void) drawRect:(CGRect)r {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState( context );
CGContextSetShouldSmoothFonts( context , false );
[super drawRect:r];
CGContextRestoreGState( context );
}
If that does not work you can try these calls too:
CGContextSetAllowsAntialiasing( context , false );
CGContextSetShouldAntialias( context , false );

Related

Phaser3 transparent snapshot

I need to create transparent snapshot of game (png24)
Here is an example of snapshot labs.phaser.io from Phaser3 official examples page, but it is not transparent.
setting game background to transparent with rgba backgroundColor - works
const config = {
...
transparent: true,
backgroundColor: 'rgba(255,110,110,0)',
...
};
const game = new Phaser.Game(config);
If you set transparent in the Game Config but didn't provide a backgroundColor then it would render as black. If you do provide a color value then it must include an alpha component.

JavaFX TextArea Hiding Scroll Bars

I have a TextArea() and would like to hide the vertical/horizontal scroll bars. I see that the control seems to have a built in scroll-pane that shows as needed.
TextArea numberPane = new TextArea();
numberPane.setEditable(false);
numberPane.setMaxWidth( 75 );
// Set the characteristics of our line number pane
numberPane.setId( "line-number-pane" );
In my CSS file I have the follow settings.
#line-number-pane
{
-fx-text-fill: white;
-fx-background-color: black;
-fx-font: 12px "Courier New";
-fx-font-family: "Courier New";
-fx-font-weight: bold;
}
#line-number-pane .scroll-pane
{
-fx-hbar-policy : never;
-fx-vbar-policy : never;
}
As expected the text area font/color/size works just fine. However, the scroll-pane policy doesn't seem to work.
Should I be able to hide the scroll bars via the CSS file or is there some code that will do the trick.
Thanks.
From How can I hide the scroll bar in TextArea?:
Remove Horizontal Scrollbar
textArea.setWrapText(true);
Remove Vertical Scrollbar
ScrollBar scrollBarv = (ScrollBar)ta.lookup(".scroll-bar:vertical");
scrollBarv.setDisable(true);
CSS
.text-area .scroll-bar:vertical:disabled {
-fx-opacity: 0;
}
I just did it very simply using a StyleSheet:
CSS
.text-area .scroll-bar:vertical {
-fx-pref-width: 1;
-fx-opacity: 0;
}
.text-area .scroll-bar:horizontal {
-fx-pref-height: 1;
-fx-opacity: 0;
}
No need for all that whacky code.
I observed code of TextAreaSkin class, and found, that a
void layoutChildren(x, y, w, h) method, which is called "during the layout pass of the scenegraph" and de facto, each time, when something happens with a control, contains a code, which changes hbarPolicy and vbarPolicy between AS_NEEDED and NEVER, according to the current state of control.
So, looks like, there is no chance to do somethign with it, using a css.
Try to just make scrollbars invisible. But, as I see code of ScrollPaneSkin, scrollBars are created once, but their visibility state seems to change during the control is working, so, instead of using setVisible(false) (which will be ignored in the nearest layout), try to use a setOpacity(0.0). (I'm not sure, it will work, but it worth to try).
Also, instead of CSS using, you can apply a recursive search of scrollBars in a control structure, using a Parent.getChildrenUnmodifiable() method, and make them invisible manually.

Dojo dijit layout ContentPane with splitter - programmatically change region orientation

I'm using two panes (grid and details) as master-details pattern.
Now I'm trying to create "Details on the right" or "Details on the bottom" toggle button. I do this by changing the region attribut of the ContentPane, like so:
function toggleDetails() {
if(dijit.byId("Details").region == "right") {
dijit.byId("Details").set("region", "bottom");
dojo.byId("Details").style.height = "200px";
}
else {
dijit.byId("Details").set("region", "right");
dojo.byId("Details").style.width = "400px";
}
dijit.byId("DetailsParent").resize();
}
The panes themselves are changing fine. The problem is that I have a splitter for the details pane. When toggling, the splitter is ok for the original orientation, but doesn't render correctly for the alternate orientation. Any solution to refresh the splitter orientation based on the contentPane region?
I have tried programmatically changing some of splitter widget attributes, like "horizontal" and "region", but nothing really fixed the alternate orientation.
A possible solution could be by using removeChild and addChild like in this example
if (isVertical) {
// vertical layout
this.ap_MainContainer.removeChild(this.ap_TopContainer);
this.ap_TopContainer.region = 'top';
this.ap_MainContainer.addChild(this.ap_TopContainer);
} else {
// horizontal layout
this.ap_MainContainer.removeChild(this.ap_TopContainer);
this.ap_TopContainer.region = 'left';
this.ap_MainContainer.addChild(this.ap_TopContainer);
}

How to disable zoom glass/lens from UIWebView?

I have disable default call out action sheet from UIWebView by using this -
[webView stringByEvaluatingJavaScriptFromString:#"document.body.style.webkitTouchCallout='none';"];
it's working fine but the main problem is that when i tap on an image for a long time a zoom lens of UIWebView comes there and i want to disable it, is it possible? then how?
Yes a few ways but some of which are buggy.
If you don't care about userinteraction at all you can just disabled it. Then they will only be able to zoom and move around the page (but not click any links or anything).
-(void)removeInput{
UIScrollView *webViewContentView;
for (UIView *checkView in [webView subviews] ) {
if ([checkView isKindOfClass:[UIScrollView class]]) {
webViewContentView = (UIScrollView*)checkView;
break;
}
}
for (UIView *checkView in [webViewContentView subviews] ) {
checkView.userInteractionEnabled = NO;
}
}
UIWebView without Copy/Paste and selection rectangle when showing documents
However that causes all userInteraction to be disabled which might not be what you want?
To JUST disable the magnifying glass I don't think is possible (though I might be wrong?).
Ok if you don't mind disabling the text selection as well you can try this.
ObjC
[webView stringByEvaluatingJavaScriptFromString:#"document.onmousedown = function() {return false;}"];
JavaScript
document.onselectstart = function() {return false;} // ie
document.onmousedown = function() {return false;}
Source:
http://javascript.internet.com/page-details/disable-text-selection.html

iPad - find the true height of a UIWebView

I work for a media company, and in our iPad application we're upgrading our content so it looks better. Previously, we used a UILabel to display the contents of our posts. I used this to get the actual height of my UILabel:
CGSize expectedSize = [label.text sizeWithFont:label.font
constrainedToSize:maximumLabelSize lineBreakMode:label.lineBreakMode];
However, we changed our posts' content to HTML, so I'm using a UIWebView. Is there a way to find the true height of the UIWebView, like I do with the UILabel?
Unlike with a plain string, you'll probably only be able to get the height once the web view finishes rendering. Here's how you can do it in a web view delegate method:
- (void)webViewDidFinishLoad:(UIWebView *)webview
{
NSString *heightString = [webview stringByEvaluatingJavaScriptFromString:
#"document.body.clientHeight"];
int height = [heightString intValue];
...
}

Resources