You've already forked lazarus-ccr
richmemo: cocoa, cleanup memory use to prevent crashes
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6473 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -262,6 +262,7 @@ end;
|
|||||||
function FindFont(const FamilyName: String; astyle: TFontStyles): NSFontDescriptor;
|
function FindFont(const FamilyName: String; astyle: TFontStyles): NSFontDescriptor;
|
||||||
var
|
var
|
||||||
fd : NSFontDescriptor;
|
fd : NSFontDescriptor;
|
||||||
|
cfd : NSFontDescriptor;
|
||||||
old : NSFontDescriptor;
|
old : NSFontDescriptor;
|
||||||
fdd : NSFontDescriptor;
|
fdd : NSFontDescriptor;
|
||||||
trt : NSFontSymbolicTraits;
|
trt : NSFontSymbolicTraits;
|
||||||
@ -276,18 +277,23 @@ begin
|
|||||||
if fsBold in aStyle then trt:=trt or NSFontBoldTrait;
|
if fsBold in aStyle then trt:=trt or NSFontBoldTrait;
|
||||||
|
|
||||||
fd:=NSFontDescriptor(NSFontDescriptor.alloc).initWithFontAttributes(nil);
|
fd:=NSFontDescriptor(NSFontDescriptor.alloc).initWithFontAttributes(nil);
|
||||||
fd:=fd.fontDescriptorWithFamily(ns);
|
cfd:=fd;
|
||||||
fd:=fd.fontDescriptorWithSymbolicTraits(trt);
|
try
|
||||||
|
fd:=fd.fontDescriptorWithFamily(ns);
|
||||||
fdd:=fd.matchingFontDescriptorWithMandatoryKeys(nil);
|
|
||||||
i:=0;
|
|
||||||
while not Assigned(fdd) and (i<length(fallback)) do begin
|
|
||||||
trt:=trt and (not fallback[i]);
|
|
||||||
fd:=fd.fontDescriptorWithSymbolicTraits(trt);
|
fd:=fd.fontDescriptorWithSymbolicTraits(trt);
|
||||||
|
|
||||||
fdd:=fd.matchingFontDescriptorWithMandatoryKeys(nil);
|
fdd:=fd.matchingFontDescriptorWithMandatoryKeys(nil);
|
||||||
|
i:=0;
|
||||||
|
while not Assigned(fdd) and (i<length(fallback)) do begin
|
||||||
|
trt:=trt and (not fallback[i]);
|
||||||
|
fd:=fd.fontDescriptorWithSymbolicTraits(trt);
|
||||||
|
fdd:=fd.matchingFontDescriptorWithMandatoryKeys(nil);
|
||||||
|
end;
|
||||||
|
Result:=fdd;
|
||||||
|
finally
|
||||||
|
ns.release;
|
||||||
|
cfd.release;
|
||||||
end;
|
end;
|
||||||
Result:=fdd;
|
|
||||||
ns.release;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class procedure TCocoaWSCustomRichMemo.SetTextAttributes(
|
class procedure TCocoaWSCustomRichMemo.SetTextAttributes(
|
||||||
@ -314,35 +320,30 @@ begin
|
|||||||
|
|
||||||
fd:=FindFont(Params.Name, Params.Style);
|
fd:=FindFont(Params.Name, Params.Style);
|
||||||
font:=NSFont.fontWithDescriptor_size(fd, Params.Size);
|
font:=NSFont.fontWithDescriptor_size(fd, Params.Size);
|
||||||
|
|
||||||
txt.addAttribute_value_range(NSFontAttributeName, font, rng);
|
txt.addAttribute_value_range(NSFontAttributeName, font, rng);
|
||||||
// fd.release;
|
// fd.release;
|
||||||
|
|
||||||
if fsUnderline in Params.Style then begin
|
if fsUnderline in Params.Style then begin
|
||||||
num:=NSNumber.numberWithInt(NSUnderlineStyleSingle);
|
num:=NSNumber.numberWithInt(NSUnderlineStyleSingle);
|
||||||
txt.addAttribute_value_range(NSUnderlineStyleAttributeName, num, rng);
|
txt.addAttribute_value_range(NSUnderlineStyleAttributeName, num, rng);
|
||||||
num.release;
|
|
||||||
end else
|
end else
|
||||||
txt.removeAttribute_range(NSUnderlineStyleAttributeName, rng);
|
txt.removeAttribute_range(NSUnderlineStyleAttributeName, rng);
|
||||||
|
|
||||||
if fsStrikeOut in Params.Style then begin
|
if fsStrikeOut in Params.Style then begin
|
||||||
num:=NSNumber.numberWithInt(NSUnderlineStyleSingle);
|
num:=NSNumber.numberWithInt(NSUnderlineStyleSingle);
|
||||||
txt.addAttribute_value_range(NSStrikethroughStyleAttributeName, num, rng);
|
txt.addAttribute_value_range(NSStrikethroughStyleAttributeName, num, rng);
|
||||||
num.release;
|
|
||||||
end else
|
end else
|
||||||
txt.removeAttribute_range(NSStrikethroughStyleAttributeName, rng);
|
txt.removeAttribute_range(NSStrikethroughStyleAttributeName, rng);
|
||||||
|
|
||||||
|
|
||||||
clr:=ColorToNSColor(Params.Color);
|
clr:=ColorToNSColor(Params.Color);
|
||||||
txt.addAttribute_value_range(NSForegroundColorAttributeName, clr, rng);
|
txt.addAttribute_value_range(NSForegroundColorAttributeName, clr, rng);
|
||||||
clr.release;
|
|
||||||
|
|
||||||
if Params.HasBkClr then begin
|
if Params.HasBkClr then begin
|
||||||
clr:=ColorToNSColor(Params.BkColor);
|
clr:=ColorToNSColor(Params.BkColor);
|
||||||
txt.addAttribute_value_range(NSBackgroundColorAttributeName, clr, rng);
|
txt.addAttribute_value_range(NSBackgroundColorAttributeName, clr, rng);
|
||||||
clr.release;
|
|
||||||
end else
|
end else
|
||||||
txt.removeAttribute_range(NSBackgroundColorAttributeName, rng);
|
txt.removeAttribute_range(NSBackgroundColorAttributeName, rng);
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class procedure TCocoaWSCustomRichMemo.SetParaAlignment(
|
class procedure TCocoaWSCustomRichMemo.SetParaAlignment(
|
||||||
|
Reference in New Issue
Block a user