how can I fix font size to image?

Cecilia Lucía Gigena shared this question 6 months ago
Answered

Hi,

I have created this rectangle, and I want font size to change in order to always fit to the rectangle.

Rectangle size is always the same, but...

1) when I zoom out, rectangle is shown smaller, but the text remains big, so now it's too big for the rectangle

2) when I zoom in, for the same reason, text turns out to be too small

3) as I click on the buttons and number value changes, either because the number becomes negative or the number has more than one digit, it eventually becomes too big for the rectangle.


I put a box with a percentage, in case I want to adjust size manually, but I didn't get how to make font size "read" this box.

Can anybody help with this? Thanks in advance

Comments (21)

photo
1

You can do it like this: https://www.geogebra.org/m/RvCFzYvu

photo
1

That's interesting.

I'm trying to find more instructions about \scalebox but I'm still confused. Can you provide the URL to this topic in the manual? I haven't found it yet.

I need to use 2 data:

1) the position where the text should be - a point named "E"

2) the text itself - the value of variable named "e"


I tried typing FORMULATEXT() but I don't get where to specify Point.

photo
2

\scalebox{} is a LaTeX command. See e.g. here https://latexref.xyz/_005cs...

photo
1

Thanks for the help so far. I'm trying to put all this together and I'm still confused.

I have tried this:

FórmulaTexto("\scalebox{4}{e}", true)


But it still writes the letter "e" instead of searching for e value (which is now 0).

I also need to make these changes:

•to assign position to point E. I tried this:

FórmulaTexto("\scalebox{4}{e}", E, true, true)

and it writes no text at all.

•To replace scale = 4 for scale = s (my new slider).

And then: Adjust variable "s" to zoom (no idea how to do that).

photo
1

FórmulaTexto("\scalebox{4}{"+e+"}", true)

photo
1

Thanks Michael. Now it is showing e value and I have also assigned the "s" variable to specify scale:

FórmulaTexto("\scalebox{" s "}{" + e + "}", true)

(I have a slider for s)

But I still didn't get how to make it be positioned in point E.

photo
1

I have found how to position in point E! But... still didn't get how to make s be related to zoom.

photo
1

Hi, I kept trying and I got better with this file. But it has 2 bugs:


-When I zoom in or out, it does not remain within the rectangle

-When value has more or less characters (like a negative sign or more digits), it does not remain centered.

So I want to change this:

-The text should ALWAYS remain within the rectangle (if necessary, reduce font size in order to fit).

-I want the text to be centered (with respect to point E).

Can anybody help me with these changes?

photo
photo
2

Mike, esto te va a encantar

https://www.geogebra.org/m/nraudgpw

photo
1

based on mathmagic's solution a slightly modified version (and adapted to your requirements).

If this still confuses you (which is very likely): ask good, specific questions (please not: how does it all work)

photo
1

Thank you.


I can see yours works! - But I'm trying to put this code into a more updated file of mine.

Here's my new try. I have modified the text using this code:

Texto("\scalebox{" + s + "} {" + e + "}", E + (4X, 3X), true, true, 0, 0)

For this purpose I created a new variable named X. I can see slider X works as a linear function.


And I have also copied your "trigger" code and I have named it Y:

Y=abs(Distancia(A, D) - Distancia(Esquina(texto1, 1), Esquina(texto1, 2)))

But I still didn't get how to connect Y with the text. Right now, my text changes when I use sliders X and s (with the label "escala"), but number Y does nothing.

I am exploring your file but I couldn't find where this number Y gets called.

photo
1

Hm.. this was a blind copy?

Check

  • s AND ss (In difference to the solution of mathmagic this solution has no circular relation)
  • texto1 and texto2 (both are strongly modified)
  • check script in Y
  • script in zoom-buttons +/-

Note: s is always = 1, it is needed for the Minimize() command in script Y

Note: X is dependent on current zoom (how long (in ggb-units) is 1 ggb-pixel on screen)

Note: mix different solutions only if you really understand them.

Note: Integral (for areas) need a lot CPU-performace

photo
1

Hi rami,


This is the new file I'm trying to create. I want text to be adjusted from point A to point B, and these points remain in the same position regardless of zoom. I am using your file as a guide, but I still don't get what I am doing different.


Thanks for your help.

I also provide a dropbox link in case you cannot open attachment:

https://www.dropbox.com/sh/...

photo
1

Hi,

I kept trying and I made some progress. Here is my new file.

I would like to fix 2 things:•I am adjusting text to point C, which is midpoint between A and B, but it's still not centered (too close to A, too far from B)

• ss cannot exceed 5 (I want it to be "infinite")

https://www.dropbox.com/s/e...

photo
photo
1

double, deleted

photo
2

here something similar (minimalistic)

photo
1

Thanks! I like this one.

But I'm not getting to put into my code.

I'm doing this (for number Y):

Definition: abs(Distancia(A, D) - Distancia(Esquina(texto2, 1), Esquina(texto2, 2)))

Code: Valor(texto2(s,Minimiza(%0,(s))))


But it says my code has an "illegal argument"

photo
1

then read here

and compare your solution with ascensor_3.ggb

or try to implement the solution by mathmagic.

But the best way is to understand one of the solutions before you implement.

photo
photo
1

1º cuando algo funciona, funciona. Si falla puntualmente se borra el objeto y se vuelve a construir. Seguramente el texto era de otro tipo de posicionamiento y se guardó con un desplazamiento tipo del que se usa para colocar los rótulos alrededor del objeto

2º no es bueno limitar los valores de los deslizadores que se calculan numéricamente pues necesitan cierto margen para aproximarse; en algunos pasos se acercan y en otros se alejan. Por eso he cambiado el script

3º he puesto el rótulo sobre y no encima del segmento, pero si es necesario ajustar algo el desfase puedes sumar a C un poquito de desplazamiento para recolocarlo; no mucho

Files: foro.ggb
photo
1

Gracias... Pero no veo que se expanda más allá de s=5. ¿Seguro que este es el archivo más reciente? Tal vez no se guardaron tus cambios

photo
1

lee las cosas. no se expande porque el deslizador lo he puesto hasta 50 pero el posible valor asignado a ss por el script es 5 si el valor minimo lo supera

photo
© 2021 International GeoGebra Institute