From 68bfbc02dc422c804c68da770e4f155001aa06bf Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Fri, 8 Jul 2016 11:05:54 +0000 Subject: [PATCH] tvplanit: Add centimeters as new measurement unit. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4937 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/tvplanit/source/vpbase.pas | 2 +- components/tvplanit/source/vpconst.pas | 2 ++ components/tvplanit/source/vpedelem.lfm | 1 + components/tvplanit/source/vpmisc.pas | 8 ++--- components/tvplanit/source/vpprtfmt.pas | 41 +++++++++++++++++++++---- 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/components/tvplanit/source/vpbase.pas b/components/tvplanit/source/vpbase.pas index 8320d96f3..11673e147 100644 --- a/components/tvplanit/source/vpbase.pas +++ b/components/tvplanit/source/vpbase.pas @@ -54,7 +54,7 @@ const type TVpRotationAngle = (ra0, ra90, ra180, ra270); - TVpItemMeasurement = (imAbsolutePixel, imPercent, imInches); + TVpItemMeasurement = (imAbsolutePixel, imPercent, imInches, imCentimeters); TVpItemType = (itDayView, itWeekView, itMonthView, itCalendar, itShape, itCaption, itTasks, itContacts); diff --git a/components/tvplanit/source/vpconst.pas b/components/tvplanit/source/vpconst.pas index 0d12b3bf4..b4bb45675 100644 --- a/components/tvplanit/source/vpconst.pas +++ b/components/tvplanit/source/vpconst.pas @@ -82,6 +82,8 @@ const { of the Contact Grid's horizontal bars. } CompareTimeEPS = 1.0 / (24*60*60*10); { Epsilon for time comparison, 0.1 sec } + cmPerInch = 2.54; { 1 inch is 2.54 cm } + ResourceTableName = 'Resources'; TasksTableName = 'Tasks'; EventsTableName = 'Events'; diff --git a/components/tvplanit/source/vpedelem.lfm b/components/tvplanit/source/vpedelem.lfm index 466b8d792..3b2e50cd9 100644 --- a/components/tvplanit/source/vpedelem.lfm +++ b/components/tvplanit/source/vpedelem.lfm @@ -184,6 +184,7 @@ object frmEditElement: TfrmEditElement 'Pixels' 'Percent' 'Inches' + 'cm' ) OnClick = rgMeasurementClick TabOrder = 1 diff --git a/components/tvplanit/source/vpmisc.pas b/components/tvplanit/source/vpmisc.pas index 4a444255f..e9b38e7e3 100644 --- a/components/tvplanit/source/vpmisc.pas +++ b/components/tvplanit/source/vpmisc.pas @@ -46,10 +46,9 @@ type TDayList = array[1..12] of Word; - TVpDayType = (dtSunday, dtMonday, dtTuesday, dtWednesday, dtThursday, - dtFriday, dtSaturday); + TVpDayType = (dtSunday, dtMonday, dtTuesday, dtWednesday, dtThursday, dtFriday, dtSaturday); - TVpDateFormat = (dfShort, dfLong); + TVpDateFormat = (dfShort, dfLong); TVpDayNameWidth = Integer; @@ -85,6 +84,8 @@ function HeightOf(const R : TRect) : Integer; {- return the height of the TRect} function WidthOf(const R : TRect) : Integer; {- return the width of the TRect} +function RightOf(AControl: TControl): Integer; + {- returns the right edge of a control } function GetDisplayString(Canvas : TCanvas; const S : string; MinChars, MaxWidth : Integer) : string; {-given a string, a minimum number of chars to display, and a max width, } @@ -126,7 +127,6 @@ function GetLineDuration(Granularity: TVpGranularity): Double; function GetLabelWidth(ALabel: TLabel): Integer; function GetRealFontHeight(AFont: TFont): Integer; -function RightOf(AControl: TControl): Integer; function DecodeLineEndings(const AText: String): String; function EncodeLineEndings(const AText: String): String; diff --git a/components/tvplanit/source/vpprtfmt.pas b/components/tvplanit/source/vpprtfmt.pas index 66fef021c..f8237a712 100644 --- a/components/tvplanit/source/vpprtfmt.pas +++ b/components/tvplanit/source/vpprtfmt.pas @@ -447,7 +447,7 @@ uses {$IFDEF LCL} DateUtils, {$ENDIF} - VpBaseDS, VpPrtFmtCBox, VpPrtPrv, VpDayView, VpWeekView, VpMonthView, + VpConst, VpBaseDS, VpPrtFmtCBox, VpPrtPrv, VpDayView, VpWeekView, VpMonthView, VpCalendar, VpTaskList, VpContactGrid; function XMLizeString(const s: string): string; @@ -1548,10 +1548,18 @@ var imInches: begin StartX := Round(Element.Left * PixelsPerInchX); - StartY := Round(Element.Top * PixelsPerInchX); + StartY := Round(Element.Top * PixelsPerInchY); StopX := Round((Element.Left + Element.Width) * PixelsPerInchX); StopY := Round((Element.Top + Element.Height) * PixelsPerInchX); end; + + imCentimeters: + begin + StartX := Round(Element.Left * PixelsPerInchX / cmPerInch); + StartY := Round(Element.Top * PixelsPerInchY / cmPerInch); + StopX := Round((Element.Left + Element.Width) * PixelsPerInchX / cmPerInch); + StopY := Round((Element.Top + Element.Height) * PixelsPerInchY / cmPerInch); + end; end; inc(StartX, ARect.Left); @@ -1768,10 +1776,19 @@ var imInches: begin ARect.Left := Round(LeftMargin * PixelsPerInchX); - ARect.Top := Round(TopMargin * PixelsPerInchX); + ARect.Top := Round(TopMargin * PixelsPerInchY); ARect.Right := ARect.Right - Round(RightMargin * PixelsPerInchX); - ARect.Bottom := ARect.Bottom - Round(BottomMargin * PixelsPerInchX); + ARect.Bottom := ARect.Bottom - Round(BottomMargin * PixelsPerInchY); end; + + imCentimeters: + begin + ARect.Left := Round(LeftMargin * PixelsPerInchX / cmPerInch); + ARect.Top := Round(TopMargin * PixelsPerInchY / cmPerInch); + ARect.Right := ARect.Right - Round(RightMargin * PixelsPerInchX / cmPerInch); + ARect.Bottom := ARect.Bottom - Round(BottomMargin * PixelsPerInchY / cmPerInch); + end; + end; end; @@ -1937,9 +1954,17 @@ var imInches: begin ARect.Left := Round(LeftMargin * PixelsPerInchX); - ARect.Top := Round(TopMargin * PixelsPerInchX); + ARect.Top := Round(TopMargin * PixelsPerInchY); ARect.Right := ARect.Right - Round(RightMargin * PixelsPerInchX); - ARect.Bottom := ARect.Bottom - Round(BottomMargin * PixelsPerInchX); + ARect.Bottom := ARect.Bottom - Round(BottomMargin * PixelsPerInchY); + end; + + imCentimeters: + begin + ARect.Left := Round(LeftMargin * PixelsPerInchX / cmPerInch); + ARect.Top := Round(TopMargin * PixelsPerInchY / cmPerInch); + ARect.Right := ARect.Right - Round(RightMargin * PixelsPerInchX / cmPerInch); + ARect.Bottom := ARect.Bottom - Round(BottomMargin * PixelsPerInchY / cmPerInch); end; end; end; @@ -2178,6 +2203,7 @@ begin imAbsolutePixel : Writeln(fpOut, ' Measurement="AbsolutePixel"'); imPercent : Writeln(fpOut, ' Measurement="Percent"'); imInches : Writeln(fpOut, ' Measurement="Inches"'); + imCentimeters : WriteLn(fpOut, ' Measurement="Centimeters"'); end; Writeln(fpOut, ' Left="' + FloatToStr(elem.Left) + '"'); Writeln(fpOut, ' Top="' + FloatToStr(elem.Top) + '"'); @@ -2585,6 +2611,9 @@ begin else if attr.Value = 'Inches' then NewElement.Measurement := imInches + else + if attr.Value = 'Centimeters' then + NewElement.Measurement := imCentimeters else raise EVpPrintFormatError.Create(RSBadMeasurement + attr.Value); end