googlewebfonts.pp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. unit googlewebfonts;
  2. {
  3. **********************************************************************
  4. This file is part of the Free Component Library (FCL)
  5. Copyright (c) 2015 The free pascal team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************
  12. }
  13. //Generated on: 16-5-15 08:53:09
  14. {$MODE objfpc}
  15. {$H+}
  16. interface
  17. uses sysutils, classes, googleservice, restbase, googlebase;
  18. type
  19. //Top-level schema types
  20. TWebfont = Class;
  21. TWebfontList = Class;
  22. TWebfontArray = Array of TWebfont;
  23. TWebfontListArray = Array of TWebfontList;
  24. //Anonymous types, using auto-generated names
  25. TWebfontTypefiles = Class;
  26. TWebfontListTypeitemsArray = Array of TWebfont;
  27. { --------------------------------------------------------------------
  28. TWebfontTypefiles
  29. --------------------------------------------------------------------}
  30. TWebfontTypefiles = Class(TGoogleBaseObject)
  31. Private
  32. Protected
  33. //Property setters
  34. Public
  35. Class Function AllowAdditionalProperties : Boolean; override;
  36. Published
  37. end;
  38. TWebfontTypefilesClass = Class of TWebfontTypefiles;
  39. { --------------------------------------------------------------------
  40. TWebfont
  41. --------------------------------------------------------------------}
  42. TWebfont = Class(TGoogleBaseObject)
  43. Private
  44. Fcategory : String;
  45. Ffamily : String;
  46. Ffiles : TWebfontTypefiles;
  47. Fkind : String;
  48. FlastModified : TDate;
  49. Fsubsets : TStringArray;
  50. Fvariants : TStringArray;
  51. Fversion : String;
  52. Protected
  53. //Property setters
  54. Procedure Setcategory(AIndex : Integer; const AValue : String); virtual;
  55. Procedure Setfamily(AIndex : Integer; const AValue : String); virtual;
  56. Procedure Setfiles(AIndex : Integer; AValue : TWebfontTypefiles); virtual;
  57. Procedure Setkind(AIndex : Integer; const AValue : String); virtual;
  58. Procedure SetlastModified(AIndex : Integer; AValue : TDate); virtual;
  59. Procedure Setsubsets(AIndex : Integer; AValue : TStringArray); virtual;
  60. Procedure Setvariants(AIndex : Integer; AValue : TStringArray); virtual;
  61. Procedure Setversion(AIndex : Integer; const AValue : String); virtual;
  62. //2.6.4. bug workaround
  63. {$IFDEF VER2_6}
  64. Procedure SetArrayLength(Const AName : String; ALength : Longint); override;
  65. {$ENDIF VER2_6}
  66. Public
  67. Published
  68. Property category : String Index 0 Read Fcategory Write Setcategory;
  69. Property family : String Index 8 Read Ffamily Write Setfamily;
  70. Property files : TWebfontTypefiles Index 16 Read Ffiles Write Setfiles;
  71. Property kind : String Index 24 Read Fkind Write Setkind;
  72. Property lastModified : TDate Index 32 Read FlastModified Write SetlastModified;
  73. Property subsets : TStringArray Index 40 Read Fsubsets Write Setsubsets;
  74. Property variants : TStringArray Index 48 Read Fvariants Write Setvariants;
  75. Property version : String Index 56 Read Fversion Write Setversion;
  76. end;
  77. TWebfontClass = Class of TWebfont;
  78. { --------------------------------------------------------------------
  79. TWebfontList
  80. --------------------------------------------------------------------}
  81. TWebfontList = Class(TGoogleBaseObject)
  82. Private
  83. Fitems : TWebfontListTypeitemsArray;
  84. Fkind : String;
  85. Protected
  86. //Property setters
  87. Procedure Setitems(AIndex : Integer; AValue : TWebfontListTypeitemsArray); virtual;
  88. Procedure Setkind(AIndex : Integer; const AValue : String); virtual;
  89. //2.6.4. bug workaround
  90. {$IFDEF VER2_6}
  91. Procedure SetArrayLength(Const AName : String; ALength : Longint); override;
  92. {$ENDIF VER2_6}
  93. Public
  94. Published
  95. Property items : TWebfontListTypeitemsArray Index 0 Read Fitems Write Setitems;
  96. Property kind : String Index 8 Read Fkind Write Setkind;
  97. end;
  98. TWebfontListClass = Class of TWebfontList;
  99. { --------------------------------------------------------------------
  100. TWebfontsResource
  101. --------------------------------------------------------------------}
  102. //Optional query Options for TWebfontsResource, method List
  103. TWebfontsListOptions = Record
  104. sort : String;
  105. end;
  106. TWebfontsResource = Class(TGoogleResource)
  107. Public
  108. Class Function ResourceName : String; override;
  109. Class Function DefaultAPI : TGoogleAPIClass; override;
  110. Function List(AQuery : string = '') : TWebfontList;
  111. Function List(AQuery : TWebfontslistOptions) : TWebfontList;
  112. end;
  113. { --------------------------------------------------------------------
  114. TWebfontsAPI
  115. --------------------------------------------------------------------}
  116. TWebfontsAPI = Class(TGoogleAPI)
  117. Private
  118. FWebfontsInstance : TWebfontsResource;
  119. Function GetWebfontsInstance : TWebfontsResource;virtual;
  120. Public
  121. //Override class functions with API info
  122. Class Function APIName : String; override;
  123. Class Function APIVersion : String; override;
  124. Class Function APIRevision : String; override;
  125. Class Function APIID : String; override;
  126. Class Function APITitle : String; override;
  127. Class Function APIDescription : String; override;
  128. Class Function APIOwnerDomain : String; override;
  129. Class Function APIOwnerName : String; override;
  130. Class Function APIIcon16 : String; override;
  131. Class Function APIIcon32 : String; override;
  132. Class Function APIdocumentationLink : String; override;
  133. Class Function APIrootUrl : string; override;
  134. Class Function APIbasePath : string;override;
  135. Class Function APIbaseURL : String;override;
  136. Class Function APIProtocol : string;override;
  137. Class Function APIservicePath : string;override;
  138. Class Function APIbatchPath : String;override;
  139. Class Function APIAuthScopes : TScopeInfoArray;override;
  140. Class Function APINeedsAuth : Boolean;override;
  141. Class Procedure RegisterAPIResources; override;
  142. //Add create function for resources
  143. Function CreateWebfontsResource(AOwner : TComponent) : TWebfontsResource;virtual;overload;
  144. Function CreateWebfontsResource : TWebfontsResource;virtual;overload;
  145. //Add default on-demand instances for resources
  146. Property WebfontsResource : TWebfontsResource Read GetWebfontsInstance;
  147. end;
  148. implementation
  149. { --------------------------------------------------------------------
  150. TWebfontTypefiles
  151. --------------------------------------------------------------------}
  152. Class Function TWebfontTypefiles.AllowAdditionalProperties : Boolean;
  153. begin
  154. Result:=True;
  155. end;
  156. { --------------------------------------------------------------------
  157. TWebfont
  158. --------------------------------------------------------------------}
  159. Procedure TWebfont.Setcategory(AIndex : Integer; const AValue : String);
  160. begin
  161. If (Fcategory=AValue) then exit;
  162. Fcategory:=AValue;
  163. MarkPropertyChanged(AIndex);
  164. end;
  165. Procedure TWebfont.Setfamily(AIndex : Integer; const AValue : String);
  166. begin
  167. If (Ffamily=AValue) then exit;
  168. Ffamily:=AValue;
  169. MarkPropertyChanged(AIndex);
  170. end;
  171. Procedure TWebfont.Setfiles(AIndex : Integer; AValue : TWebfontTypefiles);
  172. begin
  173. If (Ffiles=AValue) then exit;
  174. Ffiles:=AValue;
  175. MarkPropertyChanged(AIndex);
  176. end;
  177. Procedure TWebfont.Setkind(AIndex : Integer; const AValue : String);
  178. begin
  179. If (Fkind=AValue) then exit;
  180. Fkind:=AValue;
  181. MarkPropertyChanged(AIndex);
  182. end;
  183. Procedure TWebfont.SetlastModified(AIndex : Integer; AValue : TDate);
  184. begin
  185. If (FlastModified=AValue) then exit;
  186. FlastModified:=AValue;
  187. MarkPropertyChanged(AIndex);
  188. end;
  189. Procedure TWebfont.Setsubsets(AIndex : Integer; AValue : TStringArray);
  190. begin
  191. If (Fsubsets=AValue) then exit;
  192. Fsubsets:=AValue;
  193. MarkPropertyChanged(AIndex);
  194. end;
  195. Procedure TWebfont.Setvariants(AIndex : Integer; AValue : TStringArray);
  196. begin
  197. If (Fvariants=AValue) then exit;
  198. Fvariants:=AValue;
  199. MarkPropertyChanged(AIndex);
  200. end;
  201. Procedure TWebfont.Setversion(AIndex : Integer; const AValue : String);
  202. begin
  203. If (Fversion=AValue) then exit;
  204. Fversion:=AValue;
  205. MarkPropertyChanged(AIndex);
  206. end;
  207. //2.6.4. bug workaround
  208. {$IFDEF VER2_6}
  209. Procedure TWebfont.SetArrayLength(Const AName : String; ALength : Longint);
  210. begin
  211. Case AName of
  212. 'subsets' : SetLength(Fsubsets,ALength);
  213. 'variants' : SetLength(Fvariants,ALength);
  214. else
  215. Inherited SetArrayLength(AName,ALength);
  216. end;
  217. end;
  218. {$ENDIF VER2_6}
  219. { --------------------------------------------------------------------
  220. TWebfontList
  221. --------------------------------------------------------------------}
  222. Procedure TWebfontList.Setitems(AIndex : Integer; AValue : TWebfontListTypeitemsArray);
  223. begin
  224. If (Fitems=AValue) then exit;
  225. Fitems:=AValue;
  226. MarkPropertyChanged(AIndex);
  227. end;
  228. Procedure TWebfontList.Setkind(AIndex : Integer; const AValue : String);
  229. begin
  230. If (Fkind=AValue) then exit;
  231. Fkind:=AValue;
  232. MarkPropertyChanged(AIndex);
  233. end;
  234. //2.6.4. bug workaround
  235. {$IFDEF VER2_6}
  236. Procedure TWebfontList.SetArrayLength(Const AName : String; ALength : Longint);
  237. begin
  238. Case AName of
  239. 'items' : SetLength(Fitems,ALength);
  240. else
  241. Inherited SetArrayLength(AName,ALength);
  242. end;
  243. end;
  244. {$ENDIF VER2_6}
  245. { --------------------------------------------------------------------
  246. TWebfontsResource
  247. --------------------------------------------------------------------}
  248. Class Function TWebfontsResource.ResourceName : String;
  249. begin
  250. Result:='webfonts';
  251. end;
  252. Class Function TWebfontsResource.DefaultAPI : TGoogleAPIClass;
  253. begin
  254. Result:=TwebfontsAPI;
  255. end;
  256. Function TWebfontsResource.List(AQuery : string = '') : TWebfontList;
  257. Const
  258. _HTTPMethod = 'GET';
  259. _Path = 'webfonts';
  260. _Methodid = 'webfonts.webfonts.list';
  261. begin
  262. Result:=ServiceCall(_HTTPMethod,_Path,AQuery,Nil,TWebfontList) as TWebfontList;
  263. end;
  264. Function TWebfontsResource.List(AQuery : TWebfontslistOptions) : TWebfontList;
  265. Var
  266. _Q : String;
  267. begin
  268. _Q:='';
  269. AddToQuery(_Q,'sort',AQuery.sort);
  270. Result:=List(_Q);
  271. end;
  272. { --------------------------------------------------------------------
  273. TWebfontsAPI
  274. --------------------------------------------------------------------}
  275. Class Function TWebfontsAPI.APIName : String;
  276. begin
  277. Result:='webfonts';
  278. end;
  279. Class Function TWebfontsAPI.APIVersion : String;
  280. begin
  281. Result:='v1';
  282. end;
  283. Class Function TWebfontsAPI.APIRevision : String;
  284. begin
  285. Result:='20140210';
  286. end;
  287. Class Function TWebfontsAPI.APIID : String;
  288. begin
  289. Result:='webfonts:v1';
  290. end;
  291. Class Function TWebfontsAPI.APITitle : String;
  292. begin
  293. Result:='Google Fonts Developer API';
  294. end;
  295. Class Function TWebfontsAPI.APIDescription : String;
  296. begin
  297. Result:='The Google Fonts Developer API.';
  298. end;
  299. Class Function TWebfontsAPI.APIOwnerDomain : String;
  300. begin
  301. Result:='google.com';
  302. end;
  303. Class Function TWebfontsAPI.APIOwnerName : String;
  304. begin
  305. Result:='Google';
  306. end;
  307. Class Function TWebfontsAPI.APIIcon16 : String;
  308. begin
  309. Result:='http://www.google.com/images/icons/feature/font_api-16.png';
  310. end;
  311. Class Function TWebfontsAPI.APIIcon32 : String;
  312. begin
  313. Result:='http://www.google.com/images/icons/feature/font_api-32.gif';
  314. end;
  315. Class Function TWebfontsAPI.APIdocumentationLink : String;
  316. begin
  317. Result:='https://developers.google.com/fonts/docs/developer_api';
  318. end;
  319. Class Function TWebfontsAPI.APIrootUrl : string;
  320. begin
  321. Result:='https://www.googleapis.com:443/';
  322. end;
  323. Class Function TWebfontsAPI.APIbasePath : string;
  324. begin
  325. Result:='/webfonts/v1/';
  326. end;
  327. Class Function TWebfontsAPI.APIbaseURL : String;
  328. begin
  329. Result:='https://www.googleapis.com:443/webfonts/v1/';
  330. end;
  331. Class Function TWebfontsAPI.APIProtocol : string;
  332. begin
  333. Result:='rest';
  334. end;
  335. Class Function TWebfontsAPI.APIservicePath : string;
  336. begin
  337. Result:='webfonts/v1/';
  338. end;
  339. Class Function TWebfontsAPI.APIbatchPath : String;
  340. begin
  341. Result:='batch';
  342. end;
  343. Class Function TWebfontsAPI.APIAuthScopes : TScopeInfoArray;
  344. begin
  345. SetLength(Result,0);
  346. end;
  347. Class Function TWebfontsAPI.APINeedsAuth : Boolean;
  348. begin
  349. Result:=False;
  350. end;
  351. Class Procedure TWebfontsAPI.RegisterAPIResources;
  352. begin
  353. TWebfontTypefiles.RegisterObject;
  354. TWebfont.RegisterObject;
  355. TWebfontList.RegisterObject;
  356. end;
  357. Function TWebfontsAPI.GetWebfontsInstance : TWebfontsResource;
  358. begin
  359. if (FWebfontsInstance=Nil) then
  360. FWebfontsInstance:=CreateWebfontsResource;
  361. Result:=FWebfontsInstance;
  362. end;
  363. Function TWebfontsAPI.CreateWebfontsResource : TWebfontsResource;
  364. begin
  365. Result:=CreateWebfontsResource(Self);
  366. end;
  367. Function TWebfontsAPI.CreateWebfontsResource(AOwner : TComponent) : TWebfontsResource;
  368. begin
  369. Result:=TWebfontsResource.Create(AOwner);
  370. Result.API:=Self.API;
  371. end;
  372. initialization
  373. TWebfontsAPI.RegisterAPI;
  374. end.