Forum > RichMemo
Faster Attribute Collection
rick2691:
Is there a faster way get an inline character size than the following:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---RTFmemo.GetTextAttributes(i,SelFontFormat); // visual formatSizeVal:= SelFontFormat.Size; // active font-size
Thaddy:
No. What's your problem with the speed? Maybe you just need to use beginupdate/endupdate.
rick2691:
I am iterating a text line to check the font size of each character ... it takes too long.
skalogryz:
--- Quote from: rick2691 on August 06, 2023, 06:10:20 pm ---I am iterating a text line to check the font size of each character ... it takes too long.
--- End quote ---
per-character is indeed way too long.
You might want to use GetStyleRange()
The method returns the "length" (in characters) of the same style used in text.
Thus instead of using going by each character, you can skip the chars that are using the same style.
rick2691:
OK. I have trouble with seeing how that would be applied to my objective.
I am searching for the highest character within a specific page line.
The reason is to know the actual line height.
The following is the code I am using:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var LI,LL,j,k,SizeVal,LastVal,LineHgt: integer; try LI:= SendMessage(HgtRTF.Handle,EM_LINEINDEX,ScanLine,0); // first inline character LL:= SendMessage(HgtRTF.handle,EM_LINELENGTH,LI,0); // total inline length j:= LI; // Scan-Start position (INDEX) k:= LI + LL - 1; // Scan-Stop position (LENGTH) HgtRTF.GetTextAttributes(j,SelFontFormat); SizeVal:= SelFontFormat.Size; LastVal:= SizeVal; for i:= j to k do begin HgtRTF.GetTextAttributes(i,SelFontFormat); SizeVal:= SelFontFormat.Size; if (SizeVal>LastVal) then LastVal:= SizeVal; // update highest value end; finally LineHgt:= round (LastVal * 1.628 * ZoomStat); // ZoomStat is the RTF zoom factor end; // end of try // 1.628 is the line padding factor
Note: Either make LineHgt a global variable or transmit LineHgt as a result.
Then use it as a scroll factor ... PageMemoWheel.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TCmdForm.PageMemoWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean );var WheelRTF: TRichMemo; beginWheelRoll:= 'XX'; // global variableif WheelDelta>0 then WheelRoll:= 'UP';if WheelDelta<0 then WheelRoll:= 'DN'; case WheelRoll of 'UP': begin // ** TEXT ROLLS UP & SCROLLBAR GOES DOWN *** WheelRTF.VertScrollBar.Position:= WheelRTF.VertScrollBar.Position - LineHgt; Handled:= true; end; 'DN': begin // ** TEXT ROLLS DOWN & SCROLLBAR GOES UP *** WheelRTF.VertScrollBar.Position:= WheelRTF.VertScrollBar.Position + LineHgt; Handled:= true; end; 'XX': begin Handled:= true; end; end;
The other side of this is that you use the "top line" of the screen if you are scrolling up.
Or you use the "top line minus one" for the off screen line to scroll down.
That is why I want to speed up the collection.
My thumb turns the wheel faster than the data can be acquired.
So how would I work GetStyleRange() into the code to find the highest character?
If I can't make the code as fast as my thumb ...
having it is nice, but nevertheless useless to me.
Navigation
[0] Message Index
[#] Next page