#1 GDI+ » Pixelated TextOut from TMetaFile » 2016-11-11 16:43:06

ethanyager
Replies: 0

I am using the previous example of antialiasing from a TMetaFile. It works great for lines but I can't get smooth aa text like I usually get with GDI+. Not sure what I am doing wrong. In the example below, I added one text out and one line. If I modify this example to use regular GDI rendering the text will appear smoother than when antialiasing is turned on.

Here is my code:

var Bmp: TBitmap;
    MF: TMetaFile;
    MetafileCanvas: TMetafileCanvas;
    DC: HDC;
    ScreenLogPixels: Integer;
    LogFont: TLogFont;
begin
  MF := TMetaFile.Create;
  DC := GetDC(0);
  ScreenLogPixels := GetDeviceCaps(DC, LOGPIXELSY);
  MF.Inch := ScreenLogPixels;
  MF.Width := Form1.Width;
  MF.Height := Form1.Height;

  MetafileCanvas := TMetafileCanvas.Create(MF, DC);

  MetafileCanvas.font.Color := clblue;
  MetafileCanvas.font.Name := 'Calibri';
  MetafileCanvas.font.Size := 150;

  MetafileCanvas.TextOut(100, 100, 'Text Out AaBbCcDdEeFfGgHhIi');
  MetaFileCanvas.Pen.Width := 2;
  MetaFileCanvas.MoveTo(100,300);
  MetaFileCanvas.LineTo(900,600);

  ReleaseDC(0, DC);


  MetafileCanvas.Free;
  MF.Enhanced := FALSE;

  Bmp := TBitmap.Create;
  BMp.Width := Form1.Width;
  Bmp.Height := Form1.height;

  ExpectGDIPlusFull;

  Bmp := Gdip.DrawAntiAliased(MF,100,100, smAntiAlias);
  Canv.Draw(0,0,bmp);

  bmp.Free;
  MF.Destroy;
end;

#2 Re: mORMot 1 » Multidimensional Array support for JSON Serialization of Record » 2016-04-05 19:46:12

Thanks, Ab,

With the custom serializer are you suggesting to define the input parameter aValue as a TDocVariantData and then let the writer add the array automatically, then just reverse that for the reader? (Sorry I am unfamiliar with mORMot but am trying to wrap my head around it)

Using previous example:

TMyRecord = record
  MyInt: Integer;
  MyStr: string;
  MyArray: TDocVariantData;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Myrecord: TMyRecord;
  U: string;
begin
  try
    TTextWriter.RegisterCustomJSONSerializerFromText(
      TypeInfo(TDocVariantData),__TDocVariantData);
  except
    on e: exception do ShowMessage('ser: ' + e.Message);
  end;
  try
    TTextWriter.RegisterCustomJSONSerializerFromText(
      TypeInfo(TMyRecord),__TMyRecord);
  except
    on e: exception do ShowMessage('ser: ' + e.Message);
  end;
  MyRecord.MyInt:= 10;
  MyRecord.MyString := 'MyString';

  V := _Arr(['1','2','3']);

  U := RecordSaveJSON(MyRecord,TypeInfo(TMyRecord));
  edit1.Text := u;
end;

And then custom handle the TDocVariantData type?

class procedure TMyCustomHandler.Writer(const aWriter: TTextWriter; const aValue);
var
  V: TDocVariantData absolute aValue;
begin
  aWriter.AddVariant(V); // something like this?
end;

Thanks
Ethan

#3 mORMot 1 » Multidimensional Array support for JSON Serialization of Record » 2016-04-05 16:51:03

ethanyager
Replies: 3

Hi, I have a record containing a multidimensional array and I am getting an error when trying to serialize.

__TMyRecord = 'MyInt: integer; MyString: string; MyArray: array of array of string';

TMyRecord = record
  MyInt: Integer;
  MyStr: string;
  MyArray: Array of Array of string;
end;

If I register the type / add values and try to serialize the record:

procedure TForm1.Button1Click(Sender: TObject);
var
  Myrecord: TMyRecord;
  U: string;
begin
  try
    TTextWriter.RegisterCustomJSONSerializerFromText(
      TypeInfo(TMyRecord),__TMyRecord);
  except
    on e: exception do ShowMessage('ser: ' + e.Message);
  end;
  MyRecord.MyInt:= 10;
  MyRecord.MyString := 'MyString';
  SetLength(MyRecord.MyArray, 1,1);
  MyRecord.MyArray[0,0] := '00';
  MyRecord.MyArray[1,0] := '10';
  MyRecord.MyArray[0,1] := '01';
  MyRecord.MyArray[1,1] := '11';
  U := RecordSaveJSON(MyRecord,TypeInfo(TMyRecord));
  edit1.Text := u;
end;

It fails with: TJSONRecordTextDefinition.Parse: expected syntax is "array of record" or "array of SimpleType"

Does MORMot support multidimensional arrays somehow, like in my example? (not arrays of record)

If not, can someone point me in the right direction of how to add multidimensional array support? The JSON and class definitions are locked and I need to read/write JSON like this:

{
"MyInt":10,
"MyString":"MyString",
"MyArray": [
                  ["00", "10"],
                  ["01","11"]
                ]
}

I have some that are up to 4 or 5 dimensional arrays.

Thanks
Ethan

Board footer

Powered by FluxBB