mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-07-26 08:35:59 +02:00
fpvectorial: Fix text rotation for wmf.
git-svn-id: trunk@52831 -
This commit is contained in:
parent
8023318178
commit
2cdcbefef6
@ -9,7 +9,7 @@
|
|||||||
- see the empty case items in "TWMFVectorialReader.ReadRecords"
|
- see the empty case items in "TWMFVectorialReader.ReadRecords"
|
||||||
|
|
||||||
Issues:
|
Issues:
|
||||||
- fpvectorial polygon fill has the issue to always fill holes.
|
- Text often truncated, last character missing
|
||||||
|
|
||||||
Author: Werner Pamler
|
Author: Werner Pamler
|
||||||
}
|
}
|
||||||
@ -136,8 +136,9 @@ uses
|
|||||||
fpvUtils, fpvWMF;
|
fpvUtils, fpvWMF;
|
||||||
|
|
||||||
const
|
const
|
||||||
INCH = 25.4; // 1 inch = 25.4 mm
|
INCH2MM = 25.4; // 1 inch = 25.4 mm
|
||||||
DEFAULT_SIZE = 100; // size of image if scaling info is not available
|
DEFAULT_SIZE = 100; // size of image if scaling info is not available
|
||||||
|
SIZE_OF_WORD = 2;
|
||||||
|
|
||||||
type
|
type
|
||||||
TWMFFont = class
|
TWMFFont = class
|
||||||
@ -317,7 +318,7 @@ begin
|
|||||||
|
|
||||||
// Get font name
|
// Get font name
|
||||||
SetLength(fntName, 32);
|
SetLength(fntName, 32);
|
||||||
idx := SizeOf(TWMFFontRecord) div SizeOf(word);
|
idx := SizeOf(TWMFFontRecord) div SIZE_OF_WORD;
|
||||||
fntname := StrPas(PChar(@AParams[idx]));
|
fntname := StrPas(PChar(@AParams[idx]));
|
||||||
|
|
||||||
wmfFont.Font.Name := ISO_8859_1ToUTF8(fntName);
|
wmfFont.Font.Name := ISO_8859_1ToUTF8(fntName);
|
||||||
@ -327,7 +328,7 @@ begin
|
|||||||
wmfFont.Font.Italic := fontRec^.Italic <> 0;
|
wmfFont.Font.Italic := fontRec^.Italic <> 0;
|
||||||
wmfFont.Font.Underline := fontRec^.UnderLine <> 0;
|
wmfFont.Font.Underline := fontRec^.UnderLine <> 0;
|
||||||
wmfFont.Font.StrikeThrough := fontRec^.Strikeout <> 0;
|
wmfFont.Font.StrikeThrough := fontRec^.Strikeout <> 0;
|
||||||
wmfFont.Font.Orientation := fontRec^.Orientation div 10;
|
wmfFont.Font.Orientation := fontRec^.Escapement div 10;
|
||||||
wmfFont.RawHeight := fontRec^.Height; //* 6 div 5; // Rough correction for y position
|
wmfFont.RawHeight := fontRec^.Height; //* 6 div 5; // Rough correction for y position
|
||||||
|
|
||||||
// add to WMF object list
|
// add to WMF object list
|
||||||
@ -807,7 +808,7 @@ begin
|
|||||||
FRecordStartPos := AStream.Position;
|
FRecordStartPos := AStream.Position;
|
||||||
|
|
||||||
// Read record size and function code
|
// Read record size and function code
|
||||||
AStream.ReadBuffer(wmfRec, SizeOf(wmfRec));
|
AStream.ReadBuffer(wmfRec, SizeOf(TWMFRecord));
|
||||||
|
|
||||||
{$IFDEF WMF_DEBUG}
|
{$IFDEF WMF_DEBUG}
|
||||||
writeLn(Format('Record position: %0:d / Record size: %1:d words / Record type: %2:d ($%2:x): %3:s',
|
writeLn(Format('Record position: %0:d / Record size: %1:d words / Record type: %2:d ($%2:x): %3:s',
|
||||||
@ -826,7 +827,7 @@ begin
|
|||||||
|
|
||||||
// Read parameters
|
// Read parameters
|
||||||
SetLength(params, wmfRec.Size - 3);
|
SetLength(params, wmfRec.Size - 3);
|
||||||
AStream.ReadBuffer(params[0], (wmfRec.Size - 3)*SizeOf(word));
|
AStream.ReadBuffer(params[0], (wmfRec.Size - 3)*SIZE_OF_WORD);
|
||||||
|
|
||||||
// Process record, depending on function code
|
// Process record, depending on function code
|
||||||
case wmfRec.Func of
|
case wmfRec.Func of
|
||||||
@ -983,7 +984,7 @@ begin
|
|||||||
// None of them implemented
|
// None of them implemented
|
||||||
end;
|
end;
|
||||||
|
|
||||||
AStream.Position := FRecordStartPos + wmfRec.Size*SizeOf(word);
|
AStream.Position := FRecordStartPos + wmfRec.Size * SIZE_OF_WORD;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if FHasPlaceableMetaHeader then begin
|
if FHasPlaceableMetaHeader then begin
|
||||||
@ -1081,7 +1082,7 @@ begin
|
|||||||
|
|
||||||
memStream := TMemoryStream.Create;
|
memStream := TMemoryStream.Create;
|
||||||
try
|
try
|
||||||
datasize := (Length(AParams) - AIndex) * SizeOf(word);
|
datasize := (Length(AParams) - AIndex) * SIZE_OF_WORD;
|
||||||
|
|
||||||
// Put a bitmap file header in front of the bitmap info header and the data
|
// Put a bitmap file header in front of the bitmap info header and the data
|
||||||
bmpFileHdr.bfType := BMmagic;
|
bmpFileHdr.bfType := BMmagic;
|
||||||
@ -1093,7 +1094,7 @@ begin
|
|||||||
bmpFileHdr.bfOffset := bmpFileHdr.bfSize - imgSize;
|
bmpFileHdr.bfOffset := bmpFileHdr.bfSize - imgSize;
|
||||||
bmpFileHdr.bfReserved := 0;
|
bmpFileHdr.bfReserved := 0;
|
||||||
memstream.WriteBuffer(bmpFileHdr, SizeOf(bmpFileHdr));
|
memstream.WriteBuffer(bmpFileHdr, SizeOf(bmpFileHdr));
|
||||||
memstream.WriteBuffer(AParams[AIndex], (Length(AParams) - AIndex) * SizeOf(word));
|
memstream.WriteBuffer(AParams[AIndex], (Length(AParams) - AIndex) * SIZE_OF_WORD);
|
||||||
|
|
||||||
// Read bitmap to image using the standard bitmap reader.
|
// Read bitmap to image using the standard bitmap reader.
|
||||||
reader := TFPReaderBMP.Create;
|
reader := TFPReaderBMP.Create;
|
||||||
@ -1123,7 +1124,7 @@ begin
|
|||||||
dibRec := PWMFStretchDIBRecord(@AParams[0]);
|
dibRec := PWMFStretchDIBRecord(@AParams[0]);
|
||||||
memImg := TFPMemoryImage.Create(0, 0); //w, h);
|
memImg := TFPMemoryImage.Create(0, 0); //w, h);
|
||||||
try
|
try
|
||||||
if not ReadImage(AParams, SizeOf(TWMFStretchDIBRecord) div SizeOf(word), memImg) then
|
if not ReadImage(AParams, SizeOf(TWMFStretchDIBRecord) div SIZE_OF_WORD, memImg) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
// Pass bitmap to fpvectorial
|
// Pass bitmap to fpvectorial
|
||||||
@ -1209,7 +1210,7 @@ begin
|
|||||||
i := AStartIndex;
|
i := AStartIndex;
|
||||||
j := 1;
|
j := 1;
|
||||||
while j < ALength do begin
|
while j < ALength do begin
|
||||||
Move(AParams[i], s[j], SizeOf(Word));
|
Move(AParams[i], s[j], SIZE_OF_WORD);
|
||||||
inc(i);
|
inc(i);
|
||||||
inc(j, 2);
|
inc(j, 2);
|
||||||
end;
|
end;
|
||||||
@ -1300,8 +1301,8 @@ begin
|
|||||||
case FMapMode of
|
case FMapMode of
|
||||||
MM_TEXT: // 1 log unit = 1 pixel
|
MM_TEXT: // 1 log unit = 1 pixel
|
||||||
begin
|
begin
|
||||||
fx := ScreenDpiX * INCH;
|
fx := ScreenDpiX * INCH2MM;
|
||||||
fy := ScreenDpiY * INCH;
|
fy := ScreenDpiY * INCH2MM;
|
||||||
end;
|
end;
|
||||||
MM_LOMETRIC: // 1 log unit = 1/10 mm
|
MM_LOMETRIC: // 1 log unit = 1/10 mm
|
||||||
begin
|
begin
|
||||||
@ -1315,25 +1316,25 @@ begin
|
|||||||
end;
|
end;
|
||||||
MM_LOENGLISH: // 1 log unit = 1/100"
|
MM_LOENGLISH: // 1 log unit = 1/100"
|
||||||
begin
|
begin
|
||||||
fx := 0.01 * INCH;
|
fx := 0.01 * INCH2MM;
|
||||||
fy := fx;
|
fy := fx;
|
||||||
end;
|
end;
|
||||||
MM_HIENGLISH: // 1 log unit = 1/1000"
|
MM_HIENGLISH: // 1 log unit = 1/1000"
|
||||||
begin
|
begin
|
||||||
fx := 0.001 * INCH;
|
fx := 0.001 * INCH2MM;
|
||||||
fy := fx;
|
fy := fx;
|
||||||
end;
|
end;
|
||||||
MM_TWIPS: // 1 log unit = 1 twip
|
MM_TWIPS: // 1 log unit = 1 twip
|
||||||
begin
|
begin
|
||||||
fx := 1.0 / 1440 * INCH;
|
fx := 1.0 / 1440 * INCH2MM;
|
||||||
fy := fx;
|
fy := fx;
|
||||||
end;
|
end;
|
||||||
else
|
else
|
||||||
if (FWindowExtent.X = 0) or (FWindowExtent.Y = 0) then
|
if (FWindowExtent.X = 0) or (FWindowExtent.Y = 0) then
|
||||||
exit;
|
exit;
|
||||||
if FHasPlaceableMetaHeader then begin
|
if FHasPlaceableMetaHeader then begin
|
||||||
FPageWidth := (FBBox.Right - FBBox.Left) * INCH / FUnitsPerInch;
|
FPageWidth := (FBBox.Right - FBBox.Left) * INCH2MM / FUnitsPerInch;
|
||||||
FPageHeight := (FBBox.Bottom - FBBox.Top) * INCH / FUnitsPerInch;
|
FPageHeight := (FBBox.Bottom - FBBox.Top) * INCH2MM / FUnitsPerInch;
|
||||||
end else
|
end else
|
||||||
if FWindowExtent.X > FWindowExtent.Y then begin
|
if FWindowExtent.X > FWindowExtent.Y then begin
|
||||||
FPageWidth := DEFAULT_SIZE;
|
FPageWidth := DEFAULT_SIZE;
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
|
|
||||||
Coordinates:
|
Coordinates:
|
||||||
- wmf has y=0 at top, y grows downward (like with standard canvas).
|
- wmf has y=0 at top, y grows downward (like with standard canvas).
|
||||||
- fpv has y=0 at bottom, y grows upwards if page.UseTopLeftCoordinates is false
|
- fpv has y=0 at bottom and y grows upwards if page.UseTopLeftCoordinates is
|
||||||
or like wmf otherwise.
|
false or like wmf otherwise.
|
||||||
|
|
||||||
Issues:
|
Issues:
|
||||||
- Text background is opaque although it should not be.
|
- Text background is opaque although it should be transparent.
|
||||||
- Text rotation is ignored if files are opened by MS programs, LibreOffice ok.
|
|
||||||
- IrfanView cannot open the files written.
|
- IrfanView cannot open the files written.
|
||||||
|
- Text positioning incorrect due to positive/negative font heights.
|
||||||
|
|
||||||
Author: Werner Pamler
|
Author: Werner Pamler
|
||||||
}
|
}
|
||||||
@ -546,10 +546,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
n := SizeOf(TWMFFontRecord) + Length(fntName);
|
n := SizeOf(TWMFFontRecord) + Length(fntName);
|
||||||
rec.Height := -ScaleSizeY(AFont.Size);
|
rec.Height := ScaleSizeY(AFont.Size);
|
||||||
rec.Width := 0;
|
rec.Width := 0;
|
||||||
rec.Escapement := 0;
|
|
||||||
rec.Orientation := round(AFont.Orientation * 10);
|
rec.Orientation := round(AFont.Orientation * 10);
|
||||||
|
rec.Escapement := round(AFont.Orientation * 10); // 0;
|
||||||
|
// strange: must use "Escapement" here, not "Orientation".
|
||||||
|
// Otherwise MS software will not show the rotated font.
|
||||||
rec.Weight := IfThen(AFont.Bold, 700, 400);
|
rec.Weight := IfThen(AFont.Bold, 700, 400);
|
||||||
rec.Italic := IfThen(AFont.Italic, 1, 0);
|
rec.Italic := IfThen(AFont.Italic, 1, 0);
|
||||||
rec.Underline := IfThen(AFont.Underline, 1, 0);
|
rec.Underline := IfThen(AFont.Underline, 1, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user