Page 1 of 1

Demo request: zoom

Posted: Tue Nov 12, 2019 11:08 am
by jonjon
Hi,
The latest version of RV supports zooming and its very interesting to me. Is there a demo available with a Word-like zoom scroller from say 10% to 500% ?
I understand that the DocumentPixelsPerInch is the property to use but I'm not sure how it should be handled based on current screen's DPI. Also, is it saved within the RVF or exported to HTML / printing ? If so, should it be set back to 0 before saving / exporting / printing ?
Thank you.

Re: Demo request: zoom

Posted: Tue Nov 12, 2019 12:32 pm
by Sergey Tkachenko
If you use Delphi 10.3, you can check the demo in RichViewActions\Demos\DelphiUnicode\ActionTest_MultiRes\
It has c combobox for applying some predefined DPI: auto (using the current screen DPI), 48, 96, 144, 192, 240, 288, 384, 480.
The code for DPI application is:

Code: Select all

procedure TForm3.cmbZoomClick(Sender: TObject);
const
  DPIArray: array [0..8] of Integer =
    (0, 48, 96, 144, 192, 240, 288, 384, 480);
begin
  if cmbZoom.ItemIndex >= 0 then
  begin
    RichViewEdit1.DocumentPixelsPerInch := DPIArray[cmbZoom.ItemIndex];
    RichViewEdit1.Reformat;
    RichViewEdit1.SetFocus;
    RVRuler1.Zoom :=
      Round(100*RichViewEdit1.GetRealDocumentPixelsPerInch / RVRuler1.ScreenRes);
    RVRuler1.UpdateRulerMargins;
  end;
end;
Items in these combobox are labeled relative to 96 DPI: Auto, 50%, 100%, 150%, and so on.

Additionally, there is a code in OnAfterMonitorDpiChanged event to adjust the ruler:

Code: Select all

  {
    The ruler changes its ScreenRes automatically.
    If RichViewEdit1.DocumentPixelsPerInch = 0, both the ruler and the editor
    are displayed at the current DPI, no adjustment is needed.
    However, if we changed DocumentPixelsPerInch, we need to recalculate
    the ruler's Zoom
  }
  RVRuler1.Zoom := Round(100*RichViewEdit1.GetRealDocumentPixelsPerInch / RVRuler1.ScreenRes);
  RVRuler1.UpdateRulerMargins;

Re: Demo request: zoom

Posted: Tue Nov 12, 2019 1:40 pm
by Sergey Tkachenko
If you want to change text of items in this combobox, so that they display zooming relative to the current screen DPI instead of 96...

Add this function:

Code: Select all

procedure TForm3.ChangeZoomComboBox;
const
  DPIArray: array [0..8] of Integer =
    (0, 48, 96, 144, 192, 240, 288, 384, 480);
var
  i, idx: Integer;
begin
  idx := cmbZoom.ItemIndex;
  for i := 0 to cmbZoom.Items.Count - 1 do
    if DPIArray[i] = 0 then
      cmbZoom.Items[i] := RVA_GetS(rvam_cl_Auto)
    else
      cmbZoom.Items[i] := IntToStr(DPIArray[i] * 100 div CurrentPPI) + '% (' +
        IntToStr(DPIArray[i]) + ' dpi)';
  cmbZoom.ItemIndex := idx;
end;
Call this function in FormAfterMonitorDpiChanged procedure. This procedure is assigned to the form's OnAfterMonitorDpiChanged event. Also, it is called by the application in FormCreate, if the current DPI is not 96.

Re: Demo request: zoom

Posted: Tue Nov 12, 2019 1:41 pm
by Sergey Tkachenko
No, DocumentPixelsPerInch is not stored in RVF.
No, you do not need to reset it before printing, exporting, or importing. It does not affect them.

Re: Demo request: zoom

Posted: Tue Nov 12, 2019 1:48 pm
by Sergey Tkachenko
The code above renames items in the combobox, but it does not change the behavior:
- if DocumentPixelsPerInch = 0, the editor keeps 100% zoom when the screen DPI is changed;
- if DocumentPixelsPerInch > 0, its value is kept when the screen DPI is changed.

(the screen DPI can be changed when the user changes the screen DPI in screen settings; or in multi-monitor environment, when the user moves the window from one screen to another).

Probably, you want another behavior: to change DocumentPixelsPerInch for keeping the specified zooming percent. If yes, let me know, I'll write the code.

Re: Demo request: zoom

Posted: Tue Nov 12, 2019 2:18 pm
by jonjon
Thank you. Yes, please provide a demo to keep the specified zooming percent when dpi changes.

Re: Demo request: zoom

Posted: Wed Nov 13, 2019 12:26 pm
by Sergey Tkachenko
I created a demo:
https://www.trichview.com/forums/viewto ... f=3&t=9745

Actually, it is very simple: when the form DPI is changed, the demo re-applies the selected zooming percent.