Skip to content

Commit b60b72f

Browse files
author
sorych
committed
Samsung HTML Renderer Task my solution
0 parents  commit b60b72f

File tree

8 files changed

+1307
-0
lines changed

8 files changed

+1307
-0
lines changed

SamsungTest/.classpath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

SamsungTest/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin

SamsungTest/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>SamsungTest</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.7
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.7
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
package HTMLrenderer;
2+
3+
import java.awt.Color;
4+
5+
public interface HTMLObject {
6+
void implement (PictureCreator pc);
7+
8+
}
9+
10+
class BRObject implements HTMLObject {
11+
12+
@Override
13+
public void implement(PictureCreator pc) {
14+
pc.operateBR();
15+
16+
}
17+
18+
}
19+
20+
class TitleObject implements HTMLObject {
21+
String title;
22+
TitleObject(String title) {
23+
this.title=title;
24+
}
25+
26+
@Override
27+
public void implement(PictureCreator pc) {
28+
pc.operateTitle(title);
29+
30+
}
31+
}
32+
33+
class FontStyleObject implements HTMLObject {
34+
private int type; // 1 for i, 2 for u, 3 for b
35+
private boolean status; // true for start, false for end
36+
private Color color;
37+
38+
FontStyleObject(int t, boolean st) {
39+
type = t;
40+
status = st;
41+
}
42+
43+
public void addAttribute(Color a) { //Builder
44+
color=a;
45+
}
46+
47+
@Override
48+
public void implement(PictureCreator pc) {
49+
pc.updatestyle(type, status, color);
50+
51+
}
52+
53+
}
54+
55+
class HeaderObject implements HTMLObject {
56+
private String header;
57+
private int type;
58+
private Color color;
59+
60+
HeaderObject(int t, String header) {
61+
this.type=t;
62+
this.header=header;
63+
}
64+
65+
public void addAttribute(Color a) { //Builder
66+
color=a;
67+
}
68+
69+
@Override
70+
public void implement(PictureCreator pc) {
71+
pc.operateheader(type, header, color);
72+
73+
}
74+
}
75+
76+
class TextObject implements HTMLObject {
77+
protected String text;
78+
79+
TextObject(String txt) {
80+
text = txt;
81+
}
82+
83+
@Override
84+
public void implement(PictureCreator pc) {
85+
pc.operateText(text);
86+
87+
}
88+
89+
}
90+
91+
class ParagraphObject implements HTMLObject {
92+
private int attribute; //0,1,2 for left, center, right
93+
private boolean status;
94+
95+
ParagraphObject(boolean m) {
96+
status=m;
97+
}
98+
99+
public void setAttribute(int attr) { //Builder
100+
attribute=attr;
101+
}
102+
103+
104+
@Override
105+
public void implement(PictureCreator pc) {
106+
pc.operateParagraph(status, attribute);
107+
108+
}
109+
110+
111+
}
112+
113+
class ImgObject implements HTMLObject {
114+
private String source;
115+
private int width;
116+
private int height;
117+
118+
ImgObject(String src) {
119+
source = src;
120+
}
121+
122+
public void setWidthAndHeight(int w, int h) {
123+
width=w;
124+
height=h;
125+
}
126+
127+
@Override
128+
public void implement(PictureCreator pc) {
129+
pc.operatePic(source, width, height);
130+
}
131+
}
132+
133+
134+
class BodyObject implements HTMLObject {
135+
private Color bgcolor;
136+
private Color textcolor;
137+
private int leftmargin;
138+
private int topmargin;
139+
private int rightmargin;
140+
private int bottommargin;
141+
private String fontfamily;
142+
private int fontsize;
143+
private boolean status;
144+
145+
BodyObject(boolean status) {
146+
this.status = status;
147+
}
148+
149+
public void setBgcolor(Color color) { // Builder
150+
bgcolor = color;
151+
}
152+
153+
public void setTextcolor(Color color) {
154+
textcolor = color;
155+
}
156+
157+
public void setLeftmargin(int a) {
158+
leftmargin = a;
159+
}
160+
161+
public void setTopmargin(int a) {
162+
topmargin = a;
163+
}
164+
165+
public void setRightmargin(int a) {
166+
rightmargin = a;
167+
}
168+
169+
public void setBottommargin(int a) {
170+
bottommargin = a;
171+
}
172+
173+
public void setFontsize(int a) {
174+
fontsize = a;
175+
}
176+
177+
public void setFontFamily(String a) {
178+
fontfamily = a;
179+
}
180+
181+
@Override
182+
public void implement(PictureCreator pc) {
183+
if (status) {
184+
pc.operateBody(bgcolor, textcolor, leftmargin, bottommargin, rightmargin, topmargin, fontfamily, fontsize);
185+
}
186+
}
187+
188+
}
189+
190+
class HTMLHeadObject implements HTMLObject {
191+
@SuppressWarnings("unused")
192+
private boolean status; // open/close
193+
@SuppressWarnings("unused")
194+
private int type; // 1 for HTML, 2 for Head
195+
196+
HTMLHeadObject(int typ, boolean stat) {
197+
status = stat;
198+
type = typ;
199+
}
200+
201+
@Override
202+
public void implement(PictureCreator pc) {
203+
}
204+
205+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package HTMLrenderer;
2+
3+
public class HTMLrenderer {
4+
5+
public static void main(String[] args) {
6+
7+
int width = 0, height = 0;
8+
String filename = null;
9+
10+
for (int i = 0; i < args.length; i++) {
11+
if (args[i].equals("-i"))
12+
filename = args[i + 1];
13+
if (args[i].equals("-w"))
14+
width = Integer.valueOf(args[i + 1]);
15+
if (args[i].equals("-h"))
16+
height = Integer.valueOf(args[i + 1]);
17+
}
18+
19+
if (filename == null || width <= 0 || height <= 0) {
20+
System.out.println("You should use parameters like "
21+
+ "\"java –Xmx16m –Xms16m –Xss16m -jar myhtml.jar -i input.html -w 800 -h 1280\" \nplease try again");
22+
23+
} else
24+
new PictureCreator(filename, width, height).create(new Parser().parse(filename));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)