Because I'm loading my icons from a font, I cannot provide a url for a image property in stylesheets. I only have access to the QPixmap or QIcon. However I'm not sure what other kind of data the image property accepts besides url's. This is what I tried:
arrow_up_icon = FontIcon('arrow-up', color='white')
arrow_up_pixmap = arrow_up_icon.pixmap(QtCore.QSize(16, 16))
header = QtWigets.QHeaderView()
header.setStyleSheet("""
QHeaderView::up-arrow{
image: %s;
}
""" % arrow_up_pixmap)
Related
See here for Apple's Dynamic Type sizes.
I want to use dynamic font sizing, to make text in my app scale according to accessibility settings. However, the default pt sizes don't cover what I require.
Eg.:
Title 1 — 28pt
Title 2 — 22pt
I want to be able to use a 24pt font, with dynamic sizing. With the Large (default) setting, this is not possible... but if the user has the xLarge setting, Title 2 actually scales to 24pt...
As I am targeting iOS 15, I am using these modifiers on my Text so I can use a rounded font with dynamic sizing:
.font(.system(.title2, design: .rounded))
.fontWeight(.regular)
I've searched and searched, but none of the suggested answers work for me. I like the idea of being able to scale the existing dynamic type sizes by a multiplier but if I use .scaleEffect(value) it created pixellation when scaling up, and messes with padding even when scaling down.
You can create a font with a custom point size that scales with other dynamic fonts using:
Font.custom(_:size:relativeTo:)
e.g.
struct ContentView: View {
var body: some View {
VStack(alignment: .leading) {
Text("Title").font(.title).border(.green)
Text("Title").font(.title1½).border(.blue)
Text("Title").font(.title2).border(.red)
}
}
}
extension Font {
static let title1½ = Font.custom("", size: 24, relativeTo: .title2)
}
(leaving the name blank seems to return the system font)
You can adapt this to use rounded fonts in iOS 15. First you'll need to find the name of the font itself, using UIKit:
let font = UIFont.systemFont(ofSize: 24, weight: .regular)
let fontDescriptor = font.fontDescriptor.withDesign(.rounded)!
let roundedFont = UIFont(descriptor: fontDescriptor, size: 24)
print(roundedFont.fontName)
// .AppleSystemUIFontRounded-Regular
You can use this in your custom Font method:
extension Font {
static let title1Rounded = Font.custom(".AppleSystemUIFontRounded-Regular", size: 28, relativeTo: .title)
static let title1½Rounded = Font.custom(".AppleSystemUIFontRounded-Regular", size: 24, relativeTo: .title2)
static let title2Rounded = Font.custom(".AppleSystemUIFontRounded-Regular", size: 22, relativeTo: .title2)
}
I am experiencing some problem when inserting an html code containing images. The problem is that css information like width, height are ignored and the final pdf document always contains an image at 100% of its image size.
how can I solve this problem?
var file = _contentService.GetFile(imgPathPassport.ContentServerId).Base64Content;
var htmTxt = #"‹img src='data:image/png; base64," + file + "' style='width:30px; height:40px;'>";
builder.InsertHtml(htmTxt);
As I can see image dimensions specified in img element style attribute is applied properly by the latest Aspose.Words version. Here is a simple code I used for testing:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
string base64img = Convert.ToBase64String(File.ReadAllBytes(#"C:\Temp\test.png"));
builder.InsertHtml(string.Format("<img src=\"data:image/png; base64,{0}\" style=\"width:30px; height:40px;\" />", base64img));
doc.Save(#"C:\Temp\out.docx");
doc.Save(#"C:\Temp\out.pdf");
I need to get the width and height of a background image, I've seen examples where these can be easily retrieved ONLY IF the properties are set in CSS.
Is there anyway to get width and height when they are not set in the CSS either inline or in a CSS file?
This is all I have to work with...
element.style {
background-image: url(generated-by-cms.jpg);
}
Thanks!
I don't think you are able to get it via CSS if you didn't set the property up. As the image is being loaded externally, the CSS file has no clue about the size. Furthermore, if you are trying to set it up via background-image, the image will be restricted by the element size.
What you can do however is load the image via Javascript (since you already have the url anyway) and then set your element to the dimensions you want. For example, let's say your HTML file contains an img tag with the id "myimg"
<img id="myimg"></img> <!-- an empty image -->
You can then set up your Javascript like this:
var img = new Image(); // an empty image object
img.src = 'someurl'; // image url
// this is fired after 'someurl' is loaded.
img.onload = function() {
document.getElementById('myimg').src = img.src;
document.getElementById('myimg').width = img.width;
document.getElementById('myimg').height = img.height;
}
Note that you don't have to set the empty image or it's properties if you don't want to. You can manipulate img.width and img.height properties and use it elsewhere if needed.
I need to find a way to "upsample" text from 72dpi (screen) to 300dpi (print) for rendered client generated text. This is a true WYSIWYG application and we're expecting a ton of traffic so client side rendering is a requirement. Our application has several fonts, font sizes, colors, alignments the user can modify in a textarea. The question is how to convert 72dpi to 300dpi. We have the editior complete, we just need to make 300dpi versions of the textarea.
MY IDEA
1) Get textarea and increase the height, width, and font size by 300/72. (if ints are needed on font size I may need to increase the font then down-sample to the height/width)
2) use BitmapUtil.getSnapshot on the textarea to get a rendered version of the text
THE QUESTION
How can I render text inside of a textarea without the component lifecycle? Imagine:
var textArea:TextArea = new TextArea();
textArea.text = "This is a test";
var bmd:BitmapData = textArea.render();
Like Flextras said, width/height has nothing to do with DPI, unless you actually zoom into the application by 4.16X. If your application all has vector based graphics, it shouldn't be a problem. Plus, the concept of DPI is lost in any web application until you're trying to save/print a bitmap.
It's definitely possible, but you'll have to figure it on your own.
To ask a question another way, it is possible to create a TextArea in
memory which I can use the BitmapUtil.getSnapshot() function to
generate a BitmapData object
Technically, all components are in memory. What you want to do, I believe, is render a component without adding it to a container.
We do exactly this for the watermark on Flextras components. Conceptually we created a method to render the instance; like this:
public function render(argInheritingStyles : Object):void{
this.createChildren();
this.childrenCreated();
this.initializationComplete();
this.inheritingStyles = argInheritingStyles;
this.commitProperties();
this.measure();
this.height = this.measuredHeight;
this.width = this.measuredWidth;
this.updateDisplayList(this.unscaledWidth,this.unscaledHeight);
}
The method must be explicitly called. Then you can use the 'standard' procedure for turning the component into a bitmap. I think we use a Label; but the same approach should work on any given component.
Here is the final method I used to solve the problem of creating a printable version of the text and style of a Spark TextArea component. I ended up placing the custom component TextAreaRenderer (see below) in the MXML and setting the visibility to false. Then using the reference to this component to process any text field (renderObject) and get back a BitmapData object.
public class TextAreaRenderer extends TextArea implements IAssetRenderer
{
public function render(renderObject:Object, dpi:int = 300):BitmapData{
// CAST THE OBJECT
//.................
var userTextArea:TextArea = TextArea(renderObject);
// SCALE IS THE DIVISION OF THE NEW DPI OVER THE SCREEN DPI 72
//............................................................
var scale:Number = dpi / 72;
// COPY THE USER'S TEXT AREA INTO THE OFFSCREEN TEXT AREA
//.......................................................
this.text = userTextArea.text; // the actual text
this.height = Math.floor(userTextArea.height * scale); // scaled height
this.width = Math.floor(userTextArea.width * scale); // scaled width
// GET THE LAYOUT FORMATS AND COPY TO OFFSCREEN
// - the user's format = userTextAreaLayoutFormat
// - the hidden format = thisLayoutFormat
//...............................................
var editableLayoutProperties:Array = ['fontSize', 'fontFamily', 'fontWeight', 'fontStyle', 'textAlign', 'textDecoration', 'color']
userTextArea.selectAll();
var userTextAreaLayoutFormat:TextLayoutFormat = userTextArea.getFormatOfRange();
this.selectAll();
var thisLayoutFormat:TextLayoutFormat = this.getFormatOfRange();
for each(var prop:String in editableLayoutProperties){
thisLayoutFormat[prop] = userTextAreaLayoutFormat[prop];
}
// SCALE THE FONT SIZE
//....................
thisLayoutFormat.fontSize = thisLayoutFormat.fontSize * scale;
// SET THE FORMAT BACK IN THE TEXT BOX
//...................................
this.setFormatOfRange(thisLayoutFormat);
// REDRAW THE OFFSCREEN
// RETURN THE BITMAP DATA
//.......................
this.validateNow();
return BitmapUtil.getSnapshot(this);
}
}
Then calling the TextAreaRenderer after the text area is changed to get a scaled up bitmap.
// COPY THE DATA INTO THE OFFSCREEN COMPONENT
//............................................
var renderableComponent:IAssetRenderer = view.offScreenTextArea;
return renderableComponent.render(userTextArea, 300);
Thanks to the advice from www.Flextras.com for working through the issue with me.
I would like to display an Image using a Bitmap as source. I've been suggested something akin to this but somehow it still doesn't work.
img1 works fine... But img2 doesn't load for some reason.
private function onComplete(event:Event):void{
_bytes = event.target.data;
img1.source = _bytes; /*this last bit works*/
_bmpData = new BitmapData(img1.width,img1.height);
_bmpData.draw(img1,new Matrix());
_bmp = new Bitmap(_bmpData);
img2.source=_bmp;
}
img2.source=_bmp; doesn't work because you can't pass a Bitmap object to the source property of an Image control. From the documentation:
The value of the source property represents a relative or absolute URL; a ByteArray representing a SWF, GIF, JPEG, or PNG; an object that implements IFlexDisplayObject; a class whose type implements IFlexDisplayObject; or a String that represents a class.
A Bitmap is a DisplayObject, but it does not implement IFlexDisplayObject, so instead of using Image.source you can add the Bitmap as a child of the Image:
img2.addChild(_bmp);