Merging collections changes the font

From SuperMemopedia
Jump to navigation Jump to search

Customer report

Merging collections resulted in a change to the font in the "receiving" collection.

Problem

Existing fonts should not be modified as indicated by the (old) source code listed below. All changes occur ONLY if FontRegistry.FindPosition() returns FALSE (i.e. font does not exist).

However, if FindPosition returns TRUE, the old font is used. It is not verified if the font is different. In other words, if two different fonts use the same name, the new font will not be transferred and the old font will be used in its place. Only one font can be used with a given name.

Solution

Provide the affected font with a unique name.

For example, most library collections use the font "Question" which often carries a unique font used in learning a given language. Meaningfully rename that font, e.g. to Tibetan, Russian, etc. before merging the collection with your core collection. Otherwise, your collection, after merger, will use your current "Question" font, instead of the font in the added collection.

In the future, SuperMemo will compare all fields of TFontRecord and import new fonts even if they differ only in style or color (see: "new source code" below)

Old Source code

procedure TComponentData.ImportFont(FontMember:string;var DFontItem:integer;FontRecord:TFontRecord);
var FontRegistry:TFontRegistry;
begin
try    FontRegistry:=TDatabase(ParentDatabase).FontRegistry;
   if not FontRegistry.FindPosition(FontMember,DFontItem) then begin
      if FontRecord.Name<>"" then
          if UpperCase(FontRecord.Name)<>'DEFAULT' then
              DFontItem:=FontRegistry.AddFontRecord(FontRecord,"",false);
      if DFontItem<>0 then
          FontRegistry.RenameMember(DFontItem,FontMember,false);
end;
except
on E:Exception do EError('Cannot import font from text file',E);
end;
end;


New Source code

procedure TComponentData.ImportFont(FontMember:string;var DFontItem:integer;NewFontRecord:TFontRecord);
var FontRegistry:TFontRegistry;
      OldFontRecord:TFontRecord;
begin
try
    FontRegistry:=TDatabase(ParentDatabase).FontRegistry;
    if FontRegistry.FindPosition(FontMember,DFontItem) then begin
       OldFontRecord:=FontRegistry.GetFontRecord(DFontItem);
      if FontsDiffer(OldFontRecord,NewFontRecord) then begin
          FontMember:=ProposedFontName(NewFontRecord);
          if not FontRegistry.FindPosition(FontMember,DFontItem) then begin
               FontRegistry.MakeUnique(FontMember);
               DFontItem:=FontRegistry.AddFontRecord(NewFontRecord,"",false);
               if DFontItem<>0 then 
                   FontRegistry.RenameMember(DFontItem,FontMember,false);
               end;
          end;
      end
else begin
      if NewFontRecord.Name<>"" then
         if UpperCase(NewFontRecord.Name)<>'DEFAULT' then
             DFontItem:=FontRegistry.AddFontRecord(NewFontRecord,"",false);
      if DFontItem<>0 then
          FontRegistry.RenameMember(DFontItem,FontMember,false);
       end;
except
on E:Exception do EError('Cannot import font from a text file',E);
end;
end;