Using BitmapForCaching for calculating TextArea.FontSize

I have perused many posts and I cannot find the algorithm for using BitmapForCaching for calculating TextArea.FontSize.
I am trusting AutoComplete to guide me and it isn’t showing up.
I am not sure whether to use Graphics or Picture to get the AutoComplete.
I am sure that if I define Picture before using BitmapForCaching that the Analyzer fails the BitmapForCaching definition.
I also am not sure if I need to reference the original container in the TrueWindow.BitmapForCaching definition
It seems to work without it.

The only terms I am using are:
tCont is for the container
eWidth is the width of the container
eHeigth is the heigth of the container

Please offer your solutions

This is why you have so much trouble understanding what friends here try to explain. Start with the documentation folder next to your Xojo install. Then, when implementing your apps start at for information about the classes you’re using. if you “just want this done yesterday”

If you want to learn yourself, you definitely need to start with the documentation folder. There’s also the programming textbook which can get you up and started if you’re having trouble understanding some of the basics. Xojo: Learn Xojo Programming

I forgot to mention one important thing in my initial statement. I am passing the container to a method, which is also a method in App.

The BitmapForCaching document has an extends, which tell me it is a method and for special purposes. There is no other code anywhere in the LR or in the docs including the Blog.

It does include in the definition of the method graphics and picture, but again this is a method, and not straight code already in a method.

Every other place I look, there is contradictory ordering of code.

Also in your statement yesterday BitmapForCaching you use self

dim tpicWindowRep as Picture = self.BitmapForCaching

I don’t have a self, because I am passing only the control, and not the window.
doesn’t work.

I have tried that and it doesn’t work by AutoComplete. I say it that way because BitmapForCaching has been around for a long time and any bugs should be worked out.

My code for using TrueWindow is

Var myW As TrueWindow = tCont.TrueWindow.BitmapForCaching( eWidth, eHeight )

The definition using Picture is so far this.

Var picText2 as Picture = and anything beyond, I’m not certain of.

Me vs. Self
Xojo Documentation
Please, make a deep dive in the documentation.
Feel free to refer to this forum when something isn’t clear.

Yes. I am quite familiar with those terms. In order to use extends, one first needs a method. I don’t have a method yet from the LR

I might have found out the algorithm. Yes it is an algorithm because if you put things in the wrong then other things don’t work.
I also haven’t tested this. I also have another question at the end.

From BitmapForCaching

but there is no code separate from the shown method.
I am including this to let the reader know I have read the LR and there is no algorithm.

or 51496-temporarily-installed-fonts-don-t-work-in-xojo-s-gdi-text-rende

[quote=417287:@Carlo Rubini]In a canvas I put the following code, but no text is shown.
Replacing self.BitmapForCaching with new Picture too shows no text, but the app does not crash.

Dim p As Picture = self.BitmapForCaching(g.Width, g.Height)
g.drawpicture p,0,0
p.Graphics.TextSize = 18
p.Graphics.TextFont = mFont//a temporally installed font
p.Graphics.ForeColor = &c000000
p.Graphics.bold = true
p.Graphics.DrawString “???” + EndOfLine + “???” + EndOfLine + “???”,0,0[/quote]

As I’ve already explained Self isn’t applicable.
Using the above code

Dim p As Picture = tCont.

doesn’t quite work because BitmapForCaching cannot follow it.
It has to be TrueWindow.BitmapForCaching

This is my previous basic code.

My Method Name with Parameters SetFontSize (tCont As TextArea)

Dim eHeight As Integer = tCont.Height Dim eWidth As Integer = tCont.Width dim picText2 as new Picture(eHeight, eWidth, 32) dim fSize, vL, vR, mvL, mvR As Integer //The fontsize that is larger than SizeOfFontMin //vL and vR are identifying areas in SelText. mvL and mvR are for identifying for Mid removal //vL is start StyledText, vR is end of StyledText dim g As Graphics = picText2.Graphics fSize = SizeOfFontMax//defined elsewhere g.TextFont = DispFont//defined elsewhere g.TextSize = fSize vR = g.StringHeight(stkOfStrgs(0), eWidth) While vR > eHeight And fSize > SizeOfFontMin // Sets the area for ALL text size so everything will fit in the TextArea provided it is larger SizeOfFontMin fSize = fSize -1 g.TextSize = fSize vR = g.StringHeight(stkOfStrgs(0), eWidth-15) If fSize = SizeOfFontMin Then Exit While Wend tCont.TextSize = fSize Return

When I posted my first part here I knew that if I put this in first other things wouldn’t work.

Var myW As TrueWindow = tCont.TrueWindow.BitmapForCaching( eWidth, eHeight )

I also knew if I defined Picture above this, then nothing apparently with BitmapForCaching works.

The code the analyzer likes is replacing my picture definition with

Var picText2 as Picture = tCont.TrueWindow.BitmapForCaching( eWidth, eHeight )//32 is Depth or bits

Unfortunately, depth is missing from the pitcure definition and if I just put a comma and 32 it doesn’t like it.

Var picText2 as Picture = tCont.TrueWindow.BitmapForCaching( eWidth, eHeight ) , 32

BTW Picture has no mention of BitmapForCaching

So my question is now how do I get a constructor for Picture with BitmapForCaching and depth.

Sorry that I neglected to add my method was a shared method in App

What Xojo version are you using?

I am using current on everything.

I am one of the persons you hand things for “Idiot Proof” testing, or “If it ain’t obvious, I can miss it”. I will find the user interface problems that haven’t been proofed.
What I didn’t notice about the IDE inspector is the control for naming a method is actually a ComboBox dropdown and one of the entries is BitmapForCaching. There are also things like ShowModal, TrueWindow, Close, Control(Index as Integer) and I don’t know how to use any of them as methods for a window. I do understand Constructor and Destructor.
I also downloaded a 2014 XOJO and found a few good instruction pdf’s in the Doc section. I don’t know if this topic will be there, but it should be good reading.

By the way. “Idiot Proof” really is an industry standard term. It’s just undocumented.

Hi Arthur,

I don’t know what you are talking about.
I can assure you that the following line

is syntactically incorrect and the line

is right.

So the problem is what are you asking for and what are you lamenting about here:

[quote=487919:@Arthur Gabhart]Unfortunately, depth is missing from the pitcure definition and if I just put a comma and 32 it doesn’t like it.

Please note that computer programming is one of the most abstract thing produced by human beings in the last century.
So abstract and full of, apparently, small and insignificant details that a little change in most cases produces totally different and unexpected results.

This forum is not meant to win a prize or to demonstrates to have and higher or lower Intellectual quotient.
Is simply used to share knowledge.
A lack of knowledge is not seen as something to be guilty about: is simply something that is unknown.
I’m not feeling and idiot for all things that I don’t know.

Remember that ignorance is not a fault and can be avoided with knowledge.
Stupidity has no cure.

So please, be civil and possibly don’t use terms totally unrelated to computer programming.

Best regards.

I’m jumping into the middle of this, so forgive me if I’m repeating stuff that has already been said. I do want to point out that TrueWindow is not a class, so this var statement is incorrect. TrueWindow is a property of a RectControl and a ContainerControl that holds a reference to the window that the control is in. It removes the necessity for iterating through Window references which may be ContainerControls to finally get to the actual window itself.

This should be correct. BitmapForCaching returns a Picture object. It does not care about bit depth, so ,32 is not required.

And by the way, what was wrong with your original code? Again, I’m jumping into the middle here.