Disclosure of Invention
In order to overcome the problems in the related prior art, the invention provides a method and a system for displaying screen watermarks by a Mac system, in particular to a method and a system for displaying screen watermarks dynamically according to a strategy, which aim to solve the problems that the existing Mac computer cannot display screen watermarks and cannot support watermark effects in a multi-desktop and full-screen state. The technical scheme adopted by the invention is as follows:
The invention provides a method for displaying screen watermarks by a Mac system, which comprises the following steps:
step one, packaging NSPanel types;
step two, removing the frame and the background color;
Drawing a watermark pattern;
and fourthly, setting and displaying the screen at the topmost layer of the screen, and setting and supporting full screen and multi-desktop modes.
Further, the method specifically includes:
instantiating NSPanel types as watermark window forms, and setting background colors as transparent colors and no frame;
through the arrangement, NSPanel types become colorless and transparent drawing boards;
By setting the layer one level higher than NSMainMenuWindowLevel, NSPanel is always displayed at the uppermost part of the screen;
the watermark window supports full screen and multiple desktops through attribute setting;
instantiating NSPanel the object as a layer drawn by the screen watermark;
the watermark content is rendered at the Layer of NSPanel in combination with the issued policy.
Further, the method further comprises the following steps:
Custom type WATERPANEL inherits from NSPanel and rewrites initWithContentRect methods;
custom WATERVIEW inherits NSView, rewrites drawRect method, and draws watermark information in the rewritten drawRect method;
Initializing WATERPANEL the object with the current screen size and setting up to add the screen watermark view to WATERPANEL;
And obtaining a watermark pattern to be drawn by analyzing a strategy issued by a background, and drawing the watermark through ESTWATERMARKVIEW.
Further, by setting collectionBehavior properties of NSPanel, full screen and multi-desktop modes are enabled.
Further, by setting hasShadow, backgroundColor attribute of NSPanel, the screen is colorless and transparent and has no shadow.
Further, a watermark strategy is obtained through an application server, and whether the watermark is displayed or not and the watermark display style and content are judged through the watermark strategy.
Further, after obtaining the watermark strategy, obtaining watermark information through analysis, and drawing the watermark through the obtained watermark information, which specifically comprises:
Acquiring policy information watermark info. OnceInfo through a network request;
Obtaining corresponding information through the policy information, including watermark direction direc, machine name MACHINENAME, address information addressInfo, custom content customContent, user information userInfo, current time currentDate, font fontName, and font color rgbaValue;
And drawing the screen watermark by acquiring the strategy information.
Further, in the step of drawing the screen watermark by acquiring the policy information, the method further includes:
splicing the character strings, and dividing corresponding information by using a line feed character;
setting a style of the character string by using the attribute character string;
Custom EstWatermarkTextLayer inherits from CATextLayer and draws watermark information into EstWatermarkTextLayer.
Another object of the present invention is to provide a system for displaying a screen watermark of a Mac system, which applies the above-described method for displaying a screen watermark of a Mac system, the system for displaying a screen watermark of a Mac system comprising:
the NSPanel-type packaging module is used for instantiating NSPanel-type watermark window;
The attribute setting module is used for setting and displaying the attribute on the topmost layer of the screen and setting and supporting full screen and multi-desktop modes;
The strategy information acquisition module is used for acquiring a watermark strategy through the application server;
and the watermark drawing module is used for drawing the screen watermark pattern through the acquired strategy information.
Further, the system further comprises a computer device including a memory and a processor, the memory storing a computer program which, when executed by the processor, causes the processor to perform the steps of:
Instantiation NSPanel of class as watermark window, setting background color as transparent color and no frame, setting NSPanel of class as colorless transparent drawing board, setting Layer higher than NSMainMenuWindowLevel by one level to make NSPanel always displayed at the top of screen, setting property to make watermark window support full screen and multiple desktops, instantiation NSPanel of object as Layer of screen watermark drawing, and drawing watermark content at Layer of NSPanel in combination with issued strategy.
Further, the system further includes a computer readable storage medium storing a computer program which, when executed by the processor, causes the processor to perform the steps of the method for displaying screen watermarks of the Mac system.
Further, the system further comprises an information data processing terminal for implementing the above-described method for displaying screen watermarks by the Mac system.
In combination with the technical scheme, the invention has the advantages that:
The method for displaying the screen watermark of the Mac system is realized based on the Cocoa library of the MacOS, and the function of displaying the watermark on the screen of the Mac computer is realized by packaging NSPanel types, so that the problem of displaying the screen watermark on the Mac computer is mainly solved, the method can be compatible with intel and M1 chips, and the Mac terminal data can be protected to effectively prevent photographing and screen capture from being divulged.
The invention has the characteristics of strong reliability, good compatibility, good portability, low dependence on the development environment, small influence on the existing codes, low coupling and high aggregation, supports the display in modes such as multi-desktop mode, full-screen mode and the like, can be compatible with intel and M1 chips at the same time, and can be rapidly integrated into any software.
The invention can protect Mac terminal data, effectively prevent risks of photographing and screen capturing disclosure, and achieve the effect of information tracking of disclosure terminals. The invention supports the Mac computer multi-desktop and full-screen modes, can well display in the states of desktop switching, newly built desktop switching and the like, and does not influence the use of other software of the computer.
The invention is used together with the corresponding security policy, and the watermark policy can be obtained through the application server, so that the display and the hiding of the watermark, and the content, the color and the depth of the watermark display can be controlled through configuration.
The screen watermark anti-disclosure protection scheme based on the Cocoa is created based on the original view, has good compatibility and high reliability, does not excessively interfere the operation of other APP and system processes while realizing the screen watermark, and has high system reliability.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention as claimed.
Detailed Description
In order that the above objects, features and advantages of the invention will be readily understood, a more particular description of the invention will be rendered by reference to the appended drawings. In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present invention. The invention may be embodied in many other forms than described herein and similarly modified by those skilled in the art without departing from the spirit or scope of the invention, which is therefore not limited to the specific embodiments disclosed below.
The invention provides a method and a system for displaying screen watermarks by a Mac system, which aims at the problems in the prior art, and the invention is described in detail below with reference to the accompanying drawings.
As shown in fig. 1, the method for displaying a watermark on a screen of a Mac system according to an embodiment of the present invention includes the following steps:
S101, packaging NSPanel types;
S102, removing the frame and the background color;
s103, drawing watermark patterns;
s104, setting and displaying the screen at the topmost layer, and setting and supporting full screen and multi-desktop modes.
The schematic diagram of the method for displaying the screen watermark of the Mac system provided by the embodiment of the invention is shown in figure 2.
As shown in fig. 3, a system for displaying a watermark on a screen of a Mac system according to an embodiment of the present invention includes:
NSPanel type packaging module 1, which is used for instantiating NSPanel type window body used as watermark;
the attribute setting module 2 is used for setting and displaying the display on the topmost layer of the screen and setting and supporting full screen and multi-desktop modes;
a policy information obtaining module 3, configured to obtain a watermark policy through an application server;
and the watermark drawing module 4 is used for drawing the screen watermark pattern through the acquired strategy information.
The technical scheme of the invention is further described below by combining the embodiments.
First embodiment
The embodiment provides a method for dynamically displaying screen watermarks according to a strategy.
Aiming at the situation that the Mac computer cannot display the screen watermark and cannot support the watermark effect in a multi-desktop and full-screen state, the embodiment can display the screen watermark on the Mac computer desktop. The specific technical scheme is as follows:
The method for realizing the display of the plurality of screen watermarks by the Cocoa library of the MacOS comprises the following steps:
MacOS screen watermarking techniques are implemented using class NSPanel under the Cocoa library. Through redrawing CALayer layers of NSPanel, and setting the window to display at the uppermost layer, supporting multiple desktops, full screen mode.
The specific process of packaging NSPanel classes comprises the following steps:
1. The NSPanel types of window forms serving as watermarks are instantiated, and the background color of the window forms is set to be transparent and borderless. By this arrangement, NSPanel kinds become a colorless transparent drawing board. The specific setting process is as follows:
self.backgroundColor=NSColor.clearColor;
self.opaque=NO;
self.hasShadow=NO;
2. by setting the layer one level higher than NSMainMenuWindowLevel, it can be ensured that NSPanel is always displayed at the uppermost part of the screen and cannot be covered by other windows. The specific arrangement is as follows:
self.level=NSMainMenuWindowLevel+1;
3. Setting a watermark window to ignore a mouse event, wherein the mouse event cannot be intercepted by the watermark window, and specifically setting as follows:
self.ignoresMouseEvents=YES;
4. the watermark window is enabled to support full screen and multiple desktops by setting the following attributes:
self.hidesOnDeactivate=NO;
self.collectionBehavior=
NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollectionBehaviorStationary;
self.displaysWhenScreenProfileChanges=YES;
5. An object NSPanel is instantiated as a layer drawn by the screen watermark. The specific arrangement is as follows:
-(void)show1
{
NSView*view=[[NSView alloc]initWithFrame:self.panel.frame];
self.panel.contentView=view;
[self.panel makeKeyAndOrderFront:nil];
}
6. The watermark content is rendered at the Layer of NSPanel in combination with the issued policy.
In combination with the technical solution described above, the advantages and beneficial effects of the present embodiment include:
(1) The compatibility is good based on the development of the original components;
(2) The logic is simple and clear, the transplanting is convenient, and the secondary development is facilitated;
(3) And the display is controlled by the strategy of the server, so that the setting and updating are convenient.
The invention is realized based on the Cocoa library of the MacOS, and the function of displaying the watermark on the Mac computer screen is realized through packaging NSPanel types. The invention has the characteristics of strong reliability, good compatibility, good portability, low dependence on the development environment, small influence on the existing codes, low coupling and high aggregation, supports the display in modes such as multi-desktop mode, full-screen mode and the like, and can be compatible with intel and M1 chips simultaneously. The scheme of the invention can protect Mac terminal data, effectively prevent risks of photographing and screen capturing disclosure, and achieve the effect of information tracking of the disclosure terminal.
The technical scheme described by the embodiment supports the Mac computer multi-desktop and full-screen modes, can well display in the states of desktop switching, desktop newly-built and the like, and does not influence the use of other software of the computer. The embodiment is used together with a corresponding security policy, and the watermark can be controlled to be displayed and hidden by applying the watermark policy configuration of the server, and the content, color and shade of the watermark display.
The embodiment provides a Cocoa-based screen watermark anti-disclosure protection scheme which is completely created based on a primary view, has good compatibility and high reliability, does not excessively interfere with the operation of other APP and system processes while realizing the screen watermark, and has high system reliability. The invention has the characteristics of low coupling, high aggregation, native control, strong compatibility and simple use, and can be rapidly integrated into any software.
Second embodiment
The embodiment provides a method for displaying a plurality of screen watermarks on a Mac computer, which comprises the following steps of inheriting a custom type WATERPANEL from NSPanel and rewriting a initWithContentRect method, wherein the specific codes are as follows:
-(id)initWithContentRect:(NSRect)contentRect
{
self=[super initWithContentRect:contentRect styleMask:
(NSWindowStyleMaskBorder less|NSWindowStyleMaskNonactivatingPanel)backing:NSBackingStoreBuffered defer:NO];
if(self)
{
self.backgroundColor=NSColor.clearColor;
self.level=NSMainMenuWindowLevel+1;
self.opaque=NO;
self.hasShadow=NO;
self.hidesOnDeactivate=NO;
self.collectionBehavior=
NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollection BehaviorStationary;
self.displaysWhenScreenProfileChanges=YES;
self.ignoresMouseEvents=YES;
}
return self;
}
Further, the customization WATERVIEW is inherited from NSView, and the method of rewriting drawRect, and the method of rewriting drawRect is used for drawing watermark information, and specific codes are as follows:
-(void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];
//Drawing code here.
}
a WATERPANEL object is initialized with the current screen size and set to add the screen watermark view to WATERPANEL, the specific code is as follows:
_instance.panel=[[WaterPanel alloc]initWithContentRect:[NSScreen mainScreen].frame];
NSView*view=[[WaterView alloc]initWithFrame:self.panel.frame];
[self.panel.contentView addSubview:watermarkView];
[self.panel makeKeyAndOrderFront:nil];
the watermark pattern to be drawn is obtained by analyzing the strategy issued by the background, and the watermark is drawn by ESTWATERMARKVIEW, and the specific codes are as follows:
NSView*view=
[[WaterView alloc]initWithFrame:self.panel.frame];
EstWatermarkView*watermarkView=
[EstWatermarkUtil createWatermarkViewForProcess:
@""AndWindowView:view];
[self.panel.contentView addSubview:watermarkView];
NSDictionary*views=
NSDictionaryOfVariableBindings(watermarkView);
NSDictionary*metrics=@{@"padding":@0};
[self.panel.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-padding-[watermarkView]-padding-|"options:0metrics:metrics views:views]];
[self.panel.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-padding-[watermarkView]-padding-|"options:0metrics:metrics views:views]];
by setting collectionBehavior attribute of NSPanel, full screen and multi-desktop modes are supported, and specific codes are as follows:
self.collectionBehavior=
NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollection BehaviorStationary;
by setting collectionBehavior attribute of NSPanel, full screen and multi-desktop modes are supported, and specific codes are as follows:
self.collectionBehavior=
NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollection BehaviorStationary;
by setting hasShadow, backgroundColor attribute of NSPanel, the color is colorless and transparent, and has no shadow, and the specific code is as follows:
self.backgroundColor=NSColor.clearColor;
self.hasShadow=NO;
the Mac terminal can acquire a watermark strategy through the application server, and judge whether to display the watermark and the watermark display style and content through the watermark strategy.
After the strategy is acquired, watermark information is acquired through analysis, and the watermark is drawn through the acquired watermark information, and the specific steps are as follows:
1. acquiring strategy information, namely watermark info. OnceInfo, through a network request;
2. through the policy information, it is possible to obtain information including:
Watermark direction direc;
machine name MACHINENAME;
address information addressInfo;
The custom content is customContent;
user information userInfo;
Current time currentDate;
Font, fontName;
Font color rgbaValue;
3. Drawing a screen watermark by acquiring strategy information, which specifically comprises the following steps:
(1) The character strings are spliced, the information is divided by line feed symbols, and the specific settings are as follows:
NSString*watermarkStr=
[NSString stringWithFormat:
@"%@%@%@%@%@",machineName,addressInfo,customCon,userInfo,currentDate];
(2) The style of the character string is set by using the attribute character string, and the specific settings are as follows:
NSAttributedString*attributedStr=
[[NSAttributedString alloc]initWithString:watermarkStrattributes:@{NSFontAttributeName:
[NSFont fontWithName:fontName size:layer.frame.size.width/18-2],NSForegroundColorAttributeName:color}];
(3) Custom EstWatermarkTextLayer inherits CATextLayer and draws watermark information into EstWatermarkTextLayer, and the specific settings are as follows:
EstWatermarkTextLayer*layer=[EstWatermarkTextLayer layer];
layer.alignmentMode=kCAAlignmentCenter;
layer.backgroundColor=[NSColor clearColor].CGColor;
layer.string=attributedStr;
And analyzing to obtain whether the watermark needs to be displayed or not, and displaying the content and the style of the watermark by using the display requirement of the screen watermark.
Third embodiment
As shown in fig. 4, the present embodiment provides a method for implementing a screen watermark, which includes the following steps:
1. Judging whether the screen watermark needs to be displayed or not through issuing a strategy;
2. If the screen watermark is required to be displayed, drawing the content of the screen watermark through a issuing strategy;
3. after the screen watermark is drawn, firstly, carrying out a clearing operation on the previous screen watermark, removing all sub-views, and then adding a re-drawn screen watermark view to prevent the screen watermark from overlapping;
4. the screen watermark is arranged at the uppermost part of all the layers, and is set to support a multi-screen and full-screen mode;
5. The screen watermark view is only responsible for displaying, and does not accept any event, so that the use of other functions is not affected;
According to the technical scheme, the implementation does not need to consider the system version of the MacOS and the resolution of a screen, does not need to consider the hardware environment, can be seamlessly compatible with all machine types under the X86/ARM architecture, does not need to consider factors such as upgrading of the terminal environment after the implementation, and can seamlessly adapt to all machine types of the MacOS, so that the screen watermark can achieve the screen interception prevention protection effect.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in whole or in part in the form of a computer program product, the computer program product includes one or more computer instructions. When the computer program instructions are loaded or executed on a computer, all or part of the procedures or functions are performed according to the above-described embodiments of the present invention. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by a wired (e.g., coaxial cable, fiber optic, digital Subscriber Line (DSL), or wireless (e.g., infrared, wireless, microwave, etc.) means. Computer readable storage media can be any available media that can be accessed by a computer or data storage devices, such as servers, data centers, etc., that contain an integration of one or more available media. Usable media may be magnetic media (e.g., floppy disks, hard disks, magnetic tape), optical media (e.g., DVD), or semiconductor media (e.g., solid state disk Solid STATE DISK (SSD)), among others.
The foregoing is merely illustrative of specific embodiments of the present invention, and the scope of the invention is not limited thereto, but any modifications, equivalents, improvements and alternatives falling within the spirit and principles of the present invention will be apparent to those skilled in the art within the scope of the present invention.